fix: 简化ChatTTS调用,只传text参数
This commit is contained in:
29
server.py
29
server.py
@@ -185,25 +185,24 @@ async def synthesize(
|
||||
# 生成唯一文件名
|
||||
filename = f"{uuid.uuid4().hex}.wav"
|
||||
|
||||
# 合成参数(ChatTTS 新版本参数)
|
||||
infer_params = {}
|
||||
|
||||
# 合成语音
|
||||
logger.info(f"Synthesizing: {text[:50]}...")
|
||||
|
||||
# ChatTTS 生成(新版本 API)
|
||||
audio_tensor = model.infer(
|
||||
text,
|
||||
temperature=temperature,
|
||||
top_P=top_p,
|
||||
top_K=top_k,
|
||||
)
|
||||
# ChatTTS 基本调用(简化版)
|
||||
# 返回: list of audio tensors
|
||||
result = model.infer(text)
|
||||
|
||||
# 返回可能是列表或tensor
|
||||
if isinstance(audio_tensor, list):
|
||||
audio_tensor = audio_tensor[0]
|
||||
if isinstance(audio_tensor, tuple):
|
||||
audio_tensor = audio_tensor[0]
|
||||
# 处理返回结果
|
||||
if isinstance(result, list):
|
||||
audio_tensor = result[0]
|
||||
elif isinstance(result, tuple):
|
||||
audio_tensor = result[0]
|
||||
else:
|
||||
audio_tensor = result
|
||||
|
||||
# 确保 tensor 正确形状
|
||||
if audio_tensor.dim() == 1:
|
||||
audio_tensor = audio_tensor.unsqueeze(0)
|
||||
|
||||
# 保存音频
|
||||
filepath = save_audio(audio_tensor, filename)
|
||||
|
||||
Reference in New Issue
Block a user