Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
|
|
3 |
|
4 |
-
# Initialize
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Streamlit app UI
|
8 |
st.title("Text-to-Audio App")
|
9 |
-
st.text("This app
|
10 |
|
11 |
# User input
|
12 |
-
text_input = st.text_area("Enter some text
|
13 |
|
14 |
if st.button("Generate Audio"):
|
15 |
if not text_input.strip():
|
16 |
st.error("Please enter some text!")
|
17 |
else:
|
18 |
-
# Generate
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
-
#
|
23 |
-
audio_file =
|
24 |
-
with open(audio_file, "wb") as f:
|
25 |
-
f.write(tts_audio["wav"])
|
26 |
|
27 |
-
# Display audio response
|
28 |
-
st.audio(audio_file, format="audio/wav")
|
29 |
st.success("Audio generated successfully!")
|
30 |
|
|
|
1 |
import streamlit as st
|
2 |
+
import pyttsx3 # For text-to-speech
|
3 |
+
import os
|
4 |
|
5 |
+
# Initialize pyttsx3 TTS engine
|
6 |
+
tts_engine = pyttsx3.init()
|
7 |
+
|
8 |
+
# Configure TTS engine (optional)
|
9 |
+
voices = tts_engine.getProperty("voices")
|
10 |
+
tts_engine.setProperty("voice", voices[0].id) # Choose a voice
|
11 |
+
tts_engine.setProperty("rate", 150) # Set speech rate
|
12 |
|
13 |
# Streamlit app UI
|
14 |
st.title("Text-to-Audio App")
|
15 |
+
st.text("This app converts your text input into audio using TTS.")
|
16 |
|
17 |
# User input
|
18 |
+
text_input = st.text_area("Enter some text:")
|
19 |
|
20 |
if st.button("Generate Audio"):
|
21 |
if not text_input.strip():
|
22 |
st.error("Please enter some text!")
|
23 |
else:
|
24 |
+
# Generate speech
|
25 |
+
audio_file = "output.mp3"
|
26 |
+
tts_engine.save_to_file(text_input, audio_file)
|
27 |
+
tts_engine.runAndWait()
|
28 |
|
29 |
+
# Play the audio in the app
|
30 |
+
st.audio(audio_file, format="audio/mp3")
|
|
|
|
|
31 |
|
|
|
|
|
32 |
st.success("Audio generated successfully!")
|
33 |
|