Skip to content

refactor(#1023): extract containsWakePhrase, resolve wake model from selected engine#1066

Open
lokhor wants to merge 2 commits into
mainfrom
feature/1023-wakeword-utils-refactor
Open

refactor(#1023): extract containsWakePhrase, resolve wake model from selected engine#1066
lokhor wants to merge 2 commits into
mainfrom
feature/1023-wakeword-utils-refactor

Conversation

@lokhor
Copy link
Copy Markdown
Collaborator

@lokhor lokhor commented Jun 2, 2026

Summary

Pure refactor — no behavioural changes. Extracts containsWakePhrase() from SherpaOnnxVoiceInputController.Companion into a shared top-level utility and promotes transcribeBlocking() to the VoiceInputController interface. Additionally, the wake-word verification engine now follows the user's selected online STT model instead of always using Zipformer.

Changes — Round 1: Extraction

File Change
core/voice/.../WakeWordUtils.kt (new) Top-level fun String.containsWakePhrase() — same regex, public visibility
core/voice/.../VoiceInputController.kt Adds suspend fun transcribeBlocking(pcm: ShortArray): String? = null with doc comment
core/voice/.../SherpaOnnxVoiceInputController.kt Removes companion containsWakePhrase; changes transcribeBlocking to override suspend fun ... String? (null on failure)
app/.../WakeWordService.kt Calls voiceInputController.transcribeBlocking(pcm)?.containsWakePhrase() ?: false instead of hardcoded Sherpa field; drops unused injection
core/voice/.../SherpaOnnxVoiceInputControllerTest.kt Removes the 5 containsWakePhrase tests + stale import
core/voice/.../WakeWordUtilsTest.kt (new) Same 5 test cases against top-level function, MockK-free

Changes — Round 2: Model selection for wake verification

transcribeBlocking() previously hardcoded SherpaSttModelSpec.WAKE_VERIFICATION_DEFAULT (Zipformer). It now resolves the user's selected engine and uses it when it's an online recognizer (Zipformer/Paraformer), falling back to Zipformer for offline-only models (SenseVoice/Whisper).

File Change
core/voice/.../SherpaOnnxVoiceInputController.kt transcribeBlockingresolveSpec() + Online check; added releaseWakeRecognizer() to prevent native memory leak on engine switch; ensureWakeRecognizerBlocking doc/log updated
feature/settings/.../VoiceViewModel.kt Added resolveWakeEngineForDownload() helper; both download sites use it instead of hardcoding SherpaZipformer
core/voice/.../SherpaSttModelSpec.kt WAKE_VERIFICATION_DEFAULT doc updated to reflect fallback role
docs/SPECIFICATION.md Zipformer table row and wake-word verification section updated

Behaviour matrix

Selected engine Wake verification model
Zipformer Zipformer (same model, separate instance)
Paraformer Paraformer (same model, separate instance)
SenseVoice Zipformer (fallback — offline-only)
Whisper Zipformer (fallback — offline-only)

Verification

  • :core:voice:test
  • :app:testDebugUnitTest
  • assembleDebug
  • No stale references to SherpaOnnxVoiceInputController.Companion.containsWakePhrase or the removed field

Closes #1023

@lokhor lokhor marked this pull request as ready for review June 2, 2026 02:32
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Debug APK ready

Download app-debug.apk

Commit: f2e24a1 - Build #2067

Updated on each push. Removed when PR is merged or closed.

@lokhor lokhor changed the title refactor(#1023): extract containsWakePhrase, add transcribeBlocking to VoiceInputController interface refactor(#1023): extract containsWakePhrase, resolve wake model from selected engine Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor containsWakePhrase into shared utility and add transcribeBlocking to all STT controllers

1 participant