mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2025-05-06 11:39:01 +08:00
fix: Audio stuttering when using ASIO (#2181)
This commit is contained in:
parent
83d6a64e67
commit
45a49dde74
53
gui_v1.py
53
gui_v1.py
@ -826,15 +826,28 @@ if __name__ == "__main__":
|
|||||||
extra_settings = sd.WasapiSettings(exclusive=True)
|
extra_settings = sd.WasapiSettings(exclusive=True)
|
||||||
else:
|
else:
|
||||||
extra_settings = None
|
extra_settings = None
|
||||||
self.stream = sd.Stream(
|
|
||||||
callback=self.audio_callback,
|
if self.gui_config.sg_hostapi == "ASIO":
|
||||||
blocksize=self.block_frame,
|
self.stream = sd.Stream(
|
||||||
samplerate=self.gui_config.samplerate,
|
blocksize=self.block_frame,
|
||||||
channels=self.gui_config.channels,
|
samplerate=self.gui_config.samplerate,
|
||||||
dtype="float32",
|
channels=self.gui_config.channels,
|
||||||
extra_settings=extra_settings,
|
dtype="float32",
|
||||||
)
|
extra_settings=extra_settings,
|
||||||
self.stream.start()
|
)
|
||||||
|
self.stream.start()
|
||||||
|
audio_thread = threading.Thread(target=self.audio_thread, daemon=True)
|
||||||
|
audio_thread.start()
|
||||||
|
else:
|
||||||
|
self.stream = sd.Stream(
|
||||||
|
callback=self.audio_callback,
|
||||||
|
blocksize=self.block_frame,
|
||||||
|
samplerate=self.gui_config.samplerate,
|
||||||
|
channels=self.gui_config.channels,
|
||||||
|
dtype="float32",
|
||||||
|
extra_settings=extra_settings,
|
||||||
|
)
|
||||||
|
self.stream.start()
|
||||||
|
|
||||||
def stop_stream(self):
|
def stop_stream(self):
|
||||||
global flag_vc
|
global flag_vc
|
||||||
@ -845,9 +858,22 @@ if __name__ == "__main__":
|
|||||||
self.stream.close()
|
self.stream.close()
|
||||||
self.stream = None
|
self.stream = None
|
||||||
|
|
||||||
def audio_callback(
|
def audio_thread(self):
|
||||||
self, indata: np.ndarray, outdata: np.ndarray, frames, times, status
|
global flag_vc
|
||||||
):
|
while flag_vc and self.stream and self.stream.active:
|
||||||
|
indata, overflow = self.stream.read(self.block_frame)
|
||||||
|
if overflow:
|
||||||
|
printt("Overflow occurred, consider increasing the block_frame to avoid data loss.")
|
||||||
|
outdata = np.ascontiguousarray(self.vc_pipeline(indata))
|
||||||
|
if self.stream and self.stream.active:
|
||||||
|
underflow = self.stream.write(outdata)
|
||||||
|
if underflow:
|
||||||
|
printt("Underflow occurred, consider increasing the block_frame to avoid audio glitches.")
|
||||||
|
|
||||||
|
def audio_callback(self, indata: np.ndarray, outdata: np.ndarray, frames, times, status):
|
||||||
|
outdata[:] = self.vc_pipeline(indata)
|
||||||
|
|
||||||
|
def vc_pipeline(self, indata: np.ndarray) -> np.ndarray:
|
||||||
"""
|
"""
|
||||||
音频处理
|
音频处理
|
||||||
"""
|
"""
|
||||||
@ -995,7 +1021,7 @@ if __name__ == "__main__":
|
|||||||
self.sola_buffer[:] = infer_wav[
|
self.sola_buffer[:] = infer_wav[
|
||||||
self.block_frame : self.block_frame + self.sola_buffer_frame
|
self.block_frame : self.block_frame + self.sola_buffer_frame
|
||||||
]
|
]
|
||||||
outdata[:] = (
|
outdata = (
|
||||||
infer_wav[: self.block_frame]
|
infer_wav[: self.block_frame]
|
||||||
.repeat(self.gui_config.channels, 1)
|
.repeat(self.gui_config.channels, 1)
|
||||||
.t()
|
.t()
|
||||||
@ -1006,6 +1032,7 @@ if __name__ == "__main__":
|
|||||||
if flag_vc:
|
if flag_vc:
|
||||||
self.window["infer_time"].update(int(total_time * 1000))
|
self.window["infer_time"].update(int(total_time * 1000))
|
||||||
printt("Infer time: %.2f", total_time)
|
printt("Infer time: %.2f", total_time)
|
||||||
|
return outdata
|
||||||
|
|
||||||
def update_devices(self, hostapi_name=None):
|
def update_devices(self, hostapi_name=None):
|
||||||
"""获取设备列表"""
|
"""获取设备列表"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user