File size: 891 Bytes
f0d7f2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Import necessary libraries
import streamlit as st
from gtts import gTTS
from io import BytesIO

# Set Streamlit title
st.title("Text-to-Speech App")

# Add a textarea for user input
user_input = st.text_area("Enter the text you want to convert to speech:")

# Function to convert text to speech
def text_to_speech(text):
    # Create a Text-to-Speech object
    tts = gTTS(text=text, lang='en')
    
    # Save the speech as a BytesIO object
    speech_bytes = BytesIO()
    tts.write_to_fp(speech_bytes)
    
    return speech_bytes

# Check if the user has entered any text
if user_input:
    # Add a button to trigger text-to-speech conversion
    if st.button("Convert to Speech"):
        # Convert text to speech
        speech_bytes = text_to_speech(user_input)
        
        # Display the audio player for the generated speech
        st.audio(speech_bytes, format='audio/wav')