11import PySimpleGUI as sg
22import sounddevice as sd
3- # import noisereduce as nr
3+ import noisereduce as nr
44import numpy as np
55from fairseq import checkpoint_utils
66import librosa ,torch ,parselmouth ,faiss ,time ,threading
@@ -147,6 +147,7 @@ def __init__(self) -> None:
147147 self .threhold :int = - 30
148148 self .crossfade_time :float = 0.08
149149 self .extra_time :float = 0.04
150+ self .noise_reduce = False
150151
151152class GUI :
152153 def __init__ (self ) -> None :
@@ -181,7 +182,8 @@ def launcher(self):
181182 sg .Frame (layout = [
182183 [sg .Text (i18n ("采样长度/Sample Length" )),sg .Slider (range = (0.1 ,3.0 ),key = 'block_time' ,resolution = 0.1 ,orientation = 'h' ,default_value = 1.0 )],
183184 [sg .Text (i18n ("淡入淡出长度/Crossfade Length" )),sg .Slider (range = (0.01 ,0.15 ),key = 'crossfade_length' ,resolution = 0.01 ,orientation = 'h' ,default_value = 0.08 )],
184- [sg .Text (i18n ("额外推理时长/Extra Length" )),sg .Slider (range = (0.05 ,3.00 ),key = 'extra_time' ,resolution = 0.01 ,orientation = 'h' ,default_value = 0.05 )]
185+ [sg .Text (i18n ("额外推理时长/Extra Length" )),sg .Slider (range = (0.05 ,3.00 ),key = 'extra_time' ,resolution = 0.01 ,orientation = 'h' ,default_value = 0.05 )],
186+ [sg .Checkbox (i18n ('输出降噪/Output Noisereduce' ),key = 'noise_reduce' )]
185187 ],title = i18n ("性能设置/Performance" ))
186188 ],
187189 [sg .Button (i18n ("开始音频转换" ),key = 'start_vc' ),sg .Button (i18n ("停止音频转换" ),key = 'stop_vc' )]
@@ -217,7 +219,7 @@ def set_values(self,values):
217219 self .config .block_time = values ['block_time' ]
218220 self .config .crossfade_time = values ['crossfade_length' ]
219221 self .config .extra_time = values ['extra_time' ]
220-
222+ self . config . noise_reduce = values [ 'noise_reduce' ]
221223
222224 def start_vc (self ):
223225 torch .cuda .empty_cache ()
@@ -290,6 +292,9 @@ def audio_callback(self,indata:np.ndarray,outdata:np.ndarray, frames, times, sta
290292 else :
291293 self .sola_buffer [:] = infer_wav [- self .crossfade_frame :]* self .fade_out_window
292294
295+ if self .config .noise_reduce :
296+ self .output_wav [:]= nr .reduce_noise (y = self .output_wav ,sr = self .config .samplerate )
297+
293298 outdata [:]= np .array ([self .output_wav ,self .output_wav ]).T
294299 print ('infer time:' + str (time .perf_counter ()- start_time ))
295300
@@ -325,4 +330,6 @@ def set_devices(self,input_device,output_device):
325330 sd .default .device [0 ]= input_device_indices [input_devices .index (input_device )]
326331 sd .default .device [1 ]= output_device_indices [output_devices .index (output_device )]
327332 print ("input device:" + str (sd .default .device [0 ])+ ":" + str (input_device ))
328- print ("output device:" + str (sd .default .device [1 ])+ ":" + str (output_device ))
333+ print ("output device:" + str (sd .default .device [1 ])+ ":" + str (output_device ))
334+
335+ gui = GUI ()
0 commit comments