usmanzia commited on
Commit
68b6b2b
·
verified ·
1 Parent(s): c9e45c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -2,26 +2,33 @@ import gradio as gr
2
  import torch
3
  from TTS.api import TTS
4
 
5
- # Load model (fast_pitch from Coqui TTS)
6
- tts = TTS(model_name="tts_models/en/ljspeech/fast_pitch")
7
-
8
- # Set the device manually if CUDA is available
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- tts.device = device # Manually set the device
 
 
11
 
12
  def generate_audio(text):
13
- # Generate speech
14
  output_path = "output.wav"
15
- tts.tts_to_file(text, output_path)
16
- return output_path
 
 
 
 
 
17
 
18
  # Gradio Interface with a button
19
  interface = gr.Interface(
20
- fn=generate_audio,
21
- inputs=[gr.Textbox(label="Enter Text"), gr.Button("Synthesize")],
22
- outputs="audio",
23
- live=False # Make it non-live as we are using a button
 
 
24
  )
25
 
26
  # Launch Gradio app
27
- interface.launch(share=True)
 
 
2
  import torch
3
  from TTS.api import TTS
4
 
5
+ # Check for GPU availability
 
 
 
6
  device = "cuda" if torch.cuda.is_available() else "cpu"
7
+
8
+ # Load Coqui TTS Model (without 'device' argument)
9
+ tts = TTS(model_name="tts_models/en/ljspeech/fast_pitch", progress_bar=False)
10
 
11
  def generate_audio(text):
12
+ """Function to synthesize speech from text."""
13
  output_path = "output.wav"
14
+ print("Generating audio...") # Debugging log
15
+
16
+ # Convert text to speech
17
+ tts.tts_to_file(text, file_path=output_path)
18
+
19
+ print("Audio saved:", output_path) # Debugging log
20
+ return output_path # Returning file path to Gradio
21
 
22
  # Gradio Interface with a button
23
  interface = gr.Interface(
24
+ fn=generate_audio,
25
+ inputs=gr.Textbox(label="Enter text"),
26
+ outputs=gr.Audio(label="Generated Speech"),
27
+ title="Coqui TTS Text-to-Speech",
28
+ description="Enter text and click **Synthesize** to generate speech.",
29
+ live=True
30
  )
31
 
32
  # Launch Gradio app
33
+ if __name__ == "__main__":
34
+ interface.launch(share=True)