fix(transcribe): select multilingual model before download (#2303)

This commit is contained in:
Miguel Ángel
2026-07-16 12:03:09 -04:00
committed by GitHub
parent 75eedf5cc1
commit 584be6d64a
4 changed files with 45 additions and 4 deletions
@@ -1,6 +1,7 @@
import { describe, expect, it, test } from "vitest";
import {
dtwPresetForModel,
initialModelForLanguage,
isWhisperTimeoutError,
resolveAudioPreparationTimeoutMs,
resolveWhisperTimeoutMs,
@@ -245,3 +246,21 @@ describe("resolveAudioPreparationTimeoutMs", () => {
expect(resolveAudioPreparationTimeoutMs(Number.NaN)).toBe(120_000);
});
});
describe("initialModelForLanguage", () => {
test("keeps the default English-only model when no language is specified", () => {
expect(initialModelForLanguage("small.en", undefined)).toBe("small.en");
});
test("uses the multilingual model before downloading for explicit German", () => {
expect(initialModelForLanguage("small.en", "de")).toBe("small");
});
test("keeps English-only models for English locale variants", () => {
expect(initialModelForLanguage("small.en", "en-US")).toBe("small.en");
});
test("keeps an already multilingual model unchanged", () => {
expect(initialModelForLanguage("large-v3", "de")).toBe("large-v3");
});
});
+9 -1
View File
@@ -386,6 +386,14 @@ export function dtwPresetForModel(model: string): string {
return model.replace(/-/g, ".");
}
export function initialModelForLanguage(model: string, language?: string): string {
const baseLanguage = language?.trim().toLowerCase().split(/[-_]/, 1)[0];
if (baseLanguage && baseLanguage !== "en" && model.endsWith(".en")) {
return model.slice(0, -3);
}
return model;
}
/**
* Transcribe an audio or video file and save transcript.json to the output directory.
*/
@@ -395,7 +403,7 @@ export async function transcribe(
outputDir: string,
options?: TranscribeOptions,
): Promise<TranscribeResult> {
const model = options?.model ?? DEFAULT_MODEL;
const model = initialModelForLanguage(options?.model ?? DEFAULT_MODEL, options?.language);
// 1. Ensure whisper binary
options?.onProgress?.("Checking whisper...");