Implement locale and Norwegian language configuration
epic-speech-to-text-input-speech-engine-task-003 — Implement locale configuration logic within SpeechRecognitionService that selects nb-NO as the primary locale and falls back to no-NO or en-US if unavailable. Query NativeSpeechApiBridge for available locales, validate Norwegian support, and expose a localesAvailable stream. Log a warning if nb-NO is absent so QA can flag accuracy failures early.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Extract locale selection into a top-level or static pure function selectBestLocale(List
Do not re-query on each startListening() call — locale availability is device-level and does not change during an app session. Expose localesAvailable as a BehaviorSubject-equivalent (or a StateProvider in Riverpod) so it immediately emits the current value to new subscribers.
Testing Requirements
Unit tests for the pure selectBestLocale() function covering: nb-NO available (returns nb-NO), only no-NO available (returns no-NO + warning), only en-US available (returns en-US + warning), empty list (returns en-US + warning), list with nb-NO and others (still returns nb-NO). Integration test on a Norwegian device/simulator confirms nb-NO is available and selected. Use flutter_test. Logging assertions can use a custom log capture approach or verify via mock NativeSpeechApiBridge responses.
The speech_to_text Flutter package delegates accuracy entirely to the OS-native engine. Norwegian accuracy for domain-specific vocabulary (medical terms, organisation names, accessibility terminology) may fall below the 85% acceptance threshold on older devices or in noisy environments, causing user frustration and manual correction overhead that negates the time saving.
Mitigation & Contingency
Mitigation: Configure the SpeechRecognitionService with Norwegian as the explicit locale and test against a representative corpus of peer mentoring vocabulary on target devices. Expose locale switching so users can fallback to Bokmål vs Nynorsk. Clearly set user expectations in the UI that transcription is a starting point for editing, not a finished product.
Contingency: If accuracy is consistently below threshold on specific device/OS combinations, add a device-capability check that hides the dictation button with an explanatory message rather than offering a degraded experience. Document affected device models for QA and org contacts.
The speech_to_text Flutter package is a third-party dependency that may introduce breaking API changes or deprecations on major version upgrades, requiring rework of SpeechRecognitionService when Flutter or platform OS versions are updated.
Mitigation & Contingency
Mitigation: Wrap all speech_to_text API calls behind the SpeechRecognitionService interface so that package changes are isolated to one file. Pin the package version in pubspec.yaml and review changelogs before any upgrade. Write integration tests that exercise the package contract so regressions are caught immediately.
Contingency: If the package is abandoned or has unresolvable issues, NativeSpeechApiBridge already provides the platform-channel abstraction needed to implement a direct plugin replacement with minimal changes to SpeechRecognitionService.