fix: 修复ChatTTS API参数调用方式
This commit is contained in:
51
server.py
51
server.py
@@ -185,22 +185,25 @@ async def synthesize(
|
||||
# 生成唯一文件名
|
||||
filename = f"{uuid.uuid4().hex}.wav"
|
||||
|
||||
# 合成参数
|
||||
params = {
|
||||
'temperature': temperature,
|
||||
'top_p': top_p,
|
||||
'top_k': top_k,
|
||||
'spk_emb': None, # 可选:说话人嵌入
|
||||
}
|
||||
# 合成参数(ChatTTS 新版本参数)
|
||||
infer_params = {}
|
||||
|
||||
# 合成语音
|
||||
logger.info(f"Synthesizing: {text[:50]}...")
|
||||
|
||||
# ChatTTS 生成
|
||||
# ChatTTS 生成(新版本 API)
|
||||
audio_tensor = model.infer(
|
||||
[text],
|
||||
params=params
|
||||
)[0] # 返回是列表,取第一个
|
||||
text,
|
||||
temperature=temperature,
|
||||
top_P=top_p,
|
||||
top_K=top_k,
|
||||
)
|
||||
|
||||
# 返回可能是列表或tensor
|
||||
if isinstance(audio_tensor, list):
|
||||
audio_tensor = audio_tensor[0]
|
||||
if isinstance(audio_tensor, tuple):
|
||||
audio_tensor = audio_tensor[0]
|
||||
|
||||
# 保存音频
|
||||
filepath = save_audio(audio_tensor, filename)
|
||||
@@ -235,14 +238,15 @@ async def synthesize_batch(requests: list[SynthesizeRequest]):
|
||||
texts = [r.text for r in requests]
|
||||
|
||||
# 统一参数
|
||||
params = {
|
||||
'temperature': requests[0].temperature,
|
||||
'top_p': requests[0].top_p,
|
||||
'top_k': requests[0].top_k,
|
||||
}
|
||||
infer_params = {}
|
||||
|
||||
# 批量生成
|
||||
audio_tensors = model.infer(texts, params=params)
|
||||
audio_tensors = model.infer(
|
||||
texts,
|
||||
temperature=requests[0].temperature,
|
||||
top_P=requests[0].top_p,
|
||||
top_K=requests[0].top_k,
|
||||
)
|
||||
|
||||
results = []
|
||||
for i, audio_tensor in enumerate(audio_tensors):
|
||||
@@ -337,6 +341,19 @@ async def synthesize_with_emotion(
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=PORT) audio_url=f"/audio/{filename}",
|
||||
duration=round(duration, 2),
|
||||
text=text,
|
||||
timestamp=datetime.now().isoformat()
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Emotion synthesis error: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=PORT)
|
||||
Reference in New Issue
Block a user