Skip to content

Commit c6f5ddc

Browse files
committed
hotfix: Allow user to pass whisper language as special token
1 parent bfa5d66 commit c6f5ddc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/models/whisper/common_whisper.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ export function whisper_language_to_code(language) {
135135
if (language_code === undefined) {
136136
// User provided something that is not a language name
137137

138+
// Perhaps the user passed the special token itself
139+
const language_special_token = language.match(/^<\|([a-z]{2})\|>$/);
140+
if (language_special_token) {
141+
language = language_special_token[1];
142+
}
143+
138144
if (WHISPER_LANGUAGE_MAPPING.has(language)) {
139145
// User provided the language code directly (e.g., "en")
140146
language_code = language;
@@ -144,7 +150,7 @@ export function whisper_language_to_code(language) {
144150
const is_language_code = language.length === 2;
145151
const langs = is_language_code ? WHISPER_LANGUAGE_MAPPING.keys() : WHISPER_LANGUAGE_MAPPING.values();
146152

147-
throw new Error(`Language "${language}" is not supported. Must be one of: ${JSON.stringify(langs)}`);
153+
throw new Error(`Language "${language}" is not supported. Must be one of: ${JSON.stringify(Array.from(langs))}`);
148154
}
149155
}
150156
return language_code;

0 commit comments

Comments
 (0)