From 24b590d07f41630a6a6f83a96c71865809e3f2c7 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Wed, 22 Apr 2026 17:56:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AE=80=E5=8C=96ChatTTS=E8=B0=83?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E5=8F=AA=E4=BC=A0text=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/server.py b/server.py index 4315195..52e8ec0 100644 --- a/server.py +++ b/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)