diff --git a/Assistant.md b/Assistant.md index c8212f0..505b322 100644 --- a/Assistant.md +++ b/Assistant.md @@ -29,12 +29,47 @@ and a recognition service -- Android rejects one without both. LLeMbas provides: | 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 | +| Lock screen | the sheet opens; sending asks to unlock first, and nothing from the account is shown before (below) | `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. +> **Experimental.** The wake word, and the hands-free parts of the voice assistant -- opening +> listening, finding the end of what you said, the spoken conversation, listening over the lock +> screen -- are new and have been tried on few phones. Settings marks them so. Typing a question +> and the microphone button are the parts to rely on. + +## Over the lock screen + +`AssistActivity` is `setShowWhenLocked`; what it does when the phone is locked is `lockedStart()` +(tested): + +| Opened | Locked behaviour | +|---|---| +| to listen -- the wake word, a headset's button -- with the microphone allowed | **Listen**: the sheet stays up and listens (`AssistController.listenOverLock`). What it hears is *held* (`AssistUiState.waiting`), shown as the person's own question with **Unlock to send**, and Android is asked to unlock at once (`requestDismissKeyguard`: a face or a fingerprint is enough). If nobody unlocks, the sheet stays as it is | +| with a question handed over by the session | **Hold**: the same, without listening | +| anything else (the plain sheet, the last chat, the microphone's permission prompt) | **Unlock**: Android is asked to unlock first, and the sheet goes if that is turned down | + +The question is asked when the phone is unlocked -- by the dismiss request, or by the person +(`ACTION_USER_PRESENT`). Nothing is asked, and no answer shown or spoken, before: a conversation +that was on the sheet when the phone locked is replaced by one fixed line. The screen is kept on +while it listens or works, and a sheet over the lock screen goes when the screen goes off. + +With the instance's speech-to-text, listening over the lock screen sends the recording to the +instance to be written down (the person's own words come back); with Voice input › Phone it +stays with the phone's recogniser. + +The wake word with the screen off used to show the sheet for a moment only: a locked phone took +the "ask to unlock first" path, and `onDismissCancelled` -- which is what Android answers when +nobody unlocks -- finished the activity. The assistant's own sheet (the session, screen on and +locked) listens over the lock screen too and hands what it heard to the activity (`EXTRA_SPOKEN`). + +**Not done: an answer over the lock screen.** A wake word from across the room gets its +question heard and then waits for the unlock. Answering aloud without unlocking would be a +setting of its own (off by default, voice only, nothing drawn), since it lets anyone near the +phone use the account. + ## The sheet The assistant is a sheet over the app it was opened from, never a page of its own: a @@ -48,29 +83,45 @@ nearest stop). Both ways in -- the session and `AssistActivity` -- draw the same | Part | What it does | |---|---| | The bar | The model and connection chip (picture, name, the instance, a dot: answering, not, or being asked; a tap picks another model, kept for next time), voice reply on or off, Open in app | +| The model | Settings › Assistant › **Assistant model** (`Prefs.assistantModel`): *Instance default* (the account's default, then the instance's) or one of the instance's models, for every new assistant chat -- the sheet, the wake word, Share. `AssistController.assistantModelFor` resolves it; the controller keeps it apart from the model of a continued chat, so New chat goes back to it | | Before a question | The last chat the assistant made, to continue; the quick actions when a screen was handed over (Summarise / Translate / Explain this -- each sends the screen); how to open it, and why there is no wake word | | The questions | Each question a bubble, each answer full width as it is written; follow-ups stay in the same chat until New chat; Read aloud under the last answer | | The foot | Use screen; the microphone (or Send once there are words) | -**Microphone first.** It opens listening (Settings › Assistant can turn that off), except over -the lock screen and before the microphone is allowed -- the session cannot show the permission -prompt, so it hands over to `AssistActivity` (`EXTRA_LISTEN`). +**Microphone first.** It opens listening (Settings › Assistant can turn that off), except +before the microphone is allowed -- the session cannot show the permission prompt, so it hands +over to `AssistActivity` (`EXTRA_LISTEN`) -- and over the lock screen, where only a way in that +means to speak listens (above). **Voice input** (Settings › Voice input): - **LLeMbas** -- the instance's speech-to-text (`/v1/audio/transcriptions`, through the server). That endpoint takes a whole recording, so the words shown while speaking are the recording so - far, written down again every 1.2 s (one request at a time, not past the first minute). A - pause after speech sends it: the microphone's level (RMS) below a threshold for 1.8 s, or the - same words for 4.5 s. If nothing was said in 8 s, nothing is sent -- a speech-to-text model - asked to write down silence tends to invent a sentence. The thresholds were set without a - phone in hand; the microphone button always sends at once. + far, written down again every 1.2 s (one request at a time, not past the first minute, and not + before the microphone heard anything above the room). When to stop is `EndOfSpeech` + (`assist/EndOfSpeech.kt`, tested with level sequences), fed the microphone's level (RMS) every + 100 ms. No level is absolute: the **noise floor** is the quietest level of the last two + seconds, taken at once when it falls and slowly when it rises. Speech begins when the level is + over about twice the floor in three of the last eight ticks; a pause is back within 1.6 times + of it. A pause of 1.5 s after speech sends it; nothing said gives up after 5 s and sends + nothing (a speech-to-text model asked to write down silence invents a sentence, so its words + count as speech only when the microphone heard something above the room); the same words for + 4.5 s end it; and never past 60 s. Known limits: sound that is not steady (music, a + television, other people) counts as speech, and a very loud room at the very start can be + taken for a voice once. Earlier it was two fixed levels (0.02 speaking, 0.01 quiet): a room + between them never counted as a pause and it listened to the two-minute limit. - **Phone** -- the phone's own recogniser through `SpeechRecognizer`, with partial results. While LLeMbas is the digital assistant the system's *default* recogniser is LLeMbas's own (`LembasRecognitionService`), so `PhoneRecognizer` never asks for the default: it takes the on-device recogniser (Android 12+), else another installed app's (found through `` for `android.speech.RecognitionService`). No Google library is linked; a phone with none - says so in Settings. If the instance has no speech-to-text, the phone's is used. + says so in Settings. If the instance has no speech-to-text, the phone's is used. It is asked + for the same 1.5 s pause (`EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS`, a hint not + every recogniser takes) and watched (`phoneWatch`): no words in 8 s gives up, the same words + for 4.5 s asks it to stop, and one that does not answer has its words taken as they are. + +`LembasRecognitionService` (what other apps get as the system's recogniser) ends by +`EndOfSpeech` too, within its 15 s limit. **Voice reply** is the instance's text-to-speech (`/v1/audio/speech`), for a spoken question when the switch at the top is on; Read aloud reads any answer. Shown only when the instance offers it @@ -112,7 +163,7 @@ 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. -## The wake word (opt-in) +## The wake word (opt-in, experimental) 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 diff --git a/Release-checklist.md b/Release-checklist.md index 3d0ba85..e79abe5 100644 --- a/Release-checklist.md +++ b/Release-checklist.md @@ -17,7 +17,10 @@ the tag. 7. **Assistant**: choose LLeMbas as the digital assistant; hold the power button over another app; ask by voice; the answer is read aloud; Include screen sends the screen's text. 8. **Lock screen**: open the assistant while locked -- nothing from the account shows; sending - asks to unlock. + asks to unlock. With the wake word listening with the screen off: lock the phone, say the + phrase -- the screen comes on, the sheet **stays** and listens; ask something: your question + is shown with *Unlock to send*, and it is sent (and answered) once you unlock; leave it, and + the sheet is gone when the screen goes off. 9. **The tile and the shortcut** open the sheet. 10. **Both themes**, and the narrowest phone at hand: nothing runs off the screen. 11. **Attach**: take a photo, choose photos, choose a file; each arrives on the web page with the @@ -28,12 +31,16 @@ the tag. 14. **Offline**: airplane mode in a chat -- send says the instance cannot be reached and the message stays in the composer; back online, the stream picks up by itself. -15. **The wake word** (standard build): turn it on; the notification says *Listening for* your +15. **Listening ends**: in a quiet room and in a noisy one (a fan, a radio), open the assistant + and say nothing: it stops after about five seconds. Ask a question: it is sent a second or + two after you stop. Settings › Assistant › **Assistant model**: choose a quick model, ask by + voice, and the chip on the sheet shows that model. +16. **The wake word** (standard build): turn it on; the notification says *Listening for* your phrase, not another; **Test the wake word** says *Heard it* when you say it; close the app and say it: the assistant opens. Change the phrase: the notification follows. Take the microphone permission away in the system's settings and open the app: it says so, and does not close. -16. **Installing**: the standard APK installs without Play Protect blocking it; the +17. **Installing**: the standard APK installs without Play Protect blocking it; the `-notifications` APK installs over it and Settings then offers notification summaries. The test builds from `dev` (CI's `llembas-android-debug-N` artifact) are the way to walk this