pr0fixi commited on
Commit
0149ced
·
verified ·
1 Parent(s): 17813a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -1,17 +1,25 @@
1
- from fastapi import FastAPI, Query
2
- from TTS.api import TTS
3
- from fastapi.responses import FileResponse
4
  import gradio as gr
5
- import os
6
- import uuid
7
-
8
- app = FastAPI()
9
 
10
  # Initialize Coqui TTS
11
  tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False)
12
 
13
- @app.get("/generate-speech/")
14
- def generate_speech(text: str = Query(..., description="Text to convert to speech")):
15
- output_file = f"/tmp/{uuid.uuid4()}.wav"
16
  tts.tts_to_file(text=text, file_path=output_file)
17
- return FileResponse(output_file, media_type="audio/wav")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from TTS.api import TTS
 
 
 
3
 
4
  # Initialize Coqui TTS
5
  tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False)
6
 
7
+ def generate_speech(text):
8
+ # Generate a unique filename for the audio
9
+ output_file = "/tmp/output.wav"
10
  tts.tts_to_file(text=text, file_path=output_file)
11
+ return output_file
12
+
13
+ # Create a Gradio interface
14
+ with gr.Blocks() as demo:
15
+ gr.Markdown("# Coqui TTS Demo")
16
+ gr.Markdown("Type some text and hear it spoken!")
17
+
18
+ input_text = gr.Textbox(label="Enter Text", placeholder="Type something...")
19
+ output_audio = gr.Audio(label="Generated Speech", type="filepath")
20
+
21
+ submit_button = gr.Button("Generate Speech")
22
+ submit_button.click(generate_speech, inputs=input_text, outputs=output_audio)
23
+
24
+ # Launch the app
25
+ demo.launch()