Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
CHANGED
@@ -16,8 +16,11 @@ st.success("Models loaded successfully!")
|
|
16 |
|
17 |
# TTS function
|
18 |
def text_to_speech(text):
|
|
|
19 |
mel_output, mel_length, alignment = tacotron2.encode_text(text)
|
20 |
-
|
|
|
|
|
21 |
audio_path = "output.wav"
|
22 |
write(audio_path, 22050, waveforms.squeeze(1).cpu().numpy())
|
23 |
return audio_path
|
@@ -29,7 +32,10 @@ text = st.text_input("Enter text to convert to speech:")
|
|
29 |
if st.button("Generate Speech"):
|
30 |
if text.strip():
|
31 |
st.write("Generating speech...")
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
34 |
else:
|
35 |
st.warning("Please enter some text.")
|
|
|
16 |
|
17 |
# TTS function
|
18 |
def text_to_speech(text):
|
19 |
+
# Generate mel spectrogram
|
20 |
mel_output, mel_length, alignment = tacotron2.encode_text(text)
|
21 |
+
# Decode mel spectrogram to waveform
|
22 |
+
waveforms = hifi_gan.decode_batch(mel_output)
|
23 |
+
# Save waveform as audio file
|
24 |
audio_path = "output.wav"
|
25 |
write(audio_path, 22050, waveforms.squeeze(1).cpu().numpy())
|
26 |
return audio_path
|
|
|
32 |
if st.button("Generate Speech"):
|
33 |
if text.strip():
|
34 |
st.write("Generating speech...")
|
35 |
+
try:
|
36 |
+
audio_file = text_to_speech(text)
|
37 |
+
st.audio(audio_file, format="audio/wav")
|
38 |
+
except Exception as e:
|
39 |
+
st.error(f"Error during TTS generation: {e}")
|
40 |
else:
|
41 |
st.warning("Please enter some text.")
|