MAKHLWF commited on
Commit
4b1b73d
·
1 Parent(s): 863ba75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -1,15 +1,19 @@
1
  import gradio as gr
 
 
2
 
3
  def text_to_speech(text):
4
- # Here, you would use a text-to-speech library or service to convert 'text' to speech
5
- # Replace this line with the actual code to convert text to speech
6
- speech = "This is where your text-to-speech conversion code goes."
7
- return speech
 
 
8
 
9
  iface = gr.Interface(
10
  fn=text_to_speech,
11
  inputs="text",
12
- outputs=gr.Audio(type="mp3", label="Voice"),
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",