From ff88049afd1964248942bc49a1dcc6ff86403ee4 Mon Sep 17 00:00:00 2001 From: hex2077 Date: Sun, 5 Oct 2025 23:22:12 +0800 Subject: [PATCH] =?UTF-8?q?perf(tts):=20=E5=A2=9E=E5=8A=A0=E6=89=80?= =?UTF-8?q?=E6=9C=89TTS=E9=80=82=E9=85=8D=E5=99=A8=E7=9A=84API=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将IndexTTS、EdgeTTS、FishAudio、Minimax、Doubao和Gemini等所有TTS适配器的API请求超时时间从30-60秒统一增加到90秒,以提高音频生成的稳定性,避免因网络延迟导致的请求超时问题。 --- server/tts_adapters.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/tts_adapters.py b/server/tts_adapters.py index 09f523c..0145407 100644 --- a/server/tts_adapters.py +++ b/server/tts_adapters.py @@ -111,7 +111,7 @@ class IndexTTSAdapter(TTSAdapter): try: print(f"Calling IndexTTS API with voice {voice_code}...") - response = requests.get(api_url, stream=True, timeout=30) + response = requests.get(api_url, stream=True, timeout=90) response.raise_for_status() temp_audio_file = os.path.join(output_dir, f"temp_audio_{uuid.uuid4()}.wav") @@ -147,7 +147,7 @@ class EdgeTTSAdapter(TTSAdapter): try: print(f"Calling EdgeTTS API with voice {voice_code}...") - response = requests.get(api_url, stream=True, timeout=30) + response = requests.get(api_url, stream=True, timeout=90) response.raise_for_status() temp_audio_file = os.path.join(output_dir, f"temp_audio_{uuid.uuid4()}.mp3") @@ -192,7 +192,7 @@ class FishAudioAdapter(TTSAdapter): try: print(f"Calling FishAudio API with voice {voice_code}...") - response = requests.post(self.api_url, data=packed_payload, headers=self.headers, timeout=60) # Increased timeout for FishAudio + response = requests.post(self.api_url, data=packed_payload, headers=self.headers, timeout=90) # Increased timeout for FishAudio temp_audio_file = os.path.join(output_dir, f"temp_audio_{uuid.uuid4()}.mp3") with open(temp_audio_file, "wb") as f: @@ -236,7 +236,7 @@ class MinimaxAdapter(TTSAdapter): try: print(f"Calling Minimax API with voice {voice_code}...") - response = requests.post(self.api_url, json=payload, headers=self.headers, timeout=60) # Increased timeout for Minimax + response = requests.post(self.api_url, json=payload, headers=self.headers, timeout=90) # Increased timeout for Minimax temp_audio_file = os.path.join(output_dir, f"temp_audio_{uuid.uuid4()}.mp3") response_data = response.json() @@ -252,7 +252,7 @@ class MinimaxAdapter(TTSAdapter): raise RuntimeError("Minimax API returned success but no audio URL found when output_format is not hex.") # 下载音频文件 - audio_response = requests.get(audio_url, stream=True, timeout=30) + audio_response = requests.get(audio_url, stream=True, timeout=90) audio_response.raise_for_status() with open(temp_audio_file, 'wb') as f: for chunk in audio_response.iter_content(chunk_size=8192): @@ -289,7 +289,7 @@ class DoubaoTTSAdapter(TTSAdapter): self.headers["X-Api-Access-Key"] = self.headers["X-Api-Access-Key"].replace("{{X-Api-Access-Key}}", self.tts_extra_params["X-Api-Access-Key"]) print(f"Calling Doubao TTS API with voice {voice_code}...") - response = session.post(self.api_url, headers=self.headers, json=payload, stream=True, timeout=30) + response = session.post(self.api_url, headers=self.headers, json=payload, stream=True, timeout=90) response.raise_for_status() audio_data = bytearray() @@ -356,7 +356,7 @@ class GeminiTTSAdapter(TTSAdapter): self.headers['x-goog-api-key'] = gemini_api_key print(f"Calling Gemini TTS API with voice {voice_code}...") - response = requests.post(api_url, headers=self.headers, json=payload, timeout=60) + response = requests.post(api_url, headers=self.headers, json=payload, timeout=90) response.raise_for_status() response_data = response.json()