Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,17 @@ import io
|
|
| 4 |
|
| 5 |
def text_to_speech(text):
|
| 6 |
if text:
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
iface = gr.Interface(
|
| 15 |
fn=text_to_speech,
|
|
@@ -17,8 +22,8 @@ iface = gr.Interface(
|
|
| 17 |
outputs=gr.outputs.Audio(type="numpy", label="Voice"),
|
| 18 |
title="Text to Speech",
|
| 19 |
description="Enter text and click 'Generate' to convert it to speech.",
|
| 20 |
-
theme="
|
| 21 |
-
live=False,
|
| 22 |
)
|
| 23 |
|
| 24 |
iface.launch()
|
|
|
|
| 4 |
|
| 5 |
def text_to_speech(text):
|
| 6 |
if text:
|
| 7 |
+
try:
|
| 8 |
+
# Use gTTS to convert text to speech and save it as an MP3 file
|
| 9 |
+
speech = gtts.gTTS(text)
|
| 10 |
+
mp3_data = io.BytesIO()
|
| 11 |
+
speech.save(mp3_data)
|
| 12 |
+
mp3_data.seek(0)
|
| 13 |
+
return mp3_data.read()
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return str(e)
|
| 16 |
+
else:
|
| 17 |
+
return None
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=text_to_speech,
|
|
|
|
| 22 |
outputs=gr.outputs.Audio(type="numpy", label="Voice"),
|
| 23 |
title="Text to Speech",
|
| 24 |
description="Enter text and click 'Generate' to convert it to speech.",
|
| 25 |
+
theme="blue", # Set the theme to blue
|
| 26 |
+
live=False, # Set live to False to use a "Generate" button
|
| 27 |
)
|
| 28 |
|
| 29 |
iface.launch()
|