diff --git a/Assistant.md b/Assistant.md index 6bad136..0f8b2cd 100644 --- a/Assistant.md +++ b/Assistant.md @@ -23,10 +23,18 @@ and a recognition service -- Android rejects one without both. LLeMbas provides: | Hold the power button | Pixel and most phones on Android 12+, when LLeMbas is the assistant | | Samsung side key | Settings › Advanced features › Side button › Press and hold › **Digital assistant** (Bixby otherwise wins) | | The assist gesture | swipe up from a bottom corner, where the phone has it | -| Quick Settings tile | "Ask LLeMbas" -- add it from the tile editor | -| Launcher shortcut | long-press the icon › Ask | +| Quick Settings tile | "Ask LLeMbas" -- add it from the tile editor; always shown ready (`STATE_INACTIVE`), never as a switch | +| Launcher shortcuts | long-press the icon › Ask LLeMbas, Speak, Last chat -- published from code (`widget/AskWidget.kt` `Shortcuts`), because a static `shortcuts.xml` names the package and the test build's is `….debug` | +| Home-screen widget | `AskWidget` (RemoteViews, colours from `values*/tokens.xml`): *Ask anything*, the microphone (the sheet listening), the clock (the last assistant chat). Nothing from the account on it | +| Headset voice button | `ACTION_VOICE_COMMAND` (locked: `VOICE_SEARCH_HANDS_FREE`) opens `AssistActivity` listening, whatever Settings says about listening first | +| Share menu | "Ask LLeMbas": `ShareActivity`, the same sheet frame -- what came in, an optional request, **new chat** or **the last assistant chat**; files uploaded first; the chat opens in the app; a new chat made there becomes the assistant's last | +| Wake word | opt-in, below | | Lock screen | the sheet opens; sending asks to unlock first, and nothing from the account is shown before | +`AssistActivity` reads what a way in asked for with `Opening.of(intent)`: `ACTION_LISTEN` +(widget, Speak shortcut, headset), `ACTION_CONTINUE` (widget, Last chat shortcut), a question +handed over by the session, or just the sheet; `onNewIntent` takes a second press while it is up. + ## The sheet The assistant is a sheet over the app it was opened from, never a page of its own: a @@ -68,6 +76,21 @@ prompt, so it hands over to `AssistActivity` (`EXTRA_LISTEN`). the switch at the top is on; Read aloud reads any answer. Shown only when the instance offers it to the account (`/api/v2/me` `services.tts`). +**Spoken conversation** (Settings › Assistant › *Keep a spoken conversation going*, on; needs +voice replies). A spoken question answered aloud sets `conversation`; when `Speaker.playToEnd` +says the answer was heard to the end, the sheet listens again. It ends on a stop phrase +(`assist_stop_words`, `|`-separated per language, matched by `isStopPhrase`: the phrase alone or +with up to two words around it), **End** on the *In conversation* strip, typing, a stopped voice, +a card waiting, or nothing said (the usual silence rules). With a Bluetooth headset connected, +`HeadsetRoute` makes it the communication device (Android 12+) and the recorder prefers its +microphone; a wired headset's is the default anyway. + +**Notification summaries** (Settings › Assistant › *Notification summaries*, off; plus Android's +notification access, which only the person can give). `LembasNotificationListener` keeps +nothing; `NotificationReader.read` takes what is up when a question asks -- the *Summarise my +notifications* chip, or a question naming them (`assist_notifications_phrases`) -- and nothing +while the phone is locked. They go with that one question as "My notifications:" text. + **Open in app** continues the same chat in the app. A reply waiting on a card (an approval or a question) says to open it in the app: the sheet does not answer cards. @@ -81,26 +104,37 @@ as an attachment -- one question, then it is off again. The session makes a fres it hides, so the next invocation's screen, which may arrive before or after its `onShow`, lands in the controller that shows it. -## Why there is no wake word - -The sheet says so itself, under the quick actions, and Settings › Assistant repeats it. +## The wake word (opt-in) The platform's always-on hotword -- the low-power detector Gemini uses -- needs `CAPTURE_AUDIO_HOTWORD` and `MANAGE_HOTWORD_DETECTION`, both `signature|privileged`: only an -assistant built into the phone can hold them. No app installed from outside has a wake word that -way; ChatGPT, Claude and Perplexity have none either. +assistant built into the phone can hold them. What an app can do is listen for itself, and that is +what Settings › Assistant › *Wake word* turns on (off by default). -## The wake word, later and opt-in - -What is possible is the app listening for itself: a `microphone` foreground service running an -on-device keyword spotter. - -- **Engine: sherpa-onnx keyword spotting** -- Apache-2.0, runs on Android, any phrase without - training. openWakeWord's pre-trained models are non-commercial (CC BY-NC-SA), and Picovoice's - free tier ended in 2026; both are out. -- **Android's rules:** a microphone service cannot start from the background, except for the - app that is the voice-interaction service -- which LLeMbas is, when chosen. It cannot start at - boot, so after a restart the app posts "tap to resume listening". It shows a permanent - notification while it listens. -- **Cost:** a continuous microphone and CPU inference without the hotword chip. Measured on a real - phone before it ships, and off by default. +- **Engine: sherpa-onnx keyword spotting** (Apache-2.0, k2-fsa) with its English + `kws-zipformer-gigaspeech-3.3M` model (Apache-2.0, int8 encoder/decoder/joiner, ~5 MB). + openWakeWord's pre-trained models are non-commercial (CC BY-NC-SA) and Picovoice needs a + proprietary key; both are out. +- **Fetched, not committed**: `scripts/fetch-wakeword.py` downloads the project's prebuilt AAR + (2.0.1, onnxruntime inside, MIT) and the model archive from its GitHub releases, checks each + against a SHA-256, and puts them in `app/libs/` and `app/src/full/assets/wakeword/` (gitignored). + CI and the release workflow run it before Gradle. +- **`full` only.** The `fdroid` flavour has a stub (`src/fdroid/.../wake/Engine.kt`, + `AVAILABLE = false`) and Settings says why: F-Droid builds every library from source, and + sherpa-onnx is not built from source here yet. ABIs in `full`: arm64-v8a, armeabi-v7a, x86_64. +- **Phrases**: four English ones (`WakePhrases`), spelled in the model's BPE pieces with its + `bpe.model` (sentencepiece, offline) -- the phone has no tokenizer, and a free phrase was not + measured. Not tuned on a phone: the engine's default threshold (0.25) and score (1.5). +- **`WakeWordService`** (`foregroundServiceType="microphone"`, notification up the whole time, + with Stop): 16 kHz audio to the engine in memory, nothing kept or sent. Pauses while the sheet + is up (`AssistPresence`, counted by the session and the activity), in battery saver, and with + the screen off unless *Only while the screen is on* is off. On the word: the sheet opens + listening through `LembasAssistService.current.showSession` when LLeMbas is the assistant + (Android lets the bound voice-interaction service do that from the background), else as an + activity, else a "tap to ask" notification. +- **Android's rules**: a microphone service starts only from the app on screen and never at + boot -- `WakeBootReceiver` posts "tap to listen again", and the app restarts a service the + phone stopped whenever it opens. Settings links the battery-optimisation page and names + dontkillmyapp.com for phones that kill background services. +- **Cost**: a continuous microphone and CPU inference without the hotword chip. Not yet measured + on a phone. diff --git a/Working-notes.md b/Working-notes.md index d2353bb..b4cb5e2 100644 --- a/Working-notes.md +++ b/Working-notes.md @@ -21,7 +21,9 @@ Read this before changing anything. Each rule has its reason, because a rule wit it to the web UI's sealed frame. A picture the instance generated (`image_generate`'s `image {id, width, height}`) is drawn by `ui/chat/GeneratedPicture.kt` alone: fetched by attachment id from `/api/v2/attachments/{id}` with the token, never from a URL, size-capped - and downsampled. Markwon still loads no image. + and downsampled. Markwon still loads no image. Code is coloured by the app's own scanner + (`ui/Highlight.kt`: comments, strings, numbers, keywords, types, tags), which only reads the + text and falls back to plain -- no highlighting library, no WebView. 5. **Nothing from the account shows on the lock screen.** The assistant's sheet may open there; sending asks Android to unlock first (`AssistActivity`), and notifications are `VISIBILITY_PRIVATE`, with a public version that says only the app's name and a fixed @@ -116,3 +118,11 @@ design change, before a phone. - **`contract/harness_*.json` are the harness spec's conformance cases** from the server's copy of the spec (`src/lembas/harness_spec/conformance/`), pinned with the fixtures by `fetch-contract.py`; `ProgressTest` draws `harness_progress.json` with the English resources. +- **`--` inside an XML comment fails the resource compiler** (`aapt`: "The string "--" is not + permitted within comments"), so no `--` dash in a layout's or the manifest's comments. CI run 61. +- **The wake-word engine is not in the repository.** `scripts/fetch-wakeword.py` fetches it + (hash-pinned) before Gradle; a local `full` build without it fails on the missing AAR. +- **Phone actions drive OsmAnd through `osmand.api://` URIs only.** Its AIDL API's classes are + GPLv3 (the OsmAnd repository); copying them would change this app's licence. +- **A UI string that names another UI string's words** (`phone_actions_line` says "Do it") must + change with it, in every language.