Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,19 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def text_to_speech(text):
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
iface = gr.Interface(
|
| 10 |
fn=text_to_speech,
|
| 11 |
inputs="text",
|
| 12 |
-
outputs=gr.Audio(type="
|
| 13 |
title="Text to Speech",
|
| 14 |
description="Enter text and click 'Generate' to convert it to speech.",
|
| 15 |
theme="compact",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import gtts
|
| 3 |
+
import io
|
| 4 |
|
| 5 |
def text_to_speech(text):
|
| 6 |
+
# Use gTTS to convert text to speech and save it as an MP3 file
|
| 7 |
+
speech = gtts.gTTS(text)
|
| 8 |
+
mp3_data = io.BytesIO()
|
| 9 |
+
speech.save(mp3_data)
|
| 10 |
+
mp3_data.seek(0)
|
| 11 |
+
return mp3_data.read()
|
| 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",
|