mindspark121 commited on
Commit
8a19451
·
verified ·
1 Parent(s): 7acfe1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -1,28 +1,25 @@
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()
 
1
  import os
2
+
3
+ # Install espeak-ng before running the model
4
+ os.system("apt-get update && apt-get install -y espeak-ng")
5
+
6
  from TTS.api import TTS
7
+ import gradio as gr
8
 
9
+ # Load Coqui TTS Model (VITS)
10
  tts = TTS("tts_models/en/ljspeech/vits", progress_bar=False).to("cpu")
11
 
12
  def text_to_speech(text):
13
  """Generate Speech from Text"""
14
  output_path = "output.wav"
 
 
15
  tts.tts_to_file(text=text, file_path=output_path)
16
+ return output_path
 
 
 
 
 
17
 
18
  # Gradio UI
19
  gr.Interface(
20
  fn=text_to_speech,
21
  inputs=gr.Textbox(placeholder="Enter text to convert to speech"),
22
+ outputs=gr.Audio(type="filepath"),
23
  title="Coqui TTS - Text to Speech",
24
  description="Enter text and listen to the generated speech.",
25
  ).launch()