Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(mobile): use any downloaded on-device model before asking for a download (#2549)
Chad Pihad8ebdfb6effc
diff --git a/openwhispr-mobile/src/components/settings/OnDeviceModelSection.tsx b/openwhispr-mobile/src/components/settings/OnDeviceModelSection.tsxindex 07253069b..4261dae94 100644--- a/openwhispr-mobile/src/components/settings/OnDeviceModelSection.tsx+++ b/openwhispr-mobile/src/components/settings/OnDeviceModelSection.tsx@@ -14,7 +14,6 @@ import {localModelCoversLanguages,selectLocalEngine,type LocalEngineAvailability,- type LocalEngineChoice,} from '@/services/transcription/localEngine';import { useModelDownloadStore } from '@/store/useModelDownloadStore';@@ -23,11 +22,16 @@ type Props = {picked: LocalModelKey | undefined;};-function modelInUse(choice: LocalEngineChoice): string {+function modelInUse(languages: string[], availability: LocalEngineAvailability): string {+ const choice = selectLocalEngine(languages, availability);if (choice.engine === 'none') return 'No model is downloaded yet.';const key: LocalModelKey =choice.engine === 'whisper' ? 'whisper-base' : `parakeet-${choice.version}`;- return `Using ${LOCAL_MODEL_TITLES[key]}.`;+ // Automatic uses the only downloaded model even when it misses a language.+ const missesLanguages = localModelCoversLanguages(key, languages)+ ? ''+ : " It doesn't cover your languages.";+ return `Using ${LOCAL_MODEL_TITLES[key]}.${missesLanguages}`;}function radio(selected: boolean): { icon: string; mdIcon: 'CircleCheck' | 'Circle' } {@@ -74,7 +78,7 @@ export function OnDeviceModelSection({ scope, picked }: Props): React.JSX.Elemen{...radio(!effectivePick)}iconStyle="line"title="Automatic"- description={`Best downloaded model for your languages. ${modelInUse(selectLocalEngine(languages, availability))}`}+ description={`Best downloaded model for your languages. ${modelInUse(languages, availability)}`}selected={!effectivePick}showChevron={false}onPress={() => pickLocalModel(scope, undefined)}diff --git a/openwhispr-mobile/src/components/settings/__tests__/OnDeviceModelSection.test.tsx b/openwhispr-mobile/src/components/settings/__tests__/OnDeviceModelSection.test.tsxindex 6476984ff..713b77269 100644--- a/openwhispr-mobile/src/components/settings/__tests__/OnDeviceModelSection.test.tsx+++ b/openwhispr-mobile/src/components/settings/__tests__/OnDeviceModelSection.test.tsx@@ -93,3 +93,12 @@ it('does not let a model that misses a language be picked, and falls back to Autexpect(mockPickLocalModel).not.toHaveBeenCalled();expect(isSelected('Automatic')).toBe(true);});++it('says when the model Automatic falls back to misses the languages', async () => {+ mockLanguages = ['ja'];+ mockAvailability = { ...mockAvailability, parakeetV2Downloaded: false };+ render(<OnDeviceModelSection scope="dictation" picked={undefined} />);+ expect(+ await screen.findByText(/Using Parakeet v3\. It doesn't cover your languages\./),+ ).toBeTruthy();+});diff --git a/openwhispr-mobile/src/services/transcription/__tests__/localEngine.test.ts b/openwhispr-mobile/src/services/transcription/__tests__/localEngine.test.tsindex 286551b55..b3f0c14be 100644--- a/openwhispr-mobile/src/services/transcription/__tests__/localEngine.test.ts+++ b/openwhispr-mobile/src/services/transcription/__tests__/localEngine.test.ts@@ -68,26 +68,40 @@ describe('selectLocalEngine', () => {expect(selectLocalEngine(['de'], all())).toEqual({ engine: 'parakeet', version: 'v3' });});- it('falls back to Whisper when the preferred Parakeet is not downloaded', () => {+ it('falls back to the next downloaded model that covers the languages', () => {expect(selectLocalEngine(['en'], all({ parakeetV2Downloaded: false }))).toEqual({- engine: 'whisper',+ engine: 'parakeet',+ version: 'v3',});+ expect(+ selectLocalEngine(['en'], all({ parakeetV2Downloaded: false, parakeetV3Downloaded: false })),+ ).toEqual({ engine: 'whisper' });expect(selectLocalEngine(['de'], all({ parakeetV3Downloaded: false }))).toEqual({engine: 'whisper',});});- it('reports the missing preferred model when nothing is downloaded', () => {+ it('uses Parakeet v3 for English when it is the only model downloaded', () => {expect(selectLocalEngine(['en'], all({ parakeetV2Downloaded: false, whisperDownloaded: false })),- ).toEqual({ engine: 'none', preferred: 'parakeet-v2' });- expect(- selectLocalEngine(['de'], all({ parakeetV3Downloaded: false, whisperDownloaded: false })),- ).toEqual({ engine: 'none', preferred: 'parakeet-v3' });- expect(selectLocalEngine([], all({ whisperDownloaded: false }))).toEqual({+ ).toEqual({ engine: 'parakeet', version: 'v3' });+ });++ it('reports the missing preferred model when nothing is downloaded', () => {+ const nothing = {+ parakeetV2Downloaded: false,+ parakeetV3Downloaded: false,+ whisperDownloaded: false,+ };+ expect(selectLocalEngine(['en'], all(nothing))).toEqual({+ engine: 'none',+ preferred: 'parakeet-v2',+ });+ expect(selectLocalEngine(['de'], all(nothing))).toEqual({engine: 'none',- preferred: 'whisper',+ preferred: 'parakeet-v3',});+ expect(selectLocalEngine([], all(nothing))).toEqual({ engine: 'none', preferred: 'whisper' });});it('always routes to Whisper when the native module is unsupported (Android/Expo Go)', () => {@@ -99,11 +113,17 @@ describe('selectLocalEngine', () => {).toEqual({ engine: 'none', preferred: 'whisper' });});- it('never falls "up" to Parakeet for Whisper-bound selections', () => {+ it('uses a downloaded model that misses a language rather than none at all', () => {expect(selectLocalEngine(['ja'], all({ whisperDownloaded: false }))).toEqual({- engine: 'none',- preferred: 'whisper',+ engine: 'parakeet',+ version: 'v3',});+ expect(+ selectLocalEngine([], all({ parakeetV2Downloaded: false, whisperDownloaded: false })),+ ).toEqual({ engine: 'parakeet', version: 'v3' });+ expect(+ selectLocalEngine(['de'], all({ parakeetV3Downloaded: false, whisperDownloaded: false })),+ ).toEqual({ engine: 'parakeet', version: 'v2' });});});diff --git a/openwhispr-mobile/src/services/transcription/localEngine.ts b/openwhispr-mobile/src/services/transcription/localEngine.tsindex 36fa90d79..3ef6b3996 100644--- a/openwhispr-mobile/src/services/transcription/localEngine.ts+++ b/openwhispr-mobile/src/services/transcription/localEngine.ts@@ -105,10 +105,24 @@ function isInstalled(model: LocalModelKey, availability: LocalEngineAvailability: availability.parakeetV3Downloaded;}+// Automatic takes the first downloaded model here that covers every selected language. Each+// Parakeet is the most accurate for what it covers (v2 for English, v3 for its 25 languages), and+// Whisper base covers the rest.+const AUTOMATIC_ORDER: readonly LocalModelKey[] = ['parakeet-v2', 'parakeet-v3', 'whisper-base'];+// With nothing downloaded that covers the languages, a model that misses some still beats no+// transcription; v3 covers more of them than v2. Whisper base never gets here, it covers all.+const UNCOVERED_FALLBACK_ORDER: readonly LocalModelKey[] = ['parakeet-v3', 'parakeet-v2'];++function choiceFor(model: LocalModelKey): Exclude<LocalEngineChoice, { engine: 'none' }> {+ return model === 'whisper-base'+ ? { engine: 'whisper' }+ : { engine: 'parakeet', version: model === 'parakeet-v2' ? 'v2' : 'v3' };+}+/**- * Resolve the preferred engine against what's actually installed. Fallback order: preferred- * Parakeet → Whisper if downloaded → 'none' (caller surfaces a download prompt). Whisper-bound- * selections never fall "up" to Parakeet — it can't cover them.+ * Resolve the engine against what's actually installed: the picked model, else the first entry+ * of AUTOMATIC_ORDER that is downloaded and covers the languages, else any downloaded model.+ * 'none' (caller surfaces a download prompt) only when nothing is downloaded.*/export function selectLocalEngine(languages: readonly string[],@@ -117,32 +131,20 @@ export function selectLocalEngine(// automatic choice, so a deleted model or a language change never breaks transcription.picked?: LocalModelKey,): LocalEngineChoice {- if (picked && isInstalled(picked, availability) && localModelCoversLanguages(picked, languages)) {- return picked === 'whisper-base'- ? { engine: 'whisper' }- : { engine: 'parakeet', version: picked === 'parakeet-v2' ? 'v2' : 'v3' };- }- const preferred = preferredEngineForLanguages(languages);+ const installed = (model: LocalModelKey): boolean => isInstalled(model, availability);+ const usable = (model: LocalModelKey): boolean =>+ installed(model) && localModelCoversLanguages(model, languages);- if (preferred.engine === 'parakeet' && availability.parakeetSupported) {- const downloaded =- preferred.version === 'v2'- ? availability.parakeetV2Downloaded- : availability.parakeetV3Downloaded;- if (downloaded) {- return preferred;- }- if (availability.whisperDownloaded) {- return { engine: 'whisper' };- }- return {- engine: 'none',- preferred: preferred.version === 'v2' ? 'parakeet-v2' : 'parakeet-v3',- };- }+ if (picked && usable(picked)) return choiceFor(picked);+ const model = AUTOMATIC_ORDER.find(usable) ?? UNCOVERED_FALLBACK_ORDER.find(installed);+ if (model) return choiceFor(model);- if (availability.whisperDownloaded) {- return { engine: 'whisper' };- }- return { engine: 'none', preferred: 'whisper' };+ const preferred = preferredEngineForLanguages(languages);+ return {+ engine: 'none',+ preferred:+ preferred.engine === 'parakeet' && availability.parakeetSupported+ ? `parakeet-${preferred.version}`+ : 'whisper',+ };}