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