File size: 814 Bytes
863ba75
4b1b73d
 
863ba75
 
bed1ab1
acf183c
 
 
 
 
 
f7a0960
acf183c
 
 
 
863ba75
 
 
036908e
 
863ba75
 
b7387a3
 
863ba75
 
 
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
import gradio as gr
import gtts
import io

def text_to_speech(text):
    if text:
        try:
            # Use gTTS to convert text to speech and save it as an MP3 file
            speech = gtts.gTTS(text)
            mp3_data = io.BytesIO()
            speech.save(mp3_data)
            mp3_data.seek(0)
            return mp3_data.getvalue()
        except Exception as e:
            return str(e)
    else:
        return None

iface = gr.Interface(
    fn=text_to_speech,
    inputs=gr.inputs.Text(default="Enter text here...", label="Input Text"),  # Use gr.inputs.Text
    outputs=gr.outputs.Audio(label="Voice"),  # Use the 'numpy' type by default
    title="Text to Speech",
    description="Enter text and click 'Generate' to convert it to speech.",
    theme="blue",
    live=False,
)

iface.launch()