Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,20 @@ import gtts
|
|
| 3 |
import io
|
| 4 |
|
| 5 |
def text_to_speech(text):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
iface = gr.Interface(
|
| 14 |
fn=text_to_speech,
|
| 15 |
-
inputs="text",
|
| 16 |
-
outputs=gr.Audio(type="numpy", label="Voice"),
|
| 17 |
title="Text to Speech",
|
| 18 |
description="Enter text and click 'Generate' to convert it to speech.",
|
| 19 |
theme="compact",
|
|
|
|
| 3 |
import io
|
| 4 |
|
| 5 |
def text_to_speech(text):
|
| 6 |
+
if text:
|
| 7 |
+
# Use gTTS to convert text to speech and save it as an MP3 file
|
| 8 |
+
speech = gtts.gTTS(text)
|
| 9 |
+
mp3_data = io.BytesIO()
|
| 10 |
+
speech.save(mp3_data)
|
| 11 |
+
mp3_data.seek(0)
|
| 12 |
+
return mp3_data.read()
|
| 13 |
+
else:
|
| 14 |
+
return None
|
| 15 |
|
| 16 |
iface = gr.Interface(
|
| 17 |
fn=text_to_speech,
|
| 18 |
+
inputs=gr.inputs.Textbox(default="Enter text here...", label="Input Text"),
|
| 19 |
+
outputs=gr.outputs.Audio(type="numpy", label="Voice"),
|
| 20 |
title="Text to Speech",
|
| 21 |
description="Enter text and click 'Generate' to convert it to speech.",
|
| 22 |
theme="compact",
|