diff --git a/Assistant.md b/Assistant.md index e093832..6bad136 100644 --- a/Assistant.md +++ b/Assistant.md @@ -11,7 +11,10 @@ and a recognition service -- Android rejects one without both. LLeMbas provides: | `LembasAssistService` | the service the system binds while LLeMbas is the assistant | | `LembasAssistSessionService` / `LembasAssistSession` | one invocation: a sheet over the current app | | `LembasRecognitionService` | speech-to-text through the instance (`/v1/audio/transcriptions`); any app using the system recognizer gets it while LLeMbas is the assistant | -| `AssistActivity` | the same sheet as an activity: `ACTION_ASSIST`, the tile, the "Ask" shortcut, and the lock-screen path | +| `AssistActivity` | the same sheet in a see-through activity: `ACTION_ASSIST`, the tile, the "Ask" shortcut, the lock-screen path and the microphone's permission prompt | +| `AssistController` | what the sheet does: listening, asking, the stream, voice out | +| `AssistSheet.kt` | the frame (dim, drag, stops) and the contents, drawn from state | +| `PhoneRecognizer` (`Voice.kt`) | the phone's own recogniser, for Voice input › Phone | ## How it is opened @@ -24,16 +27,64 @@ and a recognition service -- Android rejects one without both. LLeMbas provides: | Launcher shortcut | long-press the icon › Ask | | Lock screen | the sheet opens; sending asks to unlock first, and nothing from the account is shown before | +## The sheet + +The assistant is a sheet over the app it was opened from, never a page of its own: a +see-through window with its own dim (`AssistSheetFrame`), the sheet rising to about half the +height. Its handle (and the bar beside it) drags it to the full height, or down and away; Back +or a tap on the dim closes it too. With the keyboard up, the stops are measured above it. +`settle()` decides where a let-go drag ends (a fling by its direction, a slow release by the +nearest stop). Both ways in -- the session and `AssistActivity` -- draw the same +`AssistSheetContent`, from its state alone, which is what the screenshot tests render. + +| 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 | +| 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`). + +**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. +- **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. + +**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 +to the account (`/api/v2/me` `services.tts`). + +**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. + ## The screen `onHandleAssist` delivers the screen's text and `onHandleScreenshot` a picture -- only if the person allowed it (Settings › Default apps › Assist & voice input › Use text from screen / Use -screenshot), and never from an app that marks its window secure. The sheet offers **Include -screen**, off every time it opens; when on, the text goes with the question and the screenshot as -an attachment. +screenshot), and never from an app that marks its window secure. The sheet offers **Use +screen**, off every time it opens; on, the text goes with the next question and the screenshot +as an attachment -- one question, then it is off again. The session makes a fresh controller as +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 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 diff --git a/Design.md b/Design.md index c978e96..fc3b4c5 100644 --- a/Design.md +++ b/Design.md @@ -19,8 +19,10 @@ One module, Kotlin and Jetpack Compose, Material 3 coloured by the server's toke Shaped like the AI apps people already know, in LLeMbas's own theme: -- **The app opens on a new chat**: the model's picture and a greeting, four suggestions above - the message box. A chat (or a new chat) is a top-level page -- opening one replaces the last, +- **The app opens on a new chat**: Chat or Agent chat side by side (one line each, on a shared + track), the model's picture and a greeting, four suggestions above the message box. A new + agent chat with no computer linked shows the three steps to link one, each command with Copy, + and Check again. A chat (or a new chat) is a top-level page -- opening one replaces the last, and Back leaves the app; Files, Scheduled and Settings open over it and Back returns. - **The drawer** (menu button, or a swipe from the edge on a chat page) holds everything else: search over the titles, New chat, New agent chat, Files, Scheduled, then the chats in three @@ -43,7 +45,8 @@ Shaped like the AI apps people already know, in LLeMbas's own theme: offer), the microphone and Send, which becomes Stop. The Options button sits in the row's one part that gives, so the icons keep their places at any width and type size. - **Settings** are grouped lists: a header, one rounded surface of rows, each row an icon column - of fixed width, words that wrap, a control that keeps its size. + of fixed width, words that wrap, a control that keeps its size. Language opens a sheet: + the account's language (the default), the phone's, then each language named in itself. - Spacing is on an 8 dp grid, every touch target is at least 48 dp, and every page is edge-to-edge with the system bars' and keyboard's insets. @@ -125,11 +128,21 @@ Channels: Replies, Questions and approvals (high importance), Scheduled results, failures (high importance); every one private on the lock screen. An approval's notification carries Allow once and Deny; "always" and a corrected command need the card. -## Theme and strings +## Theme, strings and language `Tokens.kt` from `tokens.css` (Moria and Shire); the theme follows the system unless chosen. Strings: see Working notes. +The app's language is the **account's** by default (`/api/v2/me` `language`, read once per +instance in use and kept), so a phone in one language signed in to an account in another shows +the account's. Settings › Language chooses the phone's or any the app has (`AppLanguage`). +Android 13+: `LocaleManager.setApplicationLocales`, and `android:localeConfig` +(`res/xml/locales_config.xml`, written by `gen-strings.py` from its `LANGS`) so the system's own +per-app language lists the same set -- a language chosen there is adopted as the person's +choice. Older phones: the tag in a small synchronous preferences file, applied in every +activity's `attachBaseContext` and to the assistant's window. No AppCompat. `LanguageTest` +holds the offered list, the `values-*` folders and the locale config equal. + ## Distribution `full`: a signed APK on the GitHub and forge Releases, which updates itself from diff --git a/Working-notes.md b/Working-notes.md index 95b572a..69967a7 100644 --- a/Working-notes.md +++ b/Working-notes.md @@ -94,6 +94,12 @@ design change, before a phone. - **A model's picture is fetched only from the instance's own `/api/v2/models/images/`** (`ApiClient.modelImageUrl`), with the token, at most 2 MB, decoded small. Anything else in the list's `image` is ignored and the initial is drawn. +- **The system's default speech recogniser is LLeMbas's own** while LLeMbas is the digital + assistant. Voice input › Phone must therefore never call `createSpeechRecognizer(context)` + without a component: it would hand the audio straight back to the instance. + `PhoneRecognizer` takes the on-device one or another app's. +- **A language is added in `gen-strings.py`'s `LANGS` and in `AppLanguage.LANGUAGES`** (named + in itself); `LanguageTest` fails until both, the `values-*` folder and the locale config agree. - **A failure is shown through `ui/Errors.kt`'s `explain()`**: the server's sentence for a refusal, one "cannot be reached" sentence for a network that is not there. Never `e.message` straight to the screen.