Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -38,26 +38,14 @@ def whisper_speech_demo(text, lang, speaker_audio, mix_lang, mix_text):
|
|
38 |
resample_audio = resampler(newsr=24000)
|
39 |
audio_data_resampled = next(resample_audio([{'sample_rate': 22050, 'samples': audio_data.cpu()}]))['samples_24k']
|
40 |
|
41 |
-
# Normalize
|
42 |
-
|
43 |
-
|
44 |
-
audio_np = audio_data_resampled.numpy() # Convert to numpy array
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
audio_np = np.stack((audio_np, audio_np), axis=-1)
|
51 |
-
|
52 |
-
audio_np = np.int16(audio_np * 32767)
|
53 |
-
|
54 |
-
with wave.open(tmp_file_name, 'w') as wav_file:
|
55 |
-
wav_file.setnchannels(2)
|
56 |
-
wav_file.setsampwidth(2)
|
57 |
-
wav_file.setframerate(24000)
|
58 |
-
wav_file.writeframes(audio_np.tobytes())
|
59 |
-
|
60 |
-
return tmp_file_name
|
61 |
|
62 |
with gr.Blocks() as demo:
|
63 |
gr.Markdown(title)
|
|
|
38 |
resample_audio = resampler(newsr=24000)
|
39 |
audio_data_resampled = next(resample_audio([{'sample_rate': 22050, 'samples': audio_data.cpu()}]))['samples_24k']
|
40 |
|
41 |
+
# Normalize audio
|
42 |
+
audio_np = audio_data.numpy()
|
43 |
+
audio_np = audio_np / np.max(np.abs(audio_np))
|
|
|
44 |
|
45 |
+
# Save to a temporary WAV file
|
46 |
+
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp_file:
|
47 |
+
sf.write(tmp_file.name, audio_np, 24000, 'PCM_16')
|
48 |
+
return tmp_file.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
with gr.Blocks() as demo:
|
51 |
gr.Markdown(title)
|