Tonic commited on
Commit
e27c13f
1 Parent(s): 2d4f3d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -20,8 +20,8 @@ Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder
20
  @spaces.GPU
21
  def whisper_speech_demo(text, lang, speaker_audio=None, mix_lang=None, mix_text=None):
22
  pipe = Pipeline()
23
-
24
  speaker_url = None
 
25
  if speaker_audio is not None:
26
  speaker_url = speaker_audio.name
27
 
@@ -36,7 +36,11 @@ def whisper_speech_demo(text, lang, speaker_audio=None, mix_lang=None, mix_text=
36
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmp_file:
37
  tmp_file_name = tmp_file.name
38
  audio_np = audio_data.cpu().numpy()
39
- sf.write(tmp_file_name, audio_np, 22050)
 
 
 
 
40
 
41
  return tmp_file_name
42
 
 
20
  @spaces.GPU
21
  def whisper_speech_demo(text, lang, speaker_audio=None, mix_lang=None, mix_text=None):
22
  pipe = Pipeline()
 
23
  speaker_url = None
24
+
25
  if speaker_audio is not None:
26
  speaker_url = speaker_audio.name
27
 
 
36
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmp_file:
37
  tmp_file_name = tmp_file.name
38
  audio_np = audio_data.cpu().numpy()
39
+
40
+ if audio_np.max() > 1.0 or audio_np.min() < -1.0:
41
+ audio_np = audio_np / np.max(np.abs(audio_np))
42
+
43
+ sf.write(tmp_file_name, audio_np, 24000)
44
 
45
  return tmp_file_name
46