-
-
Notifications
You must be signed in to change notification settings - Fork 887
Implement microwakeword detection #6312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2fc7c27
Add microfrontend gradle module
TimoPtr 9bf58c9
Add litert deps for full and minimal
TimoPtr 0ee9ddd
PoC of AssistVoiceInteractionService and MicroWakeWord using Claude
TimoPtr 5844a90
Adjust DevPlayground style
TimoPtr c23a060
Fix lint issues
TimoPtr 6898d02
Revert unwanted commit
TimoPtr f04966a
Add other models and load configurations
TimoPtr e0ef0cd
Fix ndk typo
TimoPtr 582ee68
Use MicroWakeWord json config
TimoPtr 2c08d3c
Improve Kotlin code
TimoPtr 639d493
Update Kotlin code for clarity and add tests
TimoPtr d0dded1
Merge branch 'main' into feature/wake_word
TimoPtr 8eb0aa7
Update lockfile
TimoPtr 6734641
Fix lint issue
TimoPtr 6dc9b72
Fix test setup
TimoPtr 7240608
Handle full flavor test
TimoPtr 9d49b4e
Enable back strict mode
TimoPtr c7430b9
Merge remote-tracking branch 'origin/main' into feature/wake_word
TimoPtr a39bd8a
Apply suggestions from code review
TimoPtr 4f537ca
Merge remote-tracking branch 'origin/main' into feature/wake_word
TimoPtr ca89655
Cleanup docs
TimoPtr 9daf8f4
Bump lockfile
TimoPtr 78c443b
Merge branch 'main' into feature/wake_word
TimoPtr 6faa7e9
Update lockfile
TimoPtr 3ae2386
Apply PR suggestions and add a test to avoid duplicate channels
TimoPtr 011ca85
Remove automotive service
TimoPtr 039d041
Merge branch 'main' into feature/wake_word
TimoPtr 9e80b5a
Update lockfiles
TimoPtr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,9 @@ | |
| # Compiled class file | ||
| *.class | ||
|
|
||
| ### CPP ### | ||
| **/.cxx/* | ||
|
|
||
| # Log file | ||
| *.log | ||
|
|
||
|
|
||
Large diffs are not rendered by default.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
...dTest/kotlin/io/homeassistant/companion/android/assist/wakeword/MicroWakeWordModelTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package io.homeassistant.companion.android.assist.wakeword | ||
|
|
||
| import android.content.Context | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import io.homeassistant.companion.android.BuildConfig | ||
| import kotlinx.coroutines.test.runTest | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Assume.assumeTrue | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import timber.log.Timber | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class MicroWakeWordModelTest { | ||
|
|
||
| private val appContext: Context | ||
| get() = InstrumentationRegistry.getInstrumentation().targetContext | ||
|
|
||
| /** | ||
| * Initializes TfLite and returns true if successful. | ||
| * Returns false if initialization fails (e.g., full flavor without GMS). | ||
| */ | ||
| private suspend fun tryInitializeTfLite(): Boolean { | ||
| return try { | ||
| TfLiteInitializerImpl().initialize(appContext) | ||
| true | ||
| } catch (e: Exception) { | ||
| Timber.w(e, "TfLite initialization failed, skipping test") | ||
| if (BuildConfig.FLAVOR == "full") { | ||
| false | ||
| } else { | ||
| // In minimal the test should run since we use the embedded version of TfLite | ||
| throw e | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun loadsModelsFromAppAssets_verify_models_config_files() = runTest { | ||
| val models = MicroWakeWordModelConfig.loadAvailableModels(appContext) | ||
|
|
||
| assertTrue("Expected at least one wake word model", models.isNotEmpty()) | ||
|
|
||
| // Verify each model has required fields populated | ||
| for (model in models) { | ||
| assertTrue("Wake word should not be blank", model.wakeWord.isNotBlank()) | ||
| assertTrue("Author should not be blank", model.author.isNotBlank()) | ||
| assertTrue("Website should not be blank", model.website.isNotBlank()) | ||
| assertTrue("Model file name should not be blank", model.model.isNotBlank()) | ||
| assertTrue("Trained languages should not be empty", model.trainedLanguages.isNotEmpty()) | ||
| assertTrue("Version should be positive", model.version > 0) | ||
| assertTrue("Probability cutoff should be between 0 and 1", model.micro.probabilityCutoff in 0f..1f) | ||
| assertTrue("Sliding window size should be positive", model.micro.slidingWindowSize > 0) | ||
| assertTrue("Feature step size should be positive", model.micro.featureStepSize > 0) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun microWakeWord_loadsAndProcessesAudio_withAllModels() = runTest { | ||
| assumeTrue("TfLite not available", tryInitializeTfLite()) | ||
| val models = MicroWakeWordModelConfig.loadAvailableModels(appContext) | ||
|
|
||
| for (model in models) { | ||
| val detector = MicroWakeWord.create(appContext, model) | ||
|
|
||
| try { | ||
| // Process silent audio (160 samples = 10ms at 16kHz) | ||
| val silentAudio = ShortArray(160) | ||
| val detected = detector.processAudio(silentAudio) | ||
|
|
||
| // Silent audio should not trigger detection | ||
| assertFalse( | ||
| "Silent audio should not trigger '${model.wakeWord}' detection", | ||
| detected, | ||
| ) | ||
| } finally { | ||
| detector.close() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun microWakeWord_canResetState_withoutCrashing() = runTest { | ||
| assumeTrue("TfLite not available", tryInitializeTfLite()) | ||
| val models = MicroWakeWordModelConfig.loadAvailableModels(appContext) | ||
| val model = models.first() | ||
|
|
||
| val detector = MicroWakeWord.create(appContext, model) | ||
| try { | ||
| // Process some audio | ||
| detector.processAudio(ShortArray(160)) | ||
| detector.processAudio(ShortArray(160)) | ||
|
|
||
| // Reset should not crash | ||
| detector.reset() | ||
|
|
||
| // Should be able to process more audio after reset | ||
| val detected = detector.processAudio(ShortArray(160)) | ||
| assertFalse(detected) | ||
| } finally { | ||
| detector.close() | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...c/full/kotlin/io/homeassistant/companion/android/assist/wakeword/TfLiteInitializerImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package io.homeassistant.companion.android.assist.wakeword | ||
|
|
||
| import android.content.Context | ||
| import com.google.android.gms.tflite.java.TfLite | ||
| import kotlinx.coroutines.tasks.await | ||
| import timber.log.Timber | ||
|
|
||
| /** | ||
| * TFLite initializer for the full flavor using Google Play Services. | ||
| * | ||
| * Play Services TFLite downloads the runtime on demand, which requires | ||
| * async initialization before the interpreter can be used. | ||
| */ | ||
| class TfLiteInitializerImpl : TfLiteInitializer { | ||
|
|
||
| override suspend fun initialize(context: Context) { | ||
| Timber.d("Initializing TFLite via Play Services") | ||
| try { | ||
| TfLite.initialize(context).await() | ||
| Timber.d("TFLite Play Services initialized successfully") | ||
| } catch (e: Exception) { | ||
| Timber.e(e, "Failed to initialize TFLite Play Services") | ||
| throw e | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.