mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 10:06:21 +00:00
fix(transcribe): select multilingual model before download (#2303)
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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...");
|
||||
|
||||
Reference in New Issue
Block a user