Skip to content

Commit 217fdd2

Browse files
authored
fix(qwen-asr): map ISO language codes to the names Qwen3-ASR expects (#10959)
request.language usually carries an ISO 639-1 code (e.g. "de"), which OpenAI-compatible clients such as Home Assistant / wyoming_openai send, but qwen_asr.validate_language() only accepts full English names ("German") and raises ValueError otherwise. Normalize the requested language: accept full names case-insensitively, translate ISO codes (with optional region suffix like "de-DE") to the expected name, and pass anything unrecognised through so qwen_asr still reports it clearly. Fixes #10958 Signed-off-by: Tai An <antai12232931@outlook.com>
1 parent 0e0221b commit 217fdd2

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

backend/python/qwen-asr/backend.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,55 @@ def is_int(s):
4040
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
4141
MAX_WORKERS = int(os.environ.get('PYTHON_GRPC_MAX_WORKERS', '1'))
4242

43+
# Languages Qwen3-ASR understands, spelled the way its validate_language()
44+
# expects (full English names). Used to accept case-insensitive names and to
45+
# leave anything already valid untouched.
46+
_QWEN_ASR_SUPPORTED_LANGUAGES = (
47+
"Chinese", "English", "Cantonese", "Arabic", "German", "French", "Spanish",
48+
"Portuguese", "Indonesian", "Italian", "Korean", "Russian", "Thai",
49+
"Vietnamese", "Japanese", "Turkish", "Hindi", "Malay", "Dutch", "Swedish",
50+
"Danish", "Finnish", "Polish", "Czech", "Filipino", "Persian", "Greek",
51+
"Romanian", "Hungarian", "Macedonian",
52+
)
53+
54+
# OpenAI-compatible clients (Home Assistant / wyoming_openai, Whisper tooling,
55+
# ...) send ISO 639-1 codes such as "de", but qwen_asr only accepts the full
56+
# names above. Map the codes for every supported language to its name.
57+
_LANGUAGE_CODE_TO_NAME = {
58+
"zh": "Chinese", "en": "English", "yue": "Cantonese", "ar": "Arabic",
59+
"de": "German", "fr": "French", "es": "Spanish", "pt": "Portuguese",
60+
"id": "Indonesian", "it": "Italian", "ko": "Korean", "ru": "Russian",
61+
"th": "Thai", "vi": "Vietnamese", "ja": "Japanese", "tr": "Turkish",
62+
"hi": "Hindi", "ms": "Malay", "nl": "Dutch", "sv": "Swedish",
63+
"da": "Danish", "fi": "Finnish", "pl": "Polish", "cs": "Czech",
64+
"fil": "Filipino", "tl": "Filipino", "fa": "Persian", "el": "Greek",
65+
"ro": "Romanian", "hu": "Hungarian", "mk": "Macedonian",
66+
}
67+
68+
69+
def _normalize_language(language):
70+
"""Translate an ISO language code into the name Qwen3-ASR expects.
71+
72+
``request.language`` typically carries an ISO 639-1 code ("de", "de-DE"),
73+
but ``qwen_asr.validate_language`` only accepts full English names
74+
("German"). Names that are already valid (in any case) are returned with
75+
their canonical spelling, and anything unrecognised is passed through
76+
unchanged so qwen_asr keeps raising its own descriptive error.
77+
"""
78+
if not language:
79+
return language
80+
key = language.strip()
81+
if not key:
82+
return language
83+
lowered = key.lower()
84+
# Already a full language name (compare case-insensitively).
85+
for name in _QWEN_ASR_SUPPORTED_LANGUAGES:
86+
if lowered == name.lower():
87+
return name
88+
# ISO code, optionally with a region/script suffix like "de-DE" / "zh_CN".
89+
code = lowered.replace("_", "-").split("-", 1)[0]
90+
return _LANGUAGE_CODE_TO_NAME.get(code, key)
91+
4392

4493
class BackendServicer(backend_pb2_grpc.BackendServicer):
4594
def Health(self, request, context):
@@ -299,7 +348,7 @@ def AudioTranscription(self, request, context):
299348

300349
language = None
301350
if request.language and request.language.strip():
302-
language = request.language.strip()
351+
language = _normalize_language(request.language.strip())
303352

304353
ctx = ""
305354
if request.prompt and request.prompt.strip():
@@ -374,4 +423,4 @@ def signal_handler(sig, frame):
374423
parser = argparse.ArgumentParser(description="Run the gRPC server.")
375424
parser.add_argument("--addr", default="localhost:50051", help="The address to bind the server to.")
376425
args = parser.parse_args()
377-
serve(args.addr)
426+
serve(args.addr)

0 commit comments

Comments
 (0)