Update app.py
Browse files
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
|
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 |
-
|
14 |
-
|
15 |
-
output_file =
|
16 |
tts.tts_to_file(text=text, file_path=output_file)
|
17 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|