Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ tokenizer = MarianTokenizer.from_pretrained(model_name)
|
|
13 |
tts_model_name = "microsoft/speecht5_tts"
|
14 |
tts_model = SpeechT5ForTextToSpeech.from_pretrained(tts_model_name)
|
15 |
processor = SpeechT5Processor.from_pretrained(tts_model_name)
|
|
|
|
|
16 |
speaker_embeddings = torch.tensor(load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")["xvector"][0]).unsqueeze(0)
|
17 |
|
18 |
# Function to translate text
|
@@ -30,6 +32,17 @@ def synthesize_speech(text, target_lang):
|
|
30 |
# Save the speech to a file
|
31 |
output_path = "output.wav"
|
32 |
sf.write(output_path, speech.numpy(), samplerate=16000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
return output_path
|
35 |
|
|
|
13 |
tts_model_name = "microsoft/speecht5_tts"
|
14 |
tts_model = SpeechT5ForTextToSpeech.from_pretrained(tts_model_name)
|
15 |
processor = SpeechT5Processor.from_pretrained(tts_model_name)
|
16 |
+
|
17 |
+
# Load speaker embeddings
|
18 |
speaker_embeddings = torch.tensor(load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")["xvector"][0]).unsqueeze(0)
|
19 |
|
20 |
# Function to translate text
|
|
|
32 |
# Save the speech to a file
|
33 |
output_path = "output.wav"
|
34 |
sf.write(output_path, speech.numpy(), samplerate=16000)
|
35 |
+
|
36 |
+
# Check if the audio file was generated correctly
|
37 |
+
try:
|
38 |
+
with open(output_path, 'rb') as f:
|
39 |
+
audio_data = f.read()
|
40 |
+
if not audio_data:
|
41 |
+
st.error("Error: The audio file is empty.")
|
42 |
+
else:
|
43 |
+
st.success("Audio generated successfully.")
|
44 |
+
except Exception as e:
|
45 |
+
st.error(f"Error reading the audio file: {e}")
|
46 |
|
47 |
return output_path
|
48 |
|