mindspark121 commited on
Commit
12486b9
·
verified ·
1 Parent(s): 609e154

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,20 +1,28 @@
1
- from TTS.api import TTS
2
  import gradio as gr
 
3
 
4
- # Load TTS Model
5
- tts = TTS("tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False).to("cpu")
6
 
7
  def text_to_speech(text):
8
  """Generate Speech from Text"""
9
  output_path = "output.wav"
 
 
10
  tts.tts_to_file(text=text, file_path=output_path)
11
- return output_path
 
 
 
 
 
12
 
13
  # Gradio UI
14
  gr.Interface(
15
  fn=text_to_speech,
16
  inputs=gr.Textbox(placeholder="Enter text to convert to speech"),
17
- outputs=gr.Audio(),
18
  title="Coqui TTS - Text to Speech",
19
  description="Enter text and listen to the generated speech.",
20
  ).launch()
 
1
+ import os
2
  import gradio as gr
3
+ from TTS.api import TTS
4
 
5
+ # Load a better model (VITS for high quality)
6
+ tts = TTS("tts_models/en/ljspeech/vits", progress_bar=False).to("cpu")
7
 
8
  def text_to_speech(text):
9
  """Generate Speech from Text"""
10
  output_path = "output.wav"
11
+
12
+ # Generate TTS audio
13
  tts.tts_to_file(text=text, file_path=output_path)
14
+
15
+ # Ensure the file exists before returning
16
+ if os.path.exists(output_path):
17
+ return output_path
18
+ else:
19
+ return "Error generating speech"
20
 
21
  # Gradio UI
22
  gr.Interface(
23
  fn=text_to_speech,
24
  inputs=gr.Textbox(placeholder="Enter text to convert to speech"),
25
+ outputs=gr.Audio(type="filepath"), # Ensure correct format
26
  title="Coqui TTS - Text to Speech",
27
  description="Enter text and listen to the generated speech.",
28
  ).launch()