fix(westernization): translate edge-tts monkey-patch comments from upstream sync

This commit is contained in:
lapy 2026-10-13 11:49:38 +01:00
parent a80ff5084b
commit df6fc3ae76

View file

@ -1,7 +1,7 @@
import os
import uuid
import edge_tts
import edge_tts.communicate # 显式 import,下方要给本模块的 WSS_URL 重新赋值
import edge_tts.communicate # explicit import; WSS_URL is reassigned on this module below
from datetime import datetime
from core.providers.tts.base import TTSProviderBase
from config.logger import setup_logging
@ -9,17 +9,19 @@ from config.logger import setup_logging
TAG = __name__
logger = setup_logging()
# 微软 2026-10 起对 legacy 消费者接口返回 403,edge-tts 7.2.8 仍走
# speech.platform.bing.com 走不通。上游 PR rany2/edge-tts#491 切到
# api.msedgeservices.com 修好,但 7.2.8 仍是 PyPI 最新版本,临时把 WSS_URL 顶住。
# TODO(7.2.9): 升 edge-tts ≥ 7.2.9 后删掉这段 monkey patch。
# Since 2026-10 Microsoft returns 403 for the legacy consumer endpoint, and
# edge-tts 7.2.8 still talks to speech.platform.bing.com, which no longer works.
# Upstream PR rany2/edge-tts#491 fixes it by switching to api.msedgeservices.com,
# but 7.2.8 is still the newest release on PyPI, so temporarily override WSS_URL.
# TODO(7.2.9): remove this monkey patch once edge-tts >= 7.2.9 is available.
_NEW_WSS_URL = (
"wss://api.msedgeservices.com/tts/cognitiveservices/websocket/v1"
f"?Ocp-Apim-Subscription-Key={edge_tts.constants.TRUSTED_CLIENT_TOKEN}"
)
# communicate.py 第 35 行 `from .constants import WSS_URL` 会在 import 时把
# WSS_URL 复制成本模块局部名,只改 edge_tts.constants.WSS_URL 不会生效。
# __stream() 走 LEGB 找的是 edge_tts.communicate.WSS_URL,所以这里两个都要改。
# Line 35 of communicate.py, `from .constants import WSS_URL`, copies WSS_URL
# into a module-local name at import time, so patching only
# edge_tts.constants.WSS_URL has no effect. __stream() resolves WSS_URL via LEGB
# to edge_tts.communicate.WSS_URL, so both names must be patched here.
edge_tts.constants.WSS_URL = _NEW_WSS_URL
edge_tts.communicate.WSS_URL = _NEW_WSS_URL