From d219392e5b58e2f03f1d54e3be05adb3af5e5c8f Mon Sep 17 00:00:00 2001
From: LauraGPT <18321252+LauraGPT@users.noreply.github.com>
Date: Sat, 18 Jul 2026 21:33:07 +0000
Subject: [PATCH] fix(stt): anchor Qwen3-ASR envelope stripping
---
tests/tools/test_transcription_tools.py | 24 ++++++++++++++++++++++++
tools/transcription_tools.py | 2 +-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/tests/tools/test_transcription_tools.py b/tests/tools/test_transcription_tools.py
index c0186513a0e..9cfe47a50c8 100644
--- a/tests/tools/test_transcription_tools.py
+++ b/tests/tools/test_transcription_tools.py
@@ -1850,6 +1850,30 @@ class TestTranscribeAudioElevenLabsDispatch:
assert mock_elevenlabs.call_args[0][1] == "scribe_v2"
+# ============================================================================
+# _extract_transcript_text
+# ============================================================================
+
+class TestExtractTranscriptText:
+ def test_strips_qwen3_asr_language_envelope(self):
+ from tools.transcription_tools import _extract_transcript_text
+
+ result = _extract_transcript_text(
+ "language zh\nzh\n你好,世界",
+ )
+
+ assert result == "你好,世界"
+
+ def test_keeps_non_envelope_marker_literal(self):
+ from tools.transcription_tools import _extract_transcript_text
+
+ result = _extract_transcript_text(
+ "The user literally said while reading markup.",
+ )
+
+ assert result == "The user literally said while reading markup."
+
+
# Shell safety — shlex.split on auto-detected templates
# ============================================================================
class TestShellSafety:
diff --git a/tools/transcription_tools.py b/tools/transcription_tools.py
index 0b14e34bbcf..725020ed369 100644
--- a/tools/transcription_tools.py
+++ b/tools/transcription_tools.py
@@ -2095,7 +2095,7 @@ def _extract_transcript_text(transcription: Any) -> str:
text = str(transcription).strip()
marker = ""
- if marker in text:
+ if text.lstrip().lower().startswith("language") and marker in text:
text = text.split(marker, 1)[1].strip()
return text