File size: 910 Bytes
2ce9600
263d442
 
d04894f
263d442
 
 
 
 
 
 
2ce9600
 
 
263d442
2ce9600
 
263d442
2ce9600
569b020
 
 
 
263d442
 
 
 
569b020
263d442
 
569b020
 
2ce9600
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import streamlit as st
import pyttsx3  # For text-to-speech
import os

# Initialize pyttsx3 TTS engine
tts_engine = pyttsx3.init()

# Configure TTS engine (optional)
voices = tts_engine.getProperty("voices")
tts_engine.setProperty("voice", voices[0].id)  # Choose a voice
tts_engine.setProperty("rate", 150)  # Set speech rate

# Streamlit app UI
st.title("Text-to-Audio App")
st.text("This app converts your text input into audio using TTS.")

# User input
text_input = st.text_area("Enter some text:")

if st.button("Generate Audio"):
    if not text_input.strip():
        st.error("Please enter some text!")
    else:
        # Generate speech
        audio_file = "output.mp3"
        tts_engine.save_to_file(text_input, audio_file)
        tts_engine.runAndWait()

        # Play the audio in the app
        st.audio(audio_file, format="audio/mp3")

        st.success("Audio generated successfully!")