Skip to content

fix(tts): stop overwriting the Edge TTS User-Agent (403 on every synthesis) - #10141

Open
biao-1010 wants to merge 1 commit into
AstrBotDevs:masterfrom
biao-1010:fix/edge-tts-user-agent
Open

biao-1010 wants to merge 1 commit into
AstrBotDevs:masterfrom
biao-1010:fix/edge-tts-user-agent

Conversation

@biao-1010

@biao-1010 biao-1010 commented Sep 19, 2026

Copy link
Copy Markdown

Problem

astrbot/core/provider/sources/edge_tts_source.py overwrote a shared SDK header:

from edge_tts.constants import WSS_HEADERS
WSS_HEADERS["User-Agent"] = DEFAULT_USER_AGENT

This replaces edge-tts' browser-like User-Agent

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

with astrbot/<version>. Microsoft's readaloud WebSocket endpoint rejects a
non-browser UA, so Edge TTS failed for every reply:

[Core] [ERRO] [sources.edge_tts_source:127]: 音频生成失败: 403,
message='Invalid response status',
url='wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1'

Reproduction

Same machine, same text, only the UA differs:

UA Result
SDK default (browser-like Edge UA) synthesis succeeds, 9.7 KB mp3
set to astrbot/4.28.1 raises inside edge_tts.communicate.stream

Confirmed against the live endpoint, and it matches the 403 logged by AstrBot
on every TTS attempt (voice replies, WebUI voice-call plugin, etc.).

Fix

Keep the SDK default User-Agent and drop the two imports that become unused.
A comment records why the header must not be overwritten.

Verification

  • Local synthesis produces a valid mp3 again.
  • The WebUI voice-call plugin can hear the bot's voice (it previously stayed
    silent because TTS always failed).

Summary by Sourcery

Bug Fixes:

  • Restore Edge TTS synthesis by preserving the SDK’s browser-like User-Agent instead of replacing it with AstrBot’s version identifier.

…hesis)

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/<version>". 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.
@biao-1010
biao-1010 force-pushed the fix/edge-tts-user-agent branch from 4aa79bc to fe6963a Compare September 19, 2026 15:33

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant