From 9b933012a816a449bd8f8498f795baaa4f512a21 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Mon, 3 Aug 2026 00:27:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A2=84=E7=BD=AE=E9=9F=B3=E8=89=B2=20p?= =?UTF-8?q?review=20=E6=94=B9=E4=B8=BA=E9=A1=BA=E5=BA=8F=E7=94=9F=E6=88=90?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=20DashScope=20429=20=E9=99=90?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 ThreadPoolExecutor 并行调用,改为 for 循环顺序调用 - 并行4路TTS触发 DashScope RateQuota 限流(HTTP 429) - 顺序调用+内存缓存7天:首次请求逐个合成,后续全部命中缓存 - 异常降级:合成失败时返回硬编码 fallback URL --- apps/api/app/api/routes/voices.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/apps/api/app/api/routes/voices.py b/apps/api/app/api/routes/voices.py index ed0a9f996..d03e7fa76 100755 --- a/apps/api/app/api/routes/voices.py +++ b/apps/api/app/api/routes/voices.py @@ -7,7 +7,6 @@ from __future__ import annotations import logging import time -from concurrent.futures import ThreadPoolExecutor, as_completed from typing import Literal, Optional from app.api.routes._helpers import get_user_plan @@ -97,23 +96,20 @@ def _resolve_all_preset_preview_urls( presets: list, cosyvoice: CosyVoiceService, ) -> dict[str, str]: - """并行解析所有预置音色的 preview_url. + """顺序解析所有预置音色的 preview_url. + + 采用顺序调用(而非并行)以避免触发 DashScope API 速率限制。 + 首次调用后结果缓存 7 天,后续请求直接命中缓存。 Returns: voice_id -> preview_url 映射 """ result_map: dict[str, str] = {} - with ThreadPoolExecutor(max_workers=4) as executor: - future_to_voice = { - executor.submit(_resolve_preset_preview_url, p.voice_id, p.preview_url, cosyvoice): p.voice_id - for p in presets - } - for future in as_completed(future_to_voice): - vid = future_to_voice[future] - try: - result_map[vid] = future.result() - except Exception: - result_map[vid] = "" + for p in presets: + try: + result_map[p.voice_id] = _resolve_preset_preview_url(p.voice_id, p.preview_url, cosyvoice) + except Exception: + result_map[p.voice_id] = p.preview_url return result_map -- 2.54.0