pm6six commited on
Commit
60ab783
·
verified ·
1 Parent(s): 2d3fda2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -1,15 +1,7 @@
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.")
@@ -21,10 +13,10 @@ 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")
 
1
  import streamlit as st
2
+ from gtts import gTTS
3
  import os
4
 
 
 
 
 
 
 
 
 
5
  # Streamlit app UI
6
  st.title("Text-to-Audio App")
7
  st.text("This app converts your text input into audio using TTS.")
 
13
  if not text_input.strip():
14
  st.error("Please enter some text!")
15
  else:
16
+ # Generate speech using gTTS
17
+ tts = gTTS(text=text_input, lang="en")
18
  audio_file = "output.mp3"
19
+ tts.save(audio_file)
 
20
 
21
  # Play the audio in the app
22
  st.audio(audio_file, format="audio/mp3")