From 5c3486d98d6af635039b87a028e444075caba185 Mon Sep 17 00:00:00 2001 From: aileenfun <105077614@qq.com> Date: Sat, 15 Mar 2025 21:44:19 +0800 Subject: [PATCH] =?UTF-8?q?fishspeech=20key=E9=80=89=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 2 +- .../core/providers/tts/fishspeech.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 0ff1ac0e7..a7f4e2db4 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -451,7 +451,7 @@ class ConnectionHandler: opus_datas, text_index, tts_file = [], 0, None try: self.logger.bind(tag=TAG).debug("正在处理TTS任务...") - tts_file, text, text_index = future.result(timeout=10) + tts_file, text, text_index = future.result(timeout=20) if text is None or len(text) <= 0: self.logger.bind(tag=TAG).error(f"TTS出错:{text_index}: tts text is empty") elif tts_file is None: diff --git a/main/xiaozhi-server/core/providers/tts/fishspeech.py b/main/xiaozhi-server/core/providers/tts/fishspeech.py index e8af4eb48..ba2c38312 100644 --- a/main/xiaozhi-server/core/providers/tts/fishspeech.py +++ b/main/xiaozhi-server/core/providers/tts/fishspeech.py @@ -92,9 +92,8 @@ class TTSProvider(TTSProviderBase): self.channels = config.get("channels", 1) self.rate = config.get("rate", 44100) self.api_key = config.get("api_key", "YOUR_API_KEY") - have_key = check_model_key("FishSpeech TTS", self.api_key) - if not have_key: - return + self.have_key = check_model_key("FishSpeech TTS", self.api_key) + self.normalize = config.get("normalize", True) self.max_new_tokens = config.get("max_new_tokens", 1024) self.chunk_length = config.get("chunk_length", 200) @@ -136,14 +135,13 @@ class TTSProvider(TTSProviderBase): } pydantic_data = ServeTTSRequest(**data) - + headers={"Content-Type": "application/msgpack"} + if self.have_key: + headers["Authorization"] = f"Bearer {self.api_key}" response = requests.post( self.api_url, data=ormsgpack.packb(pydantic_data, option=ormsgpack.OPT_SERIALIZE_PYDANTIC), - headers={ - "Authorization": f"Bearer {self.api_key}", - "Content-Type": "application/msgpack", - }, + headers=headers ) if response.status_code == 200: