File size: 765 Bytes
c253bc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from fastapi import FastAPI, Query
import requests

app = FastAPI()

GRADIO_API = "https://buchi-stdesign-sbv2-editor-demo.hf.space/run/predict"
GRADIO_FILE_BASE = "https://buchi-stdesign-sbv2-editor-demo.hf.space/file"

@app.get("/voice")
def get_voice(text: str = Query(...), style: str = "小春音アミ"):
    payload = {
        "data": [text, style, 1.0, 1.0, 0.5]
    }
    headers = {"Content-Type": "application/json"}
    res = requests.post(GRADIO_API, json=payload, headers=headers)
    
    if res.status_code != 200:
        return {"error": "Gradio backend error", "detail": res.text}
    
    result = res.json()
    wav_path = result["data"][0]  # tmp/audio.wav
    wav_url = f"{GRADIO_FILE_BASE}/{wav_path}"
    
    return {"audio_url": wav_url}