fix: correct Azure TTS locale extraction for SSML xml:lang (#22443)

The locale for Azure TTS SSML was being extracted with `split("-")[:1]`,
which only takes the first segment (e.g., "en" from "en-US"). The
xml:lang attribute in SSML requires a full locale like "en-US", not just
a language code. This caused Azure TTS to either fail or use incorrect
pronunciation rules.

Changed `[:1]` to `[:2]` to properly extract the locale (e.g., "en-US").

Co-authored-by: gambletan <ethanchang32@gmail.com>
This commit is contained in:
Alvin Tang
2026-03-09 05:50:25 +08:00
committed by GitHub
parent a97f5adf95
commit 7aa7bbc390

View File

@@ -492,7 +492,7 @@ async def speech(request: Request, user=Depends(get_verified_user)):
region = request.app.state.config.TTS_AZURE_SPEECH_REGION or "eastus"
base_url = request.app.state.config.TTS_AZURE_SPEECH_BASE_URL
language = request.app.state.config.TTS_VOICE
locale = "-".join(request.app.state.config.TTS_VOICE.split("-")[:1])
locale = "-".join(request.app.state.config.TTS_VOICE.split("-")[:2])
output_format = request.app.state.config.TTS_AZURE_SPEECH_OUTPUT_FORMAT
try: