From fe6963aa66884c9fe3153094ef2e16f98b406f98 Mon Sep 17 00:00:00 2001 From: biao Date: Sat, 19 Sep 2026 23:32:09 +0800 Subject: [PATCH] fix(tts): stop overwriting the Edge TTS User-Agent (403 on every synthesis) edge_tts_source.py overwrote the shared SDK header: WSS_HEADERS["User-Agent"] = DEFAULT_USER_AGENT replacing edge-tts' browser-like UA (Mozilla/5.0 ... Edg/143.0.0.0) with "astrbot/". Microsoft's readaloud WebSocket endpoint rejects a non-browser UA with: 403, message='Invalid response status', url='wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1' so Edge TTS failed for every reply. Reproduction (same machine, same text): - SDK default UA -> synthesis succeeds (9.7 KB mp3) - UA set to "astrbot/4.28.1" -> raises inside edge_tts.communicate.stream Fix: keep the SDK default UA and drop the two imports that become unused. Verified locally: synthesis works again and the WebUI voice-call plugin can hear the bot's replies. --- astrbot/core/provider/sources/edge_tts_source.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/astrbot/core/provider/sources/edge_tts_source.py b/astrbot/core/provider/sources/edge_tts_source.py index 3cf39883ec..2f3762273e 100644 --- a/astrbot/core/provider/sources/edge_tts_source.py +++ b/astrbot/core/provider/sources/edge_tts_source.py @@ -3,10 +3,8 @@ import subprocess import edge_tts -from edge_tts.constants import WSS_HEADERS from astrbot.core import logger -from astrbot.core.provider.headers import DEFAULT_USER_AGENT from astrbot.core.utils.astrbot_path import get_astrbot_temp_path from astrbot.core.utils.datetime_utils import generate_timestamp_id @@ -14,8 +12,10 @@ from ..provider import TTSProvider from ..register import register_provider_adapter -# Edge TTS exposes synthesis headers as a shared SDK default, not a client option. -WSS_HEADERS["User-Agent"] = DEFAULT_USER_AGENT +# NOTE: do NOT overwrite edge-tts' User-Agent. Microsoft's readaloud endpoint +# answers 403 "Invalid response status" when the UA is not a browser-like Edge UA, +# and the SDK already ships a valid one. Setting WSS_HEADERS["User-Agent"] to +# "astrbot/" broke synthesis for every reply. """ edge_tts 方式,能够免费、快速生成语音,使用需要先安装edge-tts库