Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,8 @@ st.title("Text to Speech Converter")
|
|
8 |
text_input = st.text_area("Enter text to convert to speech:")
|
9 |
|
10 |
# Load the Hugging Face TTS model
|
11 |
-
|
|
|
12 |
|
13 |
# Button to generate speech
|
14 |
if st.button("Convert to Speech"):
|
@@ -16,14 +17,17 @@ if st.button("Convert to Speech"):
|
|
16 |
# Generate the speech
|
17 |
tts_output = tts_pipeline(text_input)
|
18 |
|
|
|
19 |
# Save the generated speech to a file
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
# Display the audio player in Streamlit
|
24 |
-
st.audio(
|
25 |
else:
|
26 |
st.warning("Please enter some text to convert.")
|
27 |
|
28 |
# Footer
|
29 |
st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/).")
|
|
|
|
8 |
text_input = st.text_area("Enter text to convert to speech:")
|
9 |
|
10 |
# Load the Hugging Face TTS model
|
11 |
+
# Using a more reliable and commonly used model for TTS
|
12 |
+
tts_pipeline = pipeline("text-to-speech", model="microsoft/speecht5_tts")
|
13 |
|
14 |
# Button to generate speech
|
15 |
if st.button("Convert to Speech"):
|
|
|
17 |
# Generate the speech
|
18 |
tts_output = tts_pipeline(text_input)
|
19 |
|
20 |
+
# The output from the pipeline should be an array of speech chunks
|
21 |
# Save the generated speech to a file
|
22 |
+
audio_file_path = "output.wav"
|
23 |
+
with open(audio_file_path, "wb") as f:
|
24 |
+
f.write(tts_output[0]["array"])
|
25 |
|
26 |
# Display the audio player in Streamlit
|
27 |
+
st.audio(audio_file_path)
|
28 |
else:
|
29 |
st.warning("Please enter some text to convert.")
|
30 |
|
31 |
# Footer
|
32 |
st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/).")
|
33 |
+
|