Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,19 +27,27 @@ if uploaded_file is not None:
|
|
| 27 |
if text.strip() == "":
|
| 28 |
st.warning("No text found in the PDF. Please upload a valid document.")
|
| 29 |
else:
|
| 30 |
-
#
|
| 31 |
st.subheader("Generate Speech")
|
| 32 |
-
|
|
|
|
| 33 |
tts = TTS(model_name)
|
|
|
|
|
|
|
| 34 |
audio_path = "output.wav"
|
| 35 |
-
tts.tts_to_file(text, audio_path)
|
| 36 |
-
st.success("Speech generation complete!")
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
| 27 |
if text.strip() == "":
|
| 28 |
st.warning("No text found in the PDF. Please upload a valid document.")
|
| 29 |
else:
|
| 30 |
+
# Select TTS model
|
| 31 |
st.subheader("Generate Speech")
|
| 32 |
+
st.info("Using TTS single-speaker model: 'tts_models/en/ljspeech/tacotron2-DDC'")
|
| 33 |
+
model_name = "tts_models/en/ljspeech/tacotron2-DDC" # Single-speaker model
|
| 34 |
tts = TTS(model_name)
|
| 35 |
+
|
| 36 |
+
# Specify output file
|
| 37 |
audio_path = "output.wav"
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
try:
|
| 40 |
+
# Generate speech
|
| 41 |
+
tts.tts_to_file(text=text, file_path=audio_path) # Ensure no `speaker` for single-speaker models
|
| 42 |
+
st.success("Speech generation complete!")
|
| 43 |
+
|
| 44 |
+
# Audio playback
|
| 45 |
+
st.audio(audio_path, format="audio/wav", start_time=0)
|
| 46 |
|
| 47 |
+
# Cleanup button
|
| 48 |
+
if st.button("Clear Audio"):
|
| 49 |
+
os.remove("uploaded.pdf")
|
| 50 |
+
os.remove(audio_path)
|
| 51 |
+
st.experimental_rerun()
|
| 52 |
+
except Exception as e:
|
| 53 |
+
st.error(f"Error generating speech: {e}")
|