File size: 555 Bytes
a15b3d8
 
f3e0fbe
 
7ceebd8
f3e0fbe
a15b3d8
 
 
f3e0fbe
a15b3d8
 
 
 
 
f3e0fbe
 
 
a15b3d8
 
7ceebd8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from fastapi import FastAPI
from pydantic import BaseModel
from huggingface_hub import snapshot_download
from transformers import pipeline
import os

class TTSRequest(BaseModel):
    text: str

app = FastAPI()
model_dir = snapshot_download(
    "blacknight3113/edith",
    repo_type="model",
    use_auth_token=True
)
tts = pipeline("text-to-speech", model=model_dir)

@app.post("/tts")
async def tts_api(req: TTSRequest):
    out = tts(req.text, forward_params={"do_sample": True})
    return {"sr": out["sampling_rate"], "audio": out["audio"].tolist()}