pm6six commited on
Commit
263d442
1 Parent(s): 571c406

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -1,30 +1,33 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
3
 
4
- # Initialize text-to-speech model (small lightweight model)
5
- tts_model = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
 
 
 
 
 
6
 
7
  # Streamlit app UI
8
  st.title("Text-to-Audio App")
9
- st.text("This app generates audio from text input using Hugging Face models.")
10
 
11
  # User input
12
- text_input = st.text_area("Enter some text for the model:")
13
 
14
  if st.button("Generate Audio"):
15
  if not text_input.strip():
16
  st.error("Please enter some text!")
17
  else:
18
- # Generate response
19
- st.text("Generating audio response...")
20
- tts_audio = tts_model(text_input)
 
21
 
22
- # Save the audio output
23
- audio_file = "response.wav"
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