Transcription: don't pass task/language to English-only models
Whisper ".en" models reject `task`/`language`; transformers.js throws "Cannot specify `task` or `language` for an English-only model" if either is passed — and the web engine passed `task: 'transcribe'` (plus a possibly-undefined `language`) unconditionally. Since the default model is tiny.en, web/PWA transcription failed for every default user. Only add `task`/`language` for multilingual models now (translation also requires a multilingual model), and never pass an explicit `undefined` language (which trips the same check). Mirror the same gate on native (whisper.rn) so a .en model is never asked to do a language/translate it can't. tsc clean, 279 tests pass, web export OK. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -117,13 +117,22 @@ export const engine: TranscriptionEngine = {
|
||||
const asr = loaded.get(opts.modelId);
|
||||
if (!asr) throw new Error(`Model "${opts.modelId}" is not loaded; call loadModel() first.`);
|
||||
|
||||
const out = await asr(audio.samples, {
|
||||
// English-only Whisper models (".en") reject `language`/`task` — transformers.js
|
||||
// throws "Cannot specify `task` or `language` for an English-only model" if
|
||||
// either is passed. Only multilingual models accept them (translation also
|
||||
// requires a multilingual model). So we add those keys ONLY when multilingual,
|
||||
// and never pass an explicit `undefined` language (which trips the same check).
|
||||
const genOpts: Record<string, unknown> = {
|
||||
return_timestamps: true,
|
||||
// One window at a time; 30s matches Whisper's frame so it won't re-chunk.
|
||||
chunk_length_s: 30,
|
||||
language: opts.language,
|
||||
task: opts.translate ? 'translate' : 'transcribe',
|
||||
});
|
||||
};
|
||||
if (MODELS[opts.modelId].multilingual) {
|
||||
genOpts.task = opts.translate ? 'translate' : 'transcribe';
|
||||
if (opts.language) genOpts.language = opts.language;
|
||||
}
|
||||
|
||||
const out = await asr(audio.samples, genOpts);
|
||||
|
||||
const segments: Segment[] = [];
|
||||
for (const c of out.chunks ?? []) {
|
||||
|
||||
Reference in New Issue
Block a user