muqeet1234 commited on
Commit
5c147df
·
verified ·
1 Parent(s): cc9e151

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -28
app.py CHANGED
@@ -1,43 +1,31 @@
1
  import streamlit as st
2
- import pyttsx3
3
  import os
4
 
5
- # Initialize the TTS engine
6
- engine = pyttsx3.init()
7
-
8
- # Configure Streamlit interface
9
  st.title("Text-to-Speech Converter")
10
- st.write("Convert your text into speech quickly and easily.")
11
-
12
- # User input for text
13
- user_input = st.text_area("Enter the text you want to convert to speech:", "")
14
-
15
- # Speed and voice options
16
- voice_option = st.selectbox("Select Voice:", ("Male", "Female"))
17
- rate = st.slider("Speech Rate:", min_value=100, max_value=200, value=150)
18
 
19
- # Apply user settings to the TTS engine
20
- voices = engine.getProperty("voices")
21
- engine.setProperty("voice", voices[0].id if voice_option == "Male" else voices[1].id)
22
- engine.setProperty("rate", rate)
23
 
24
- # Convert text to speech and save as audio file
25
  if st.button("Convert to Speech"):
26
  if user_input.strip():
27
- audio_file = "output_audio.mp3"
28
- engine.save_to_file(user_input, audio_file)
29
- engine.runAndWait()
30
 
31
- # Display audio player and download link
32
- st.audio(audio_file, format="audio/mp3")
33
- with open(audio_file, "rb") as file:
34
- st.download_button("Download Audio", file, file_name="output_audio.mp3", mime="audio/mp3")
 
 
35
 
36
  # Clean up
37
- os.remove(audio_file)
38
  else:
39
- st.error("Please enter some text to convert.")
40
 
41
  # Footer
42
  st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.")
43
-
 
1
  import streamlit as st
2
+ from gtts import gTTS
3
  import os
4
 
5
+ # Streamlit app setup
 
 
 
6
  st.title("Text-to-Speech Converter")
7
+ st.write("Enter your text below to convert it into speech.")
 
 
 
 
 
 
 
8
 
9
+ # Text input
10
+ user_input = st.text_area("Enter text here:", "")
 
 
11
 
 
12
  if st.button("Convert to Speech"):
13
  if user_input.strip():
14
+ # Generate speech
15
+ tts = gTTS(user_input, lang="en")
16
+ tts.save("output.mp3")
17
 
18
+ # Display audio player
19
+ st.audio("output.mp3", format="audio/mp3")
20
+
21
+ # Provide download link
22
+ with open("output.mp3", "rb") as audio_file:
23
+ st.download_button("Download Audio", audio_file, file_name="output.mp3", mime="audio/mp3")
24
 
25
  # Clean up
26
+ os.remove("output.mp3")
27
  else:
28
+ st.error("Please enter some text.")
29
 
30
  # Footer
31
  st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.")