Tonic commited on
Commit
7500d41
1 Parent(s): decaf77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -24,9 +24,15 @@ def whisper_speech_demo(text, lang, speaker_audio, mix_lang, mix_text):
24
  print(f"Text: {text}, Lang: {lang}, Speaker Audio: {speaker_audio}, Mix Lang: {mix_lang}, Mix Text: {mix_text}")
25
  pipe = Pipeline()
26
  speaker_url = speaker_audio if speaker_audio is not None else None
 
 
 
 
 
 
27
 
28
  if mix_lang and mix_text:
29
- mixed_langs = mix_lang
30
  mixed_texts = mix_text.split(',')
31
  stoks = pipe.t2s.generate(mixed_texts, lang=mixed_langs)
32
  audio_data = pipe.generate(stoks, speaker_url, lang=mixed_langs[0])
@@ -42,8 +48,8 @@ def whisper_speech_demo(text, lang, speaker_audio, mix_lang, mix_text):
42
  audio_stereo = np.stack((audio_np, audio_np), axis=-1)
43
  audio_stereo = audio_stereo.reshape(-1, 2)
44
 
45
- # print("Audio Array Shape:", audio_stereo.shape)
46
- # print("Audio Array Dtype:", audio_stereo.dtype)
47
  with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp_file:
48
  sf.write(tmp_file.name, audio_stereo, 24000, format='WAV', subtype='PCM_16')
49
  return tmp_file.name
 
24
  print(f"Text: {text}, Lang: {lang}, Speaker Audio: {speaker_audio}, Mix Lang: {mix_lang}, Mix Text: {mix_text}")
25
  pipe = Pipeline()
26
  speaker_url = speaker_audio if speaker_audio is not None else None
27
+ if isinstance(lang, list):
28
+ if not lang:
29
+ raise ValueError("Language list is empty.")
30
+ lang = lang[0]
31
+ elif not isinstance(lang, str):
32
+ raise ValueError("Language is not specified correctly.")
33
 
34
  if mix_lang and mix_text:
35
+ mixed_langs = mix_lang.split(',') if isinstance(mix_lang, str) else mix_lang
36
  mixed_texts = mix_text.split(',')
37
  stoks = pipe.t2s.generate(mixed_texts, lang=mixed_langs)
38
  audio_data = pipe.generate(stoks, speaker_url, lang=mixed_langs[0])
 
48
  audio_stereo = np.stack((audio_np, audio_np), axis=-1)
49
  audio_stereo = audio_stereo.reshape(-1, 2)
50
 
51
+ print("Audio Array Shape:", audio_stereo.shape)
52
+ print("Audio Array Dtype:", audio_stereo.dtype)
53
  with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp_file:
54
  sf.write(tmp_file.name, audio_stereo, 24000, format='WAV', subtype='PCM_16')
55
  return tmp_file.name