Tonic commited on
Commit
9d5b6f7
1 Parent(s): 13a19c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -22,14 +22,11 @@ Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder
22
  @spaces.GPU
23
  def whisper_speech_demo(text, lang, speaker_audio, mix_lang, mix_text):
24
  pipe = Pipeline()
25
- speaker_url = None
26
 
27
- if speaker_audio is not None:
28
- speaker_url = speaker_audio
29
-
30
- if mix_lang and mix_text:
31
- mixed_langs = lang.split(',') + mix_lang.split(',')
32
- mixed_texts = [text] + mix_text.split(',')
33
  stoks = pipe.t2s.generate(mixed_texts, lang=mixed_langs)
34
  audio_data = pipe.generate(stoks, speaker_url, lang=mixed_langs[0])
35
  else:
@@ -39,10 +36,9 @@ def whisper_speech_demo(text, lang, speaker_audio, mix_lang, mix_text):
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.cpu().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
@@ -56,8 +52,8 @@ with gr.Blocks() as demo:
56
  text_input_standard = gr.Textbox(label="Enter text")
57
  lang_input_standard = gr.Dropdown(choices=list(LANGUAGES.keys()), label="Language")
58
  speaker_input_standard = gr.Audio(label="Upload or Record Speaker Audio (optional)", sources=["upload", "microphone"], type="filepath")
59
- placeholder_mix_lang = gr.Textbox(visible=False) # Placeholder, hidden
60
- placeholder_mix_text = gr.Textbox(visible=False) # Placeholder, hidden
61
  generate_button_standard = gr.Button("Generate Speech")
62
  output_audio_standard = gr.Audio(label="🌬️💬📝WhisperSpeech")
63
 
@@ -69,8 +65,8 @@ with gr.Blocks() as demo:
69
 
70
  with gr.TabItem("🌬️💬📝Mixed Language TTS"):
71
  with gr.Row():
72
- placeholder_text_input = gr.Textbox(visible=False) # Placeholder, hidden
73
- placeholder_lang_input = gr.Dropdown(choices=[], visible=False) # Placeholder, hidden
74
  placeholder_speaker_input = gr.Audio(visible=False)
75
  mix_lang_input_mixed = gr.CheckboxGroup(choices=list(LANGUAGES.keys()), label="Select Languages")
76
  mix_text_input_mixed = gr.Textbox(label="Enter mixed language text", placeholder="e.g., Hello, Cześć")
 
22
  @spaces.GPU
23
  def whisper_speech_demo(text, lang, speaker_audio, mix_lang, mix_text):
24
  pipe = Pipeline()
25
+ speaker_url = speaker_audio if speaker_audio is not None else None
26
 
27
+ if mix_lang and mix_text:
28
+ mixed_langs = mix_lang
29
+ mixed_texts = mix_text.split(',')
 
 
 
30
  stoks = pipe.t2s.generate(mixed_texts, lang=mixed_langs)
31
  audio_data = pipe.generate(stoks, speaker_url, lang=mixed_langs[0])
32
  else:
 
36
  audio_data_resampled = next(resample_audio([{'sample_rate': 22050, 'samples': audio_data.cpu()}]))['samples_24k']
37
 
38
  # Normalize audio
39
+ audio_np = audio_data_resampled.cpu().numpy()
40
  audio_np = audio_np / np.max(np.abs(audio_np))
41
 
 
42
  with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp_file:
43
  sf.write(tmp_file.name, audio_np, 24000, 'PCM_16')
44
  return tmp_file.name
 
52
  text_input_standard = gr.Textbox(label="Enter text")
53
  lang_input_standard = gr.Dropdown(choices=list(LANGUAGES.keys()), label="Language")
54
  speaker_input_standard = gr.Audio(label="Upload or Record Speaker Audio (optional)", sources=["upload", "microphone"], type="filepath")
55
+ placeholder_mix_lang = gr.Textbox(visible=False)
56
+ placeholder_mix_text = gr.Textbox(visible=False)
57
  generate_button_standard = gr.Button("Generate Speech")
58
  output_audio_standard = gr.Audio(label="🌬️💬📝WhisperSpeech")
59
 
 
65
 
66
  with gr.TabItem("🌬️💬📝Mixed Language TTS"):
67
  with gr.Row():
68
+ placeholder_text_input = gr.Textbox(visible=False)
69
+ placeholder_lang_input = gr.Dropdown(choices=[], visible=False)
70
  placeholder_speaker_input = gr.Audio(visible=False)
71
  mix_lang_input_mixed = gr.CheckboxGroup(choices=list(LANGUAGES.keys()), label="Select Languages")
72
  mix_text_input_mixed = gr.Textbox(label="Enter mixed language text", placeholder="e.g., Hello, Cześć")