1/**
2 * transcribe.cpp accepts a language only when it equals an entry of the GGUF's
3 * `general.languages` byte for byte. Nemotron Streaming 3.5 lists `de-DE` where the catalog
4 * says `de`, so the request carries the loaded model's own spelling. "auto" omits the hint.
5 */
6export function nativeSpeechLanguage(
7 advertised: readonly string[],
8 language: string,
9): string | undefined {
10 if (language === "auto") return undefined;
11 const tag = (value: string) => value.toLowerCase().replaceAll("_", "-");
12 const wanted = tag(language);
13 return (
14 advertised.find((entry) => entry === language) ??
15 advertised.find((entry) => tag(entry) === wanted) ??
16 (wanted.includes("-")
17 ? undefined
18 : advertised.find((entry) => tag(entry).split("-", 1)[0] === wanted)) ??
19 language
20 );
21}