Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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,
|
| 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 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 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()
|