mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-10-16 22:15:36 +08:00
添加健康检查端点和音频上传功能
This commit is contained in:
parent
338498ad68
commit
0bde5d4a81
55
api.py
55
api.py
@ -157,7 +157,7 @@ import torch
|
|||||||
import torchaudio
|
import torchaudio
|
||||||
import librosa
|
import librosa
|
||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
from fastapi import FastAPI, Request, Query
|
from fastapi import FastAPI, Request, Query, UploadFile, File
|
||||||
from fastapi.responses import StreamingResponse, JSONResponse
|
from fastapi.responses import StreamingResponse, JSONResponse
|
||||||
import base64
|
import base64
|
||||||
import io
|
import io
|
||||||
@ -1429,11 +1429,64 @@ async def control(request: Request):
|
|||||||
return handle_control(json_post_raw.get("command"))
|
return handle_control(json_post_raw.get("command"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health")
|
||||||
|
async def health_check():
|
||||||
|
"""
|
||||||
|
健康检查端点
|
||||||
|
"""
|
||||||
|
return JSONResponse({
|
||||||
|
"code": 0,
|
||||||
|
"message": "API is running",
|
||||||
|
"status": "ok"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@app.get("/control")
|
@app.get("/control")
|
||||||
async def control(command: str = None):
|
async def control(command: str = None):
|
||||||
return handle_control(command)
|
return handle_control(command)
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/upload_audio")
|
||||||
|
async def upload_audio(file: UploadFile = File(...)):
|
||||||
|
"""
|
||||||
|
上传参考音频文件
|
||||||
|
返回服务器上的文件路径
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# 创建上传目录
|
||||||
|
upload_dir = Path("uploaded_audio")
|
||||||
|
upload_dir.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
# 生成唯一文件名
|
||||||
|
file_ext = os.path.splitext(file.filename)[1] or ".wav"
|
||||||
|
unique_filename = f"{uuid.uuid4()}{file_ext}"
|
||||||
|
file_path = upload_dir / unique_filename
|
||||||
|
|
||||||
|
# 保存文件
|
||||||
|
content = await file.read()
|
||||||
|
with open(file_path, "wb") as f:
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
|
# 返回相对路径
|
||||||
|
return JSONResponse({
|
||||||
|
"code": 0,
|
||||||
|
"message": "上传成功",
|
||||||
|
"data": {
|
||||||
|
"path": str(file_path),
|
||||||
|
"filename": unique_filename
|
||||||
|
}
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
return JSONResponse({
|
||||||
|
"code": 400,
|
||||||
|
"message": f"上传失败: {str(e)}"
|
||||||
|
}, status_code=400)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/change_refer")
|
@app.post("/change_refer")
|
||||||
async def change_refer(request: Request):
|
async def change_refer(request: Request):
|
||||||
json_post_raw = await request.json()
|
json_post_raw = await request.json()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user