Tonic commited on
Commit
a0ed1d8
1 Parent(s): 25a42f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -38,19 +38,18 @@ def parse_multilingual_text(input_text):
38
  return [(lang, text.strip()) for lang, text in segments if lang in LANGUAGES.keys()]
39
 
40
  @spaces.GPU
41
- def generate_segment_audio(text, lang, speaker_url, pipe):
42
-
43
- # Ensure text is a string
44
  if not isinstance(text, str):
45
  text = text.decode("utf-8") if isinstance(text, bytes) else str(text)
46
-
47
- # Check and process speaker_audio if it is a string (path to file)
48
- if isinstance(speaker_audio, str):
49
- print("Speaker Audio Type:", type(speaker_audio))
50
- with open(speaker_audio, 'rb') as file:
51
- speaker_audio = file.read()
52
-
53
- audio_data = pipe.generate(text, speaker_audio, lang)
 
54
  resample_audio = resampler(newsr=24000)
55
  audio_data_resampled = next(resample_audio([{'sample_rate': 24000, 'samples': audio_data.cpu()}]))['samples_24k']
56
  audio_np = audio_data_resampled.cpu().numpy()
 
38
  return [(lang, text.strip()) for lang, text in segments if lang in LANGUAGES.keys()]
39
 
40
  @spaces.GPU
41
+ def generate_segment_audio(text, lang, speaker_audio, pipe):
 
 
42
  if not isinstance(text, str):
43
  text = text.decode("utf-8") if isinstance(text, bytes) else str(text)
44
+ if speaker_audio is not None:
45
+ if isinstance(speaker_audio, str):
46
+ with open(speaker_audio, 'rb') as file:
47
+ speaker_audio_data = file.read()
48
+ else:
49
+ speaker_audio_data = speaker_audio
50
+ else:
51
+ speaker_audio_data = None
52
+ audio_data = pipe.generate(text, speaker_audio_data, lang)
53
  resample_audio = resampler(newsr=24000)
54
  audio_data_resampled = next(resample_audio([{'sample_rate': 24000, 'samples': audio_data.cpu()}]))['samples_24k']
55
  audio_np = audio_data_resampled.cpu().numpy()