Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

docs: drop the wake-word docs

Durganshu Mishra7c9500420885
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 9fb4bf5..75bba22 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -390,7 +390,7 @@ dependencies {
// On-device wake word ("Hey Gotcha") via OpenWakeWord ONNX models run with
// Microsoft's official ONNX Runtime. The three models live in
- // app/src/main/assets/openwakeword (see docs/wake-word.md + docs/MODEL_CARD.md).
+ // app/src/main/assets/openwakeword (see docs/MODEL_CARD.md).
implementation("com.microsoft.onnxruntime:onnxruntime-android:1.26.0")
// Static analysis
diff --git a/docs/wake-word-handoff.md b/docs/wake-word-handoff.md
deleted file mode 100644
index ea6b83b..0000000
--- a/docs/wake-word-handoff.md
+++ /dev/null
@@ -1,134 +0,0 @@
-# Wake Word Handoff
-
-## Goal
-Add an optional wake word ("Hey Gotcha") to the existing Assistive Ball flow
-using [openWakeWord](https://github.com/dscripka/openWakeWord) ONNX models,
-while reusing the current `CallSessionController` voice-call path.
-
-## Current status
-
-### In production (merged)
-- **Engine:** direct Microsoft ONNX Runtime (`com.microsoft.onnxruntime:onnxruntime-android:1.26.0`).
- The detector runs the melspectrogram → speech-embedding → classifier pipeline
- directly, no third-party wrapper.
-- **Models:** three Apache-2.0 ONNX models in
- `app/src/main/assets/openwakeword/` (see `docs/wake-word.md`). The
- classifier (`hey_gotcha.onnx`) was trained by the Gotcha project on
- synthetic Piper-TTS positives and OpenWakeWord's standard negatives.
-- **Settings:** `Settings.wakeWordEnabled` and `Settings.wakeWordSensitivity`,
- persisted by `SettingsRepository`.
-- **Detection integration in `AssistiveBallService`:**
- - listens only while the call controller is idle and both `wakeWordEnabled`
- and `assistiveBallEnabled` are on;
- - stops for active call states, `stopBall()`, and `onDestroy()`;
- - on detection, vibrates and starts the existing call flow through
- `callController.startWakeWordCall()`;
- - pauses while `ttsEngine.isSpeaking` is true so a screen read-aloud that
- contains "gotcha" cannot self-trigger a call;
- - live settings: reacts to `wakeWordSensitivity` changes via
- `settingsChangeNotifier` while idle;
- - surfaces startup errors through the overlay.
-- **Auto-end after the task:** `CallSessionController.startWakeWordCall()`
- plus the `autoEndOnReply` flag, so a wake-word-triggered call ends after
- the spoken reply while ordinary calls keep the existing stay-open behavior.
-- **Hands-free wake-word calls:** after the short wake-word acknowledgment
- ("Yes?") the microphone opens itself; a voice-activity detector
- (`audio/SilenceDetector.kt`) stops it after ~3 s of silence (API STT, via a
- new `AudioRecord` + WAV path in `SttEngine.listenForUtterance`; ~2 s
- platform end-of-speech hint for the Android provider). The transcript then
- runs through the exact same `finishTurn` path as push-to-talk, so the two
- flows behave identically downstream. The mic re-opens for agent questions,
- and two silent listens end the call. Normal long-press calls are untouched
- (`handsFree` is only set by `startWakeWordCall`; `startMic`/`stopMic` are
- no-ops while it is set).
-- **Black/blank screen skip:** `ScreenSnapshot.isMostlyBlack()` drops
- essentially-black screenshots (screen off/blank, common during wake-word
- use) from every voice-call turn and substitutes a short explanatory note,
- so the agent never reasons over a black frame.
-- **Boot restart:** `WakeWordBootReceiver` + manifest registration; only
- fires when both `assistiveBallEnabled` and `wakeWordEnabled` are on.
-- **UI:** `AssistiveBallScreen` exposes a "Wake word: Hey Gotcha" toggle
- and a sensitivity slider, plus a battery-optimization education row.
-- **Tests:** `WakeWordMatcherTest` covers sensitivity → threshold mapping
- and patience; `SettingsTest` covers wake-word defaults; the
- `CallSessionControllerTest` extension covers `startWakeWordCall` success
- and failure paths.
-- **Legal:** `docs/privacy-data-retention.md` documents the wake-word data
- flow (on-device only); `LEGAL_VERSION` bumped to 2 to force re-acceptance.
-- **License notice:** `app/src/main/assets/licenses/openwakeword-notice.txt`
- lists the three bundled models and their Apache-2.0 provenance.
-
-### Architecture pieces intentionally kept engine-agnostic
-- `AssistiveBallService` idle-gating, `stopBall()`, `onDestroy()` cleanup.
-- `CallSessionController.startWakeWordCall()` + `autoEndOnReply`.
-- The `WakeWordBootReceiver` boot path.
-- The `Settings` data class and repository.
-- The `WakeWordDetector` public surface (`start()`/`stop()`/`isRunning()` +
- `onStarted`/`onDetected`/`onError` callbacks + `sensitivityProvider`).
-
-These are reusable if the underlying engine is swapped again (e.g. to a
-custom TFLite classifier).
-
-## Manual device-verification checklist
-
-- [ ] Ball on, microphone granted, wake word on; say "Hey Gotcha" — the ball
- pulses, a short "Yes?" is spoken, **mic opens by itself**, reply spoken,
- call auto-ends.
-- [ ] Speak, pause >3 s (API STT) — mic stops on its own and the turn sends.
-- [ ] Keep speaking — mic stays open (no early cut-off).
-- [ ] Agent asks a question — mic re-opens itself and the spoken answer is
- captured.
-- [ ] Say nothing — after two silent listens the call ends gracefully.
-- [ ] Wake word call with screen off — a black screenshot is NOT injected;
- the LLM sees the "(screen was blank)" note.
-- [ ] Normal long-press call — still push-to-talk, mic/stop buttons work as
- before, no auto-open.
-- [ ] Say "Hey Gotcha" during an active call — ignored (idle gate).
-- [ ] Reboot — listener resumes via `WakeWordBootReceiver`.
-- [ ] TV / music playing near the phone — no false triggers at the balanced
- threshold.
-- [ ] Slide sensitivity to "High precision" — stricter triggers, fewer
- false activations.
-
-## Risks / notes
-
-- The custom classifier is Apache-2.0 because training data and architecture
- are all Apache-2.0 (OpenWakeWord code + Google speech-embedding backbone
- + Piper-TTS-generated positives + OpenWakeWord's standard negatives).
-- The detector runs three small ONNX models continuously; on a modern
- Android device CPU usage is negligible compared to a full ASR engine.
-- Real-device false-accept rates must be validated before shipping the
- always-on listener to users; the `Hey Gotcha` phrase is short and can
- sound similar to casual speech in noisy environments. The sensitivity
- slider and confuser-style pronunciation training give users a way to
- trade off misses vs. false triggers.
-- Mic contention with the call STT is handled by the idle-gate, but
- device-level validation is recommended.
-
-## Files in the wake-word effort
-
-- `app/build.gradle.kts` — adds ONNX Runtime dep.
-- `app/src/main/AndroidManifest.xml` — wake-word boot receiver,
- `REQUEST_IGNORE_BATTERY_OPTIMIZATIONS` permission.
-- `app/src/main/assets/openwakeword/{hey_gotcha.onnx,melspectrogram.onnx,embedding_model.onnx}`
-- `app/src/main/assets/licenses/openwakeword-notice.txt`
-- `app/src/main/assets/legal/privacy-data-retention.md` — wake-word section.
-- `app/src/main/java/com/gotcha/data/SettingsRepository.kt` — fields, persistence, `LEGAL_VERSION` bump.
-- `app/src/main/java/com/gotcha/audio/TtsEngine.kt` — `isSpeaking` tracking.
-- `app/src/main/java/com/gotcha/service/WakeWordDetector.kt` — detector.
-- `app/src/main/java/com/gotcha/service/OnnxWakeWordPipeline.kt` — ONNX pipeline.
-- `app/src/main/java/com/gotcha/service/WakeWordMatcher.kt` — threshold/patience.
-- `app/src/main/java/com/gotcha/service/CallSessionController.kt` — `autoEndOnReply`, hands-free auto-listen loop, black-screen skip.
-- `app/src/main/java/com/gotcha/service/AssistiveBallService.kt` — idle-gate, TTS guard, live settings.
-- `app/src/main/java/com/gotcha/audio/SttEngine.kt` — `listenForUtterance` (VAD hands-free listen + WAV path).
-- `app/src/main/java/com/gotcha/audio/SilenceDetector.kt` — noise-floor-adaptive voice-activity detector.
-- `app/src/main/java/com/gotcha/audio/AudioApi.kt` — transcribe content-type parameter.
-- `app/src/main/java/com/gotcha/agent/ScreenSnapshot.kt` — `isMostlyBlack()`.
-- `app/src/main/java/com/gotcha/tools/WakeWordBootReceiver.kt` — boot restart.
-- `app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt` — toggle + slider + battery row.
-- `app/src/test/java/com/gotcha/service/WakeWordMatcherTest.kt` — unit tests.
-- `app/src/test/java/com/gotcha/data/SettingsTest.kt` — wake-word defaults.
-- `app/src/test/java/com/gotcha/service/CallSessionControllerTest.kt` — wake-word start paths.
-- `app/src/test/java/com/gotcha/audio/SilenceDetectorTest.kt` — VAD decision tests.
-- `app/src/test/java/com/gotcha/agent/ScreenSnapshotTest.kt` — black-frame classification tests.
-- `docs/wake-word.md`, `docs/wake-word-handoff.md`, `docs/MODEL_CARD.md`.
diff --git a/docs/wake-word.md b/docs/wake-word.md
deleted file mode 100644
index 6854492..0000000
--- a/docs/wake-word.md
+++ /dev/null
@@ -1,150 +0,0 @@
-# Wake Word
-
-Gotcha's optional wake word is **"Hey Gotcha"**. It listens locally with the
-bundled [OpenWakeWord](https://github.com/dscripka/openWakeWord) ONNX models —
-no audio leaves the device while the listener is waiting. Only the existing
-voice call sends the spoken command to the configured speech-to-text provider.
-
-## Bundled models
-
-Three Apache-2.0 models live under `app/src/main/assets/openwakeword/`:
-
-| File | Role |
-| :--- | :--- |
-| `hey_gotcha.onnx` | Custom classifier head trained by the Gotcha project on synthetic Piper-TTS positives and OpenWakeWord's standard negative/background data |
-| `embedding_model.onnx` | Google's speech-embedding backbone, as used by OpenWakeWord |
-| `melspectrogram.onnx` | OpenWakeWord melspectrogram front-end |
-
-Provenance and license details are in
-`app/src/main/assets/licenses/openwakeword-notice.txt` and
-[`docs/MODEL_CARD.md`](MODEL_CARD.md).
-
-## Pipeline
-
-Per 80 ms (1280-sample) frame @ 16 kHz mono PCM-16, the
-`WakeWordDetector` runs:
-
-1. **Melspectrogram** — the most recent 1760 samples → `melspectrogram.onnx` →
- 32-bin mel rows, transformed with `spec / 10 + 2`.
-2. **Embedding** — the latest 76 mel rows → `embedding_model.onnx` → one
- 96-dim speech embedding per frame.
-3. **Classification** — the last 16 embeddings → `hey_gotcha.onnx` → a score
- in [0, 1].
-
-Step 1 runs on every frame. Steps 2 and 3 run only when `WakeWordGate` hears
-something — see [Battery](#battery-and-reliability) below.
-
-A `WakeWordMatcher` then maps the user-facing sensitivity slider to the
-score threshold (`threshold = 0.70 − 0.27 × sensitivity`) and requires two
-consecutive qualifying frames before firing. The default sensitivity of 0.75
-corresponds to the model card's balanced threshold of 0.50.
-
-## When the listener runs
-
-- **Wake word enabled** AND **Assistive Ball enabled** AND microphone
- permission granted AND the call state is idle.
-- An unloadable model or unavailable microphone disables detection without
- crashing the service.
-- The detector is paused while the App's own text-to-speech is playing, so
- the App reading "gotcha" aloud does not self-trigger a call.
-
-## Hands-free calls (wake word only)
-
-A wake-word-triggered call is **hands-free**, not push-to-talk:
-
-1. The wake word starts the call and a short acknowledgment ("Yes?") is spoken.
-2. The microphone **opens automatically** once that announcement finishes.
-3. A voice-activity detector listens for the user's speech. When the user
- stops talking for **~3 seconds** (API STT; the on-device Android recognizer
- uses a ~2 s platform end-of-speech hint), the microphone **stops itself**.
-4. From that point the flow is identical to a normal call: the recording is
- transcribed, cleaned, sent to the agent, and the reply is spoken.
-5. The call **ends itself** after the reply (the existing wake-word
- auto-end behaviour), so it never stays open waiting for another tap.
-
-If the agent asks a clarifying question mid-call, the microphone re-opens by
-itself and the answer is captured the same way. After two silent listen
-attempts the call ends gracefully instead of listening forever.
-
-Normal long-press calls are unchanged: they stay push-to-talk, with the same
-mic/stop buttons and the same states.
-
-## Black / blank screen handling
-
-Every voice-call turn attaches a screenshot of the current screen. Before it
-is injected into the model, the screenshot is checked: a frame that is
-essentially solid black (the screen was off or blank — common during
-wake-word use) is **not sent**; instead the turn carries a short note
-"(The screen was blank or off — no screenshot was sent.)" so the agent does
-not reason over a meaningless black frame. Dark apps with visible content
-have enough bright pixels/variance to still be sent.
-
-## Battery and reliability
-
-OEM battery managers may kill the always-on listener. The Assistive Ball
-settings page offers a one-tap link to Android's battery-optimization
-exemption request when the wake word is on.
-
-### What the listener does to stay cheap
-
-Measured on a physical device, one 80 ms frame through the full chain costs
-~4.4 ms, of which the embedding backbone is ~85% and the mel front-end ~8%.
-Five things follow from that (issue #37):
-
-- **The embedding stage is gated on energy.** `WakeWordGate` tracks the room's
- noise floor from the frame RMS and lets the expensive stages run only when
- something rises above it, with a ~3 s hangover so a pause mid-sentence does
- not re-arm the pipeline. In a quiet room the listener is doing a mel run and
- an RMS, nothing more.
-- **Gating cannot cost a detection.** The mel front-end keeps running while the
- gate is shut, so the embeddings that were skipped are rebuilt from the mel
- rows that produced them. The classifier sees exactly the window it would have
- seen ungated — asserted, not assumed, by `OnnxWakeWordPipelineGateTest`.
-- **The ONNX sessions are single-threaded and do not spin** between runs. ORT's
- defaults size a thread pool per session to the core count and busy-wait,
- which suits a busy server and not a 12.5 Hz duty cycle.
-- **The sessions stay loaded across pauses.** The listener is paused on every
- call transition and every TTS utterance; reloading ~2.6 MB of models each
- time the app spoke a sentence was pure waste. `pause()` keeps the models and
- still releases the microphone in full — see §10.3 of the privacy doc.
-- **The microphone is read in 320 ms batches** into a ~1.3 s buffer, waking the
- CPU 3.1×/s instead of 12.5×/s, at the cost of up to 320 ms of extra trigger
- latency.
-
-Two things are deliberately still open: the idle-hour `batterystats` figure
-that would quantify all of the above, and `SoundTrigger`/DSP hotword offload,
-which is the only way for the application processor to sleep at all while
-listening.
-
-`WakeWordPipelineBenchmarkTest` regenerates the per-stage numbers on a
-connected device; see its KDoc for the command.
-
-## Play Store disclosure
-
-The wake-word listener keeps the microphone open while the Assistive Ball is
-on, which is material for Play Store policy. The current implementation:
-
-- Adds `REQUEST_IGNORE_BATTERY_OPTIMIZATIONS` to the manifest and offers a
- one-tap exemption link in settings — required to receive the Play
- "background audio" carve-out for always-listening apps.
-- Documents wake-word data flow in `docs/privacy-data-retention.md`
- (Section 10): audio frames stay on-device; only the post-trigger command
- uses the configured STT provider.
-
-Before publishing, declare the wake-word mic use on the Play Console and
-ensure the in-app legal copy is up to date (bump `LEGAL_VERSION` in
-`SettingsRepository` whenever the legal docs change so existing users
-re-accept).
-
-## Custom training
-
-The bundled classifier was trained on two pronunciation variants
-(`hey gotcha`, `hey gah chuh`). To retrain for a different phrase or
-accent, follow the [official openWakeWord training
-Colab](https://colab.research.google.com/drive/1q1oe2zOyZp7UsB3jJiQ1IFn8z5YfjwEb),
-export `model.onnx`, replace `app/src/main/assets/openwakeword/hey_gotcha.onnx`,
-and update `WakeWordDetector.CLASSIFIER_MODEL` if the filename changes.
-
-See [`docs/MODEL_CARD.md`](MODEL_CARD.md) for the threshold recommendations and
-[`docs/wake-word-handoff.md`](wake-word-handoff.md) for the implementation
-checkpoint and ongoing work.