(language: string | undefined)
| 119 | // non-empty but unsupported, fellBackFrom is set to the original input so |
| 120 | // callers can surface a warning. |
| 121 | export function normalizeLanguageForSTT(language: string | undefined): { |
| 122 | code: string |
| 123 | fellBackFrom?: string |
| 124 | } { |
| 125 | if (!language) return { code: DEFAULT_STT_LANGUAGE } |
| 126 | const lower = language.toLowerCase().trim() |
| 127 | if (!lower) return { code: DEFAULT_STT_LANGUAGE } |
| 128 | if (SUPPORTED_LANGUAGE_CODES.has(lower)) return { code: lower } |
| 129 | const fromName = LANGUAGE_NAME_TO_CODE[lower] |
| 130 | if (fromName) return { code: fromName } |
| 131 | const base = lower.split('-')[0] |
| 132 | if (base && SUPPORTED_LANGUAGE_CODES.has(base)) return { code: base } |
| 133 | return { code: DEFAULT_STT_LANGUAGE, fellBackFrom: language } |
| 134 | } |
| 135 | |
| 136 | // Lazy-loaded voice module. We defer importing voice.ts (and its native |
| 137 | // audio-capture-napi dependency) until voice input is actually activated. |
no test coverage detected