MAKHLWF commited on
Commit
bed1ab1
·
1 Parent(s): 4c8135e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -3,17 +3,20 @@ 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",
 
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",