Hev832 commited on
Commit
de395e6
·
verified ·
1 Parent(s): 75e5563

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -8,7 +8,8 @@ import gradio as gr
8
  import yt_dlp
9
  import subprocess
10
  from pydub import AudioSegment
11
- from pydub.effects import reverb
 
12
  from audio_separator.separator import Separator
13
  from lib.infer import infer_audio
14
  import edge_tts
@@ -88,18 +89,28 @@ async def text_to_speech_edge(text, language_code):
88
 
89
 
90
 
91
- # Function to add reverb effect using pydub
92
  def add_simple_reverb(input_audio):
93
- # Load the uploaded audio file
94
  sound = AudioSegment.from_file(input_audio)
95
- # Apply reverb effect
96
- reverbed_sound = reverb(sound)
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  # Export the reverbed sound to a new file-like object (in-memory)
99
  output_path = "vocals_with_reverb.wav"
100
  reverbed_sound.export(output_path, format='wav')
101
 
102
- # Return the output path for Gradio to handle
103
  return output_path
104
 
105
 
 
8
  import yt_dlp
9
  import subprocess
10
  from pydub import AudioSegment
11
+ from scipy.signal import convolve
12
+
13
  from audio_separator.separator import Separator
14
  from lib.infer import infer_audio
15
  import edge_tts
 
89
 
90
 
91
 
92
+ # Function to apply a basic reverb effect using convolution
93
  def add_simple_reverb(input_audio):
94
+ # Load the uploaded audio file using pydub
95
  sound = AudioSegment.from_file(input_audio)
96
+
97
+ # Convert AudioSegment to numpy array
98
+ samples = np.array(sound.get_array_of_samples())
99
+
100
+ # Define a simple impulse response for reverb (can be customized)
101
+ impulse_response = np.concatenate([np.zeros(5000), np.array([0.5**i for i in range(1000)])])
102
+
103
+ # Apply convolution (reverb effect)
104
+ reverbed_samples = convolve(samples, impulse_response, mode='full')
105
+ reverbed_samples = reverbed_samples[:len(samples)] # trim to original length
106
+
107
+ # Convert numpy array back to AudioSegment
108
+ reverbed_sound = sound._spawn(reverbed_samples.astype(np.int16).tobytes())
109
 
110
  # Export the reverbed sound to a new file-like object (in-memory)
111
  output_path = "vocals_with_reverb.wav"
112
  reverbed_sound.export(output_path, format='wav')
113
 
 
114
  return output_path
115
 
116