Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,17 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
import os, requests
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
audio, sr = inference(
|
| 10 |
-
text=text,
|
| 11 |
-
model_path=MODEL_FILE,
|
| 12 |
-
config_path=CONFIG_FILE,
|
| 13 |
-
vocab_file=VOCAB_FILE,
|
| 14 |
-
device="cpu"
|
| 15 |
-
)
|
| 16 |
-
sf.write("output.wav", audio, sr)
|
| 17 |
-
return "output.wav"
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
inputs=gr.Textbox(lines=3, placeholder="Digite o texto..."),
|
| 22 |
-
outputs=gr.Audio(type="filepath"),
|
| 23 |
-
title="F5-TTS PT-BR",
|
| 24 |
-
)
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Body
|
| 2 |
+
from fastapi.responses import FileResponse
|
| 3 |
+
from TTS.api import TTS
|
|
|
|
| 4 |
|
| 5 |
+
MODEL_FILE = "model/model_last.safetensors"
|
| 6 |
+
CONFIG_FILE = "config/config.yaml"
|
| 7 |
|
| 8 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Carrega o modelo na inicializa莽茫o
|
| 11 |
+
tts_model = TTS(model_path=MODEL_FILE, config_path=CONFIG_FILE)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
@app.post("/tts")
|
| 14 |
+
def tts(text: str = Body(..., embed=True)):
|
| 15 |
+
out_path = "output.wav"
|
| 16 |
+
tts_model.tts_to_file(text=text, file_path=out_path)
|
| 17 |
+
return FileResponse(out_path, media_type="audio/wav", filename="output.wav")
|