vishal2002 commited on
Commit
e1b4aaf
1 Parent(s): 0e2ee76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,16 +1,13 @@
1
  import gradio as gr
2
- from transformers import Text2SpeechForConditionalGeneration, Text2SpeechTokenizer
3
-
4
- # Load TTS model and tokenizer
5
- model_name = "facebook/wav2vec2-base-960h"
6
- tts_model = Text2SpeechForConditionalGeneration.from_pretrained(model_name)
7
- tokenizer = Text2SpeechTokenizer.from_pretrained(model_name)
8
 
9
  def text_to_speech(text):
10
- inputs = tokenizer(text, return_tensors="pt", clean_up_tokenization_spaces=True)
11
- with gr.Output() as out:
12
- speech = tts_model.generate(**inputs)
13
- gr.Audio(speech[0].numpy(), type="audio/wav")
14
 
15
  iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio")
16
  iface.launch()
 
1
  import gradio as gr
2
+ from gtts import gTTS
3
+ import tempfile
4
+ import os
 
 
 
5
 
6
  def text_to_speech(text):
7
+ tts = gTTS(text=text, lang='en')
8
+ _, temp_path = tempfile.mkstemp(suffix=".mp3")
9
+ tts.save(temp_path)
10
+ return temp_path
11
 
12
  iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio")
13
  iface.launch()