Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,16 @@
|
|
1 |
-
import
|
2 |
from TTS.api import TTS
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
# Initialize Coqui
|
5 |
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False)
|
6 |
|
7 |
-
|
8 |
-
|
|
|
9 |
tts.tts_to_file(text=text, file_path=output_file)
|
10 |
-
return output_file
|
11 |
-
|
12 |
-
# Create a Gradio interface
|
13 |
-
iface = gr.Interface(
|
14 |
-
fn=generate_speech,
|
15 |
-
inputs="text",
|
16 |
-
outputs="audio",
|
17 |
-
title="Coqui XTTS-v2 Demo",
|
18 |
-
description="Type some text and hear it spoken!"
|
19 |
-
)
|
20 |
-
|
21 |
-
iface.launch()
|
|
|
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 uuid
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
|
9 |
+
# Initialize Coqui TTS
|
10 |
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False)
|
11 |
|
12 |
+
@app.get("/generate-speech/")
|
13 |
+
def generate_speech(text: str = Query(..., description="Text to convert to speech")):
|
14 |
+
output_file = f"/tmp/{uuid.uuid4()}.wav"
|
15 |
tts.tts_to_file(text=text, file_path=output_file)
|
16 |
+
return FileResponse(output_file, media_type="audio/wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|