Staticaliza commited on
Commit
d6b0acb
1 Parent(s): 6cad840

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import numpy as np
3
  import soundfile as sf
 
4
  import spaces
5
  import torch
6
  import torchaudio
@@ -323,16 +324,20 @@ def voice_conversion(input, reference, steps, guidance, speed):
323
  print("[INFO] | Final audio normalized.")
324
 
325
  # Smoothen the audio to reduce distorted audio
326
- def butter_lowpass_filter(data, cutoff=3000, fs=sr_current, order=6):
327
-
328
  nyq = 0.5 * fs
329
- normal_cutoff = cutoff / nyq
330
- b, a = butter(order, normal_cutoff, btype='low', analog=False)
331
- y = lfilter(b, a, data)
 
332
  return y
333
 
334
- final_audio = butter_lowpass_filter(final_audio)
335
  print("[INFO] | Final audio smoothed with low-pass filter.")
 
 
 
 
336
 
337
  # Save the audio to a temporary WAV file
338
  print("[INFO] | Saving final audio to a temporary WAV file.")
 
1
  import gradio as gr
2
  import numpy as np
3
  import soundfile as sf
4
+ import noisereduce as nr
5
  import spaces
6
  import torch
7
  import torchaudio
 
324
  print("[INFO] | Final audio normalized.")
325
 
326
  # Smoothen the audio to reduce distorted audio
327
+ def butter_bandpass_filter_filtfilt(data, lowcut=80, highcut=6000, fs=sr_current, order=4):
 
328
  nyq = 0.5 * fs
329
+ low = lowcut / nyq
330
+ high = highcut / nyq
331
+ b, a = butter(order, [low, high], btype='band')
332
+ y = filtfilt(b, a, data)
333
  return y
334
 
335
+ final_audio = butter_bandpass_filter_filtfilt(final_audio)
336
  print("[INFO] | Final audio smoothed with low-pass filter.")
337
+
338
+ noise_profile = nr.get_noise_profile(final_audio, sr_current)
339
+ final_audio = nr.reduce_noise(y=final_audio, sr=sr_current, y_noise=noise_profile, prop_decrease=1.0)
340
+ print("[INFO] | Final audio noise reduced using noisereduce.")
341
 
342
  # Save the audio to a temporary WAV file
343
  print("[INFO] | Saving final audio to a temporary WAV file.")