multija commited on
Commit
dcc3f8d
verified
1 Parent(s): 4c131c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -22
app.py CHANGED
@@ -1,26 +1,17 @@
1
- import gradio as gr
2
- from f5_tts.inference import inference
3
- import soundfile as sf
4
- import os, requests
5
 
6
- # (mesmo c贸digo de download dos modelos aqui)
 
7
 
8
- def synthesize(text):
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
- iface = gr.Interface(
20
- fn=synthesize,
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
- iface.launch()
 
 
 
 
 
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")