Simonlob commited on
Commit
20c0403
·
verified ·
1 Parent(s): aba236b

Update util.py

Browse files
Files changed (1) hide show
  1. util.py +8 -0
util.py CHANGED
@@ -172,6 +172,14 @@ class SpeakerManager:
172
  audio_array = audio_data
173
  sample_rate = 16000
174
 
 
 
 
 
 
 
 
 
175
  # Generate embedding (SpeakerEmbedder will handle resampling if needed)
176
  embedding = self.embedder.embed_audio(audio_array, sample_rate=sample_rate)
177
 
 
172
  audio_array = audio_data
173
  sample_rate = 16000
174
 
175
+ # convert audio from int16 (gradio.audio() returns int16) to float32
176
+ audio_array = audio_array.astype(np.float32) / 32768.0
177
+
178
+ # make mono if stereo (gradio specific)! gradio returns waveform with shape (num_samples, num_channels) that not typical for torch paradigm
179
+ if audio_array.ndim == 2:
180
+ print('Make MONO from STEREO')
181
+ audio_array = audio_array.mean(axis=1)
182
+
183
  # Generate embedding (SpeakerEmbedder will handle resampling if needed)
184
  embedding = self.embedder.embed_audio(audio_array, sample_rate=sample_rate)
185