Compare commits

...
Author SHA1 Message Date
HomerandClaude Fable 5.2 2375affca8 1.0.0-beta.12: contract and tokens pinned from LLeMbas v2.0.0-beta.15
CI / check (push) Canceled after 0s
Release / release (push) Canceled after 0s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 09:54:24 +00:00
HomerandClaude Fable 5.2 df20788d7f A dictation that fails says so, in the instance's own words
CI / check (push) Canceled after 0s
The composer's dictation kept a refused or unreachable transcription to
itself: the field stayed as it was. It is now said as any failure is.

And /v1 refuses in OpenAI's shape (error.message), which the client did
not read: a refusal about speech was "The server answered 502." in the
chat, in Read aloud and in the assistant. Both shapes are read now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 09:16:55 +00:00
HomerandClaude Fable 5.2 8e84f0d53d Dictation and Read aloud say which chat they are for
CI / check (push) Canceled after 0s
The instance may give a connection speech models of its own, used for the
chats whose model is on it. A transcription and a speech request now carry
chat_id for a chat that exists, else chat_model with the model a new chat
(or the assistant's next one) starts on; another app's dictation names
neither and stays on the default. A server before this reads only the
fields it knows.

When the answer says the default answered for the chat's own
(X-Lembas-Fallback), the chat screen says so once per kind, with the
server's sentence. The assistant's sheet does not: it may be over the lock.
No request was added on a locked path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 09:04:31 +00:00
27 changed files with 412 additions and 44 deletions

No files matched your search

+24
View File
@@ -5,6 +5,30 @@ is in alpha and releases come off `main`.
## [Unreleased]
## [1.0.0-beta.12] — 2026-11-18
For what is new here the instance must be newer than LLeMbas 2.0.0-beta.14; an older one ignores
what the app adds and answers as before.
### Added
- **Dictation and Read aloud follow the chat's model.** An instance may now give a connection
speech models of its own, used for the chats whose model is on that connection. The app says
which chat a recording or a reading is for: the chat it is in, or -- before the chat exists --
the model chosen for it (in the assistant, the assistant's model). Dictation into another app
belongs to no chat and stays on the instance's default. When the chat's own speech model did
not answer and the default did, the chat says so once, quietly, naming what answered; the
assistant's sheet does not say it, because it may be open over the lock screen. Nothing new
is sent while the phone is locked.
### Fixed
- **A dictation that fails says so.** When the instance refused a recording or could not be
reached, the chat's field simply stayed as it was. Now the chat says why.
- **A refusal about speech is said in the instance's own words.** A dictation or a reading the
instance refused showed "The server answered 502." in the chat and in the assistant; the
instance's sentence is shown instead.
## [1.0.0-beta.11] — 2026-11-18
Needs LLeMbas 2.0.0-beta.14 for what is new here; with an older instance the app works as before.
+1 -1
View File
@@ -31,7 +31,7 @@ android {
// The one source of the version. versionCode is derived from it, so the two cannot
// drift, and a beta sorts below its release: 1.0.0-beta.1 -> 1000001,
// 1.0.0-beta.2 -> 1000002, 1.0.0 -> 1000099, 1.2.3 -> 1020399.
versionName = "1.0.0-beta.11"
versionName = "1.0.0-beta.12"
versionCode = versionName!!.split("-beta.").let { parts ->
val (a, b, c) = parts[0].split(".").map { it.toInt() }
val pre = if (parts.size == 2) parts[1].toInt() else 99
@@ -9,7 +9,6 @@ import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.put
import kotlinx.serialization.serializer
import okhttp3.Call
@@ -108,12 +107,19 @@ private fun agentsJson(agents: AgentsSetting) = buildJsonObject {
internal fun detail(response: Response): String {
val text = runCatching { response.body?.string().orEmpty() }.getOrDefault("")
val said = runCatching {
LembasJson.parseToJsonElement(text).let { it as JsonObject }["detail"]?.jsonPrimitive?.content
}.getOrNull()
return said ?: "The server answered ${response.code}."
return refusal(text) ?: "The server answered ${response.code}."
}
/**
* The server's own sentence in a refusal's body: `detail` on `/api/v2`, and OpenAI's shape
* (`error.message`) on `/v1`, where speech lives. Null when the body says neither.
*/
internal fun refusal(body: String): String? = runCatching {
val said = LembasJson.parseToJsonElement(body) as JsonObject
fun words(of: Any?): String? = (of as? JsonPrimitive)?.takeUnless { it is JsonNull }?.content?.ifBlank { null }
words(said["detail"]) ?: words((said["error"] as? JsonObject)?.get("message"))
}.getOrNull()
/**
* Everything the app asks one instance, with its token. Every call is the server's
* `/api/v2` (or `/v1` for speech), and every refusal comes back as an [ApiException]
@@ -619,22 +625,28 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
suspend fun forgetPush() = empty(authed("$v2/push").delete().build())
// --- Voice (/v1, the `models` scope) -----------------------------------------------------
suspend fun transcribe(wav: ByteArray, language: String? = null): String {
/**
* Write a recording down. [media] says which chat it is for, so that the chat's model's
* connection may serve it with its own speech model (server 2.0.0-beta.15); a server before
* that reads only the fields it knows and answers from its one endpoint.
*/
suspend fun transcribe(wav: ByteArray, language: String? = null, media: MediaFor = MediaFor.DEFAULT): Heard = withContext(Dispatchers.IO) {
val body = MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file", "speech.wav", wav.toRequestBody("audio/wav".toMediaType()))
.apply { language?.let { addFormDataPart("language", it) } }
.apply { transcriptionFields(language, media).forEach { (name, value) -> addFormDataPart(name, value) } }
.build()
return call(authed("$base/v1/audio/transcriptions").post(body).build(), Transcript.serializer()).text
http.newCall(authed("$base/v1/audio/transcriptions").post(body).build()).await().use {
if (!it.isSuccessful) throw ApiException(it.code, detail(it))
Heard(LembasJson.decodeFromString(Transcript.serializer(), it.body!!.string()).text, fallbackSource(it))
}
}
suspend fun speech(text: String): ByteArray = withContext(Dispatchers.IO) {
val body = buildJsonObject {
put("input", text.take(20_000))
put("response_format", "mp3")
}
http.newCall(authed("$base/v1/audio/speech").post(body.toString().toRequestBody(JSON)).build()).await().use {
/** [text] as speech, for the chat [media] names (see [transcribe]). */
suspend fun speech(text: String, media: MediaFor = MediaFor.DEFAULT): Spoken = withContext(Dispatchers.IO) {
http.newCall(authed("$base/v1/audio/speech").post(speechBody(text, media).toString().toRequestBody(JSON)).build()).await().use {
if (!it.isSuccessful) throw ApiException(it.code, detail(it))
it.body!!.bytes()
Spoken(it.body!!.bytes(), fallbackSource(it))
}
}
@@ -655,6 +667,33 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
/** 1 MB, the server's own limit on a shown file, with room for a little more. */
const val SHOWN_MAX_BYTES = 1_100_000L
/** The transcription's form fields beside the file: the language, and which chat. */
fun transcriptionFields(language: String?, media: MediaFor): List<Pair<String, String>> = buildList {
language?.let { add("language" to it) }
media.chatId?.let { add("chat_id" to it) }
media.chatModel?.let { add("chat_model" to it) }
}
/** The body of a speech request: the words, the format, and which chat. */
fun speechBody(text: String, media: MediaFor): JsonObject = buildJsonObject {
put("input", text.take(20_000))
put("response_format", "mp3")
media.chatId?.let { put("chat_id", it) }
media.chatModel?.let { put("chat_model", it) }
}
/**
* The source that answered in place of the chat's own (`X-Lembas-Fallback`), by its name
* (`X-Lembas-Source`, percent-encoded: a header is Latin-1); null when the one expected
* answered, and from a server that says neither.
*/
fun fallbackSource(fallback: String?, source: String?): String? {
if (fallback.isNullOrBlank() || fallback == "0" || source.isNullOrBlank()) return null
return runCatching { java.net.URLDecoder.decode(source.replace("+", "%2B"), "UTF-8") }.getOrDefault(source).ifBlank { null }
}
private fun fallbackSource(response: Response): String? = fallbackSource(response.header("X-Lembas-Fallback"), response.header("X-Lembas-Source"))
fun emptyBody(): RequestBody = ByteArray(0).toRequestBody(null)
/** A model's picture is small; anything larger is not one. */
@@ -730,6 +730,31 @@ data class PushKey(val key: String = "", val registered: Boolean = false)
@Serializable
data class Transcript(val text: String = "")
/**
* Which chat a recording or a reading is for: the chat's own id, or -- for a chat that does not
* exist yet -- the model it will be on. The instance serves it from that model's connection
* where the connection has speech models of its own; with neither ([DEFAULT]) from its default.
* Never both: a chat that exists says its model itself.
*/
data class MediaFor(val chatId: String? = null, val chatModel: String? = null) {
companion object {
/** No chat: another app's dictation. */
val DEFAULT = MediaFor()
fun of(chatId: String?, model: String?): MediaFor = when {
!chatId.isNullOrBlank() -> MediaFor(chatId = chatId)
!model.isNullOrBlank() -> MediaFor(chatModel = model)
else -> DEFAULT
}
}
}
/** A recording written down; [fallback] names the source that answered when the chat's own did not. */
data class Heard(val text: String, val fallback: String? = null)
/** Words as sound (mp3); [fallback] as [Heard]'s. */
class Spoken(val audio: ByteArray, val fallback: String? = null)
// --- The stream's frames -----------------------------------------------------------------
@Serializable
data class Tail(val thinking: String = "", val text: String = "", val label: String = "")
@@ -16,6 +16,7 @@ import eu.llembas.android.api.ApiException
import eu.llembas.android.api.Card
import eu.llembas.android.api.CardAnswer
import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.MediaFor
import eu.llembas.android.api.ModelInfo
import eu.llembas.android.api.Step
import eu.llembas.android.api.StreamClient
@@ -335,7 +336,7 @@ class AssistController(
scope.launch {
try {
_state.update { it.copy(busy = true, error = null) }
val text = context.lembas.instances.client()?.transcribe(wav).orEmpty()
val text = context.lembas.instances.client()?.transcribe(wav, media = mediaFor())?.text.orEmpty()
_state.update { it.copy(busy = false) }
if (text.isNotBlank()) ask(text, spoken = true)
} catch (e: CancellationException) {
@@ -454,7 +455,7 @@ class AssistController(
val seconds = recorder.seconds
if (seconds - sent < 0.5f || seconds > 60f || ear?.heardSomething != true || locked()) continue
sent = seconds
val words = runCatching { api.transcribe(recorder.snapshot()) }.getOrNull()
val words = runCatching { api.transcribe(recorder.snapshot(), media = mediaFor()).text }.getOrNull()
if (!words.isNullOrBlank() && _state.value.listening) _state.update { it.copy(heard = words) }
}
}
@@ -549,7 +550,7 @@ class AssistController(
}
try {
_state.update { it.copy(busy = true) }
val text = context.lembas.instances.client()?.transcribe(wav).orEmpty()
val text = context.lembas.instances.client()?.transcribe(wav, media = mediaFor())?.text.orEmpty()
_state.update { it.copy(busy = false, heard = "") }
if (text.isNotBlank()) askOrStop(text) else endConversation()
} catch (e: Exception) {
@@ -779,13 +780,19 @@ class AssistController(
/** Stop the voice -- and, in a conversation, the listening that would follow it. */
override fun stopReading() = speaker.stop()
/**
* Which chat the sheet's speech is for: the chat it is in, else the model its next chat
* starts on. That a fallback answered is not said here: the sheet may be over the lock.
*/
private fun mediaFor(): MediaFor = _state.value.let { MediaFor.of(it.chatId, it.modelId ?: newChatModel) }
/** Read [words] aloud; true when they were heard to the end. */
private suspend fun speak(words: String): Boolean {
// Never aloud over the lock screen: an answer is the account's.
if (words.isBlank() || locked()) return false
return try {
val api = context.lembas.instances.client() ?: return false
speaker.playToEnd(api.speech(words))
speaker.playToEnd(api.speech(words, mediaFor()).audio)
} catch (e: Exception) {
_state.update { it.copy(error = context.explain(e)) }
false
@@ -11,6 +11,7 @@ import android.speech.RecognitionService
import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import androidx.annotation.RequiresApi
import eu.llembas.android.api.MediaFor
import eu.llembas.android.lembas
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -200,7 +201,8 @@ class LembasRecognitionService : RecognitionService() {
return@launch
}
try {
val text = lembas.instances.client()?.transcribe(wav).orEmpty()
// Another app's dictation belongs to no chat: the instance's default writes it down.
val text = lembas.instances.client()?.transcribe(wav, media = MediaFor.DEFAULT)?.text.orEmpty()
if (text.isBlank()) {
listener.error(SpeechRecognizer.ERROR_NO_MATCH)
} else {
@@ -148,7 +148,15 @@ fun ChatScreen(
// Read aloud on a reply, when the instance has a voice; it stops when the chat is left.
val context = LocalContext.current
val scope = rememberCoroutineScope()
val readAloud = remember { ReadAloud(context, scope) { said -> scope.launch { snackbar.showSnackbar(said) } } }
val readAloud = remember {
ReadAloud(
context,
scope,
media = { model.state.value.mediaFor },
onFallback = { source -> model.mediaFellBack(MEDIA_SPEECH, context.getString(R.string.read_by_fallback, source)) },
onError = { said -> scope.launch { snackbar.showSnackbar(said) } },
)
}
LaunchedEffect(Unit) { readAloud.load() }
DisposableEffect(Unit) { onDispose { readAloud.stop() } }
@@ -25,6 +25,7 @@ import eu.llembas.android.api.DeviceDirectory
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LinkedDevice
import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.MediaFor
import eu.llembas.android.api.Mention
import eu.llembas.android.api.Message
import eu.llembas.android.api.MessagePage
@@ -146,6 +147,23 @@ val ChatState.folderModel: String?
val ChatState.modelInfo: ModelInfo? get() = models.named(modelId)
/**
* Which chat a dictation or a reply read aloud is for: this chat once it exists, else the model
* a new one would be on -- so the instance can serve it from that model's connection.
*/
val ChatState.mediaFor: MediaFor get() = MediaFor.of(chat?.id, modelId)
/** The two things a chat asks the instance's speech for, each with its own one note of a fallback. */
const val MEDIA_DICTATION = "dictation"
const val MEDIA_SPEECH = "speech"
/**
* Whether a fallback of [kind] is still to be said, given what was [told]: once per kind for as
* long as the chat is open. A connection's speech model that is down stays down for a while,
* and the same sentence after every dictation is noise.
*/
fun fallbackToSay(told: Set<String>, kind: String): Boolean = kind !in told
/** The thinking level in force, by the model's levels; null for a model with no choice. */
val ChatState.level: String?
get() = modelInfo?.takeIf { it.levelControl != "none" }?.level(if (chat == null) draft.effort else chat.effort?.ifBlank { null })
@@ -227,6 +245,12 @@ interface ChatActions {
fun answer(card: Card, answer: CardAnswer) {}
fun change(key: String, value: String?) {}
/** The instance's default answered a dictation or a reading ([kind]) for the chat's own: [sentence] says so, once. */
fun mediaFellBack(kind: String, sentence: String) {}
/** Something the screen asked the instance itself (a dictation) failed: said as any failure is. */
fun failed(e: Throwable) {}
/** A new agent chat with no computer linked: read the linked devices again. */
fun recheckDevices() {}
@@ -545,6 +569,16 @@ class ChatViewModel(app: Application) :
refresh()
}
override fun failed(e: Throwable) = _state.update { it.copy(error = getApplication<Application>().explain(e)) }
private val toldFallback = mutableSetOf<String>()
override fun mediaFellBack(kind: String, sentence: String) {
if (!fallbackToSay(toldFallback, kind)) return
toldFallback += kind
_state.update { it.copy(notice = sentence) }
}
override fun answer(card: Card, answer: CardAnswer) = control { api, chat ->
try {
api.answer(chat.id, card.id, answer)
@@ -94,6 +94,7 @@ import eu.llembas.android.auth.Prefs
import eu.llembas.android.lembas
import eu.llembas.android.ui.DirectoryPicker
import eu.llembas.android.ui.theme.LocalPalette
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
@@ -395,8 +396,18 @@ fun Composer(state: ChatState, actions: ChatActions, agent: Boolean, onTune: ()
scope.launch {
val wav = recorder.stop()
if (wav.isNotEmpty()) {
runCatching { context.lembas.instances.client()?.transcribe(wav) }
.onSuccess { heard -> if (!heard.isNullOrBlank()) text = (text + " " + heard).trim() }
// A transcription that was refused or never arrived is said: a field
// that stays as it was, without a word, reads as "nothing was heard".
try {
val heard = context.lembas.instances.client()?.transcribe(wav, media = state.mediaFor)
val said = heard?.text
if (!said.isNullOrBlank()) text = (text + " " + said).trim()
heard?.fallback?.let { actions.mediaFellBack(MEDIA_DICTATION, context.getString(R.string.transcribed_by_fallback, it)) }
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
actions.failed(e)
}
}
}
} else if (ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
@@ -6,6 +6,7 @@ import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import eu.llembas.android.api.MediaFor
import eu.llembas.android.assist.AssistController
import eu.llembas.android.assist.Speaker
import eu.llembas.android.lembas
@@ -23,7 +24,15 @@ import kotlinx.coroutines.launch
* shows a button that can only fail.
*/
@Stable
class ReadAloud(private val context: Context, private val scope: CoroutineScope, private val onError: (String) -> Unit) {
class ReadAloud(
private val context: Context,
private val scope: CoroutineScope,
/** Which chat is read from, asked at each reading: its connection may have a voice of its own. */
private val media: () -> MediaFor = { MediaFor.DEFAULT },
/** Another source read it than the chat's own: its name. */
private val onFallback: (String) -> Unit = {},
private val onError: (String) -> Unit,
) {
private val speaker = Speaker(context)
private var job: Job? = null
@@ -45,7 +54,9 @@ class ReadAloud(private val context: Context, private val scope: CoroutineScope,
job = scope.launch {
try {
val api = context.lembas.instances.client() ?: return@launch
speaker.play(api.speech(AssistController.plain(markdown)))
val spoken = api.speech(AssistController.plain(markdown), media())
spoken.fallback?.let(onFallback)
speaker.play(spoken.audio)
speaker.playing.first { !it }
} catch (e: CancellationException) {
throw e
@@ -1,4 +1,4 @@
// Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.14. Do not edit.
// Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.15. Do not edit.
package eu.llembas.android.ui.theme
import androidx.compose.ui.graphics.Color
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Zkusit znovu</string>
<string name="offline">Instance není dostupná. Zkontrolujte připojení telefonu a to, zda se dostane na adresu instance.</string>
<string name="dictate">Diktovat</string>
<string name="transcribed_by_fallback">Přepsal %1$s: vlastní model řeči tohoto chatu neodpověděl.</string>
<string name="read_by_fallback">Přečetl %1$s: vlastní model řeči tohoto chatu neodpověděl.</string>
<string name="remove">Odebrat</string>
<string name="more">Více</string>
<string name="back">Zpět</string>
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Erneut versuchen</string>
<string name="offline">Die Instanz ist nicht erreichbar. Prüfen Sie die Verbindung des Telefons und ob es die Adresse der Instanz erreicht.</string>
<string name="dictate">Diktieren</string>
<string name="transcribed_by_fallback">Transkribiert von %1$s: Das eigene Sprachmodell dieses Chats hat nicht geantwortet.</string>
<string name="read_by_fallback">Vorgelesen von %1$s: Das eigene Sprachmodell dieses Chats hat nicht geantwortet.</string>
<string name="remove">Entfernen</string>
<string name="more">Mehr</string>
<string name="back">Zurück</string>
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Reintentar</string>
<string name="offline">No se puede acceder a la instancia. Compruebe la conexión del teléfono y que llegue a la dirección de la instancia.</string>
<string name="dictate">Dictar</string>
<string name="transcribed_by_fallback">Transcrito por %1$s: el modelo de voz propio de este chat no respondió.</string>
<string name="read_by_fallback">Leído por %1$s: el modelo de voz propio de este chat no respondió.</string>
<string name="remove">Quitar</string>
<string name="more">Más</string>
<string name="back">Volver</string>
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Réessayer</string>
<string name="offline">L\'instance est injoignable. Vérifiez la connexion du téléphone et qu\'il atteint bien l\'adresse de l\'instance.</string>
<string name="dictate">Dicter</string>
<string name="transcribed_by_fallback">Transcrit par %1$s : le modèle vocal propre à cette discussion n\'a pas répondu.</string>
<string name="read_by_fallback">Lu par %1$s : le modèle vocal propre à cette discussion n\'a pas répondu.</string>
<string name="remove">Retirer</string>
<string name="more">Plus</string>
<string name="back">Retour</string>
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Újrapróbálás</string>
<string name="offline">A példány nem érhető el. Ellenőrizze a telefon kapcsolatát, és hogy eléri-e a példány címét.</string>
<string name="dictate">Diktálás</string>
<string name="transcribed_by_fallback">Átírta: %1$s — a csevegés saját beszédmodellje nem válaszolt.</string>
<string name="read_by_fallback">Felolvasta: %1$s — a csevegés saját beszédmodellje nem válaszolt.</string>
<string name="remove">Eltávolítás</string>
<string name="more">Továbbiak</string>
<string name="back">Vissza</string>
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Riprova</string>
<string name="offline">L\'istanza non è raggiungibile. Controlla la connessione del telefono e che raggiunga l\'indirizzo dell\'istanza.</string>
<string name="dictate">Detta</string>
<string name="transcribed_by_fallback">Trascritto da %1$s: il modello vocale proprio di questa chat non ha risposto.</string>
<string name="read_by_fallback">Letto da %1$s: il modello vocale proprio di questa chat non ha risposto.</string>
<string name="remove">Rimuovi</string>
<string name="more">Altro</string>
<string name="back">Indietro</string>
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.14 (moria). Do not edit. -->
<!-- Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.15 (moria). Do not edit. -->
<resources>
<color name="token_bg">#FF0B0D10</color>
<color name="token_surface">#FF11151A</color>
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Spróbuj ponownie</string>
<string name="offline">Instancja jest nieosiągalna. Sprawdź połączenie telefonu i czy dociera on do adresu instancji.</string>
<string name="dictate">Dyktuj</string>
<string name="transcribed_by_fallback">Transkrybował %1$s: własny model mowy tego czatu nie odpowiedział.</string>
<string name="read_by_fallback">Przeczytał %1$s: własny model mowy tego czatu nie odpowiedział.</string>
<string name="remove">Usuń</string>
<string name="more">Więcej</string>
<string name="back">Wstecz</string>
+2
View File
@@ -71,6 +71,8 @@
<string name="retry">Skúsiť znova</string>
<string name="offline">Inštancia nie je dostupná. Skontrolujte pripojenie telefónu a či sa dostane na adresu inštancie.</string>
<string name="dictate">Diktovať</string>
<string name="transcribed_by_fallback">Prepísal %1$s: vlastný model reči tohto chatu neodpovedal.</string>
<string name="read_by_fallback">Prečítal %1$s: vlastný model reči tohto chatu neodpovedal.</string>
<string name="remove">Odstrániť</string>
<string name="more">Viac</string>
<string name="back">Späť</string>
+2
View File
@@ -72,6 +72,8 @@
<string name="retry">Try again</string>
<string name="offline">The instance cannot be reached. Check the phone\'s connection, and that it can reach the instance\'s address.</string>
<string name="dictate">Dictate</string>
<string name="transcribed_by_fallback">Transcribed by %1$s: this chat\'s own speech model did not answer.</string>
<string name="read_by_fallback">Read by %1$s: this chat\'s own speech model did not answer.</string>
<string name="remove">Remove</string>
<string name="more">More</string>
<string name="back">Back</string>
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.14 (shire). Do not edit. -->
<!-- Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.15 (shire). Do not edit. -->
<resources>
<color name="token_bg">#FFF1EAD6</color>
<color name="token_surface">#FFF8F3E5</color>
@@ -0,0 +1,167 @@
package eu.llembas.android
import eu.llembas.android.api.ApiClient
import eu.llembas.android.api.ApiException
import eu.llembas.android.api.Chat
import eu.llembas.android.api.MediaFor
import eu.llembas.android.api.ModelInfo
import eu.llembas.android.api.refusal
import eu.llembas.android.ui.chat.ChatState
import eu.llembas.android.ui.chat.Draft
import eu.llembas.android.ui.chat.MEDIA_DICTATION
import eu.llembas.android.ui.chat.MEDIA_SPEECH
import eu.llembas.android.ui.chat.fallbackToSay
import eu.llembas.android.ui.chat.mediaFor
import kotlinx.coroutines.test.runTest
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
/**
* Speech follows the chat's model (server 2.0.0-beta.15): a transcription or a speech request
* says which chat it is for -- `chat_id`, or `chat_model` before the chat exists -- and never
* both; another app's dictation says neither.
*/
class MediaForTest {
private lateinit var server: MockWebServer
@Before
fun up() {
server = MockWebServer().apply { start() }
}
@After
fun down() = server.shutdown()
private fun client() = ApiClient(server.url("/").toString().trimEnd('/'), "lmb_test")
@Test
fun aChatThatExistsIsNamedByItsIdAlone() {
assertEquals(MediaFor(chatId = "c1"), MediaFor.of("c1", "shire/pippin"))
assertEquals(MediaFor(chatModel = "shire/pippin"), MediaFor.of(null, "shire/pippin"))
assertEquals(MediaFor(chatModel = "shire/pippin"), MediaFor.of(" ", "shire/pippin"))
assertEquals(MediaFor.DEFAULT, MediaFor.of(null, null))
assertEquals(MediaFor.DEFAULT, MediaFor.of("", " "))
}
@Test
fun theTranscriptionFieldsSayWhichChat() {
assertEquals(listOf("chat_id" to "c1"), ApiClient.transcriptionFields(null, MediaFor.of("c1", "shire/pippin")))
assertEquals(
listOf("language" to "sk", "chat_model" to "shire/pippin"),
ApiClient.transcriptionFields("sk", MediaFor.of(null, "shire/pippin")),
)
assertEquals(emptyList<Pair<String, String>>(), ApiClient.transcriptionFields(null, MediaFor.DEFAULT))
}
@Test
fun theSpeechBodySaysWhichChat() {
val inChat = ApiClient.speechBody("Hello", MediaFor.of("c1", "shire/pippin")).toString()
assertTrue(inChat, inChat.contains("\"chat_id\":\"c1\""))
assertFalse(inChat, inChat.contains("chat_model"))
assertTrue(inChat, inChat.contains("\"input\":\"Hello\""))
val before = ApiClient.speechBody("Hello", MediaFor.of(null, "shire/pippin")).toString()
assertTrue(before, before.contains("\"chat_model\":\"shire/pippin\""))
assertFalse(before, before.contains("chat_id"))
val none = ApiClient.speechBody("Hello", MediaFor.DEFAULT).toString()
assertFalse(none, none.contains("chat_"))
}
@Test
fun aTranscriptionCarriesTheChatAndReadsTheFallback() = runTest {
server.enqueue(
MockResponse().setBody("""{"text":"Second breakfast"}""")
.setHeader("X-Lembas-Source", "Bree%20%2B%20Inn").setHeader("X-Lembas-Fallback", "1"),
)
val heard = client().transcribe(ByteArray(64), media = MediaFor.of("c1", null))
assertEquals("Second breakfast", heard.text)
assertEquals("Bree + Inn", heard.fallback)
val request = server.takeRequest()
assertEquals("/v1/audio/transcriptions", request.path)
val body = request.body.readUtf8()
assertTrue(body, body.contains("name=\"chat_id\""))
assertFalse(body, body.contains("chat_model"))
}
@Test
fun anotherAppsDictationNamesNoChat() = runTest {
server.enqueue(MockResponse().setBody("""{"text":"Elevenses"}""").setHeader("X-Lembas-Source", "stt%2Fsmall"))
val heard = client().transcribe(ByteArray(64))
assertEquals("Elevenses", heard.text)
// The source is named, and it is the one expected: nothing to say.
assertNull(heard.fallback)
val body = server.takeRequest().body.readUtf8()
assertFalse(body, body.contains("chat_id"))
assertFalse(body, body.contains("chat_model"))
}
@Test
fun speechCarriesTheModelOfAChatNotMadeYet() = runTest {
server.enqueue(MockResponse().setBody("mp3"))
val spoken = client().speech("Hello", MediaFor.of(null, "shire/pippin"))
// An older server names no source at all.
assertNull(spoken.fallback)
assertEquals(3, spoken.audio.size)
val request = server.takeRequest()
assertEquals("/v1/audio/speech", request.path)
assertTrue(request.body.readUtf8().contains("\"chat_model\":\"shire/pippin\""))
}
@Test
fun aRefusedTranscriptionSaysTheServersSentence() = runTest {
// `/v1` refuses in OpenAI's shape, not `/api/v2`'s `detail`.
server.enqueue(
MockResponse().setResponseCode(502)
.setBody("""{"error":{"message":"The speech model did not answer.","type":"upstream_error","code":502}}"""),
)
try {
client().transcribe(ByteArray(64), media = MediaFor.of("c1", null))
fail("a 502 is a refusal")
} catch (e: ApiException) {
assertEquals(502, e.status)
assertEquals("The speech model did not answer.", e.message)
}
}
@Test
fun aRefusalIsReadInBothShapes() {
assertEquals("No.", refusal("""{"detail":"No."}"""))
assertEquals("Too long.", refusal("""{"error":{"message":"Too long.","code":413}}"""))
assertNull(refusal("""{"error":"plain"}"""))
assertNull(refusal("<html>Bad gateway</html>"))
assertNull(refusal(""))
}
@Test
fun aFallbackIsNamedOnlyWhenTheServerSaysBoth() {
assertEquals("Bree", ApiClient.fallbackSource("1", "Bree"))
assertNull(ApiClient.fallbackSource(null, "Bree"))
assertNull(ApiClient.fallbackSource("1", null))
assertNull(ApiClient.fallbackSource("0", "Bree"))
// A name that is not percent-encoding stays as it came.
assertEquals("100%", ApiClient.fallbackSource("1", "100%"))
}
@Test
fun theChatScreenNamesItsChatOrTheModelItWillBeOn() {
val models = listOf(ModelInfo(id = "pippin", ref = "shire/pippin", default = true), ModelInfo(id = "merry", ref = "buckland/merry"))
assertEquals(MediaFor(chatModel = "shire/pippin"), ChatState(models = models).mediaFor)
assertEquals(MediaFor(chatModel = "buckland/merry"), ChatState(models = models, draft = Draft(model = "buckland/merry")).mediaFor)
assertEquals(MediaFor(chatId = "c1"), ChatState(models = models, chat = Chat(id = "c1", model = "merry")).mediaFor)
assertEquals(MediaFor.DEFAULT, ChatState().mediaFor)
}
@Test
fun aFallbackIsSaidOncePerKind() {
assertTrue(fallbackToSay(emptySet(), MEDIA_DICTATION))
assertFalse(fallbackToSay(setOf(MEDIA_DICTATION), MEDIA_DICTATION))
assertTrue(fallbackToSay(setOf(MEDIA_DICTATION), MEDIA_SPEECH))
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
{
"ref": "v2.0.0-beta.14",
"commit": "ce6b992c7d125a3f9e127be5afdd06d24dbbaf9a",
"ref": "v2.0.0-beta.15",
"commit": "e38cec75b3685d09ba8ff28c859bd25e5b3a294c",
"sha256": "208111001ffd502f13d7f6fbc24a232e5ddc0d63c6789afe1636e34f1c737834"
}
+6
View File
@@ -84,6 +84,10 @@ STRINGS: dict[str, str] = {
"retry": "Try again",
"offline": "The instance cannot be reached. Check the phone's connection, and that it can reach the instance's address.",
"dictate": "Dictate",
# A connection's own speech model did not answer and the instance's default did (the
# server's sentences, `SERVER_ENGLISH`): a note in the chat, once.
"transcribed_by_fallback": "Transcribed by %1$s: this chat's own speech model did not answer.",
"read_by_fallback": "Read by %1$s: this chat's own speech model did not answer.",
"remove": "Remove",
"more": "More",
"back": "Back",
@@ -643,6 +647,8 @@ STRINGS: dict[str, str] = {
# taken from the server's catalogue and its named placeholders numbered in the order the
# English names them -- so "%(steps)s steps, %(tools)s tools" becomes `%1$s`, `%2$s`.
SERVER_ENGLISH: dict[str, str] = {
"transcribed_by_fallback": "Transcribed by %(source)s: this chat's own speech model did not answer.",
"read_by_fallback": "Read by %(source)s: this chat's own speech model did not answer.",
# The progress texts: the server's catalogues key them by the spec's English, {{fields}} and all.
"progress_queued_ahead": "Queued: {{ahead}} ahead",
"progress_waiting_for_model": "Waiting for {{model}}: {{reason}}",
+24 -8
View File
@@ -395,7 +395,9 @@
"wake_word_unavailable": "V tomto sestavení není. Sestavení pro F-Droid nemá modul pro budicí slovo, protože F-Droid sestavuje každou knihovnu ze zdrojů; sestavení z llembas.eu ho má.",
"widget_description": "Ptejte se hlasem nebo textem, nebo pokračujte v poslední konverzaci s asistentem. Neukazuje nic z vašeho účtu.",
"widget_hint": "Zeptejte se na cokoli",
"widget_speak": "Mluvit"
"widget_speak": "Mluvit",
"transcribed_by_fallback": "Přepsal %1$s: vlastní model řeči tohoto chatu neodpověděl.",
"read_by_fallback": "Přečetl %1$s: vlastní model řeči tohoto chatu neodpověděl."
},
"de": {
"about_version": "LLeMbas für Android %1$s",
@@ -794,7 +796,9 @@
"wake_word_unavailable": "Nicht in diesem Build. Der F-Droid-Build hat keine Aktivierungswort-Engine, weil F-Droid jede Bibliothek aus dem Quellcode baut; der Build von llembas.eu hat eine.",
"widget_description": "Per Sprache oder Text fragen oder den letzten Assistenten-Chat fortsetzen. Zeigt nichts aus Ihrem Konto.",
"widget_hint": "Frag mich alles",
"widget_speak": "Sprechen"
"widget_speak": "Sprechen",
"transcribed_by_fallback": "Transkribiert von %1$s: Das eigene Sprachmodell dieses Chats hat nicht geantwortet.",
"read_by_fallback": "Vorgelesen von %1$s: Das eigene Sprachmodell dieses Chats hat nicht geantwortet."
},
"es": {
"about_version": "LLeMbas para Android %1$s",
@@ -1192,7 +1196,9 @@
"wake_word_unavailable": "No en esta versión. La versión de F-Droid no tiene motor de palabra de activación, porque F-Droid compila cada biblioteca desde el código fuente; la de llembas.eu sí lo tiene.",
"widget_description": "Pregunta por voz o por texto, o continúa el último chat del asistente. No muestra nada de tu cuenta.",
"widget_hint": "Pregunta lo que quieras",
"widget_speak": "Hablar"
"widget_speak": "Hablar",
"transcribed_by_fallback": "Transcrito por %1$s: el modelo de voz propio de este chat no respondió.",
"read_by_fallback": "Leído por %1$s: el modelo de voz propio de este chat no respondió."
},
"fr": {
"about_version": "LLeMbas pour Android %1$s",
@@ -1591,7 +1597,9 @@
"wake_word_unavailable": "Pas dans cette version. La version F-Droid n’a pas de moteur de mot d’activation, car F-Droid compile chaque bibliothèque depuis les sources ; celle de llembas.eu en a un.",
"widget_description": "Demandez à la voix ou par écrit, ou reprenez la dernière discussion de l’assistant. N’affiche rien de votre compte.",
"widget_hint": "Posez une question",
"widget_speak": "Parler"
"widget_speak": "Parler",
"transcribed_by_fallback": "Transcrit par %1$s : le modèle vocal propre à cette discussion n'a pas répondu.",
"read_by_fallback": "Lu par %1$s : le modèle vocal propre à cette discussion n'a pas répondu."
},
"hu": {
"about_version": "LLeMbas Androidra %1$s",
@@ -1990,7 +1998,9 @@
"wake_word_unavailable": "Ebben a változatban nincs. Az F-Droid-változatban nincs ébresztőszó-motor, mert az F-Droid minden könyvtárat forrásból fordít; a llembas.eu-s változatban van.",
"widget_description": "Kérdezz hanggal vagy szöveggel, vagy folytasd az asszisztens legutóbbi csevegését. A fiókodból semmit sem mutat.",
"widget_hint": "Kérdezz bármit",
"widget_speak": "Beszéd"
"widget_speak": "Beszéd",
"transcribed_by_fallback": "Átírta: %1$s — a csevegés saját beszédmodellje nem válaszolt.",
"read_by_fallback": "Felolvasta: %1$s — a csevegés saját beszédmodellje nem válaszolt."
},
"it": {
"about_version": "LLeMbas per Android %1$s",
@@ -2388,7 +2398,9 @@
"wake_word_unavailable": "Non in questa build. La build F-Droid non ha un motore per la parola di attivazione, perché F-Droid compila ogni libreria dal sorgente; la build di llembas.eu ce l’ha.",
"widget_description": "Chiedi a voce o per iscritto, o continua l’ultima chat dell’assistente. Non mostra nulla del tuo account.",
"widget_hint": "Chiedi qualsiasi cosa",
"widget_speak": "Parla"
"widget_speak": "Parla",
"transcribed_by_fallback": "Trascritto da %1$s: il modello vocale proprio di questa chat non ha risposto.",
"read_by_fallback": "Letto da %1$s: il modello vocale proprio di questa chat non ha risposto."
},
"pl": {
"about_version": "LLeMbas na Androida %1$s",
@@ -2786,7 +2798,9 @@
"wake_word_unavailable": "Nie w tej wersji. Wersja z F-Droid nie ma silnika słowa aktywującego, bo F-Droid buduje każdą bibliotekę ze źródeł; wersja z llembas.eu go ma.",
"widget_description": "Pytaj głosem lub tekstem albo kontynuuj ostatni czat asystenta. Nie pokazuje niczego z Twojego konta.",
"widget_hint": "Zapytaj o cokolwiek",
"widget_speak": "Mów"
"widget_speak": "Mów",
"transcribed_by_fallback": "Transkrybował %1$s: własny model mowy tego czatu nie odpowiedział.",
"read_by_fallback": "Przeczytał %1$s: własny model mowy tego czatu nie odpowiedział."
},
"sk": {
"about_version": "LLeMbas pre Android %1$s",
@@ -3184,6 +3198,8 @@
"wake_word_unavailable": "V tomto zostavení nie je. Zostavenie pre F-Droid nemá modul pre budiace slovo, pretože F-Droid zostavuje každú knižnicu zo zdrojov; zostavenie z llembas.eu ho má.",
"widget_description": "Pýtajte sa hlasom alebo textom, alebo pokračujte v poslednej konverzácii s asistentom. Neukazuje nič z vášho účtu.",
"widget_hint": "Opýtajte sa na čokoľvek",
"widget_speak": "Hovoriť"
"widget_speak": "Hovoriť",
"transcribed_by_fallback": "Prepísal %1$s: vlastný model reči tohto chatu neodpovedal.",
"read_by_fallback": "Prečítal %1$s: vlastný model reči tohto chatu neodpovedal."
}
}
+5 -5
View File
@@ -1,9 +1,9 @@
{
"tag": "v2.0.0-beta.14",
"commit": "ce6b992c7d125a3f9e127be5afdd06d24dbbaf9a",
"sha256": "b72677b02467fb3119abfe81201a8f2d8e37d0f17070a69ff8a2ed77b867aac3",
"tag": "v2.0.0-beta.15",
"commit": "e38cec75b3685d09ba8ff28c859bd25e5b3a294c",
"sha256": "7e9822ced4d8a0215546e3bf32c31785db0291086d69d48ea4ca273e17788013",
"res": {
"values": "88d9a5785eef61449fd1b74ce9ef6fe9b45b6bb80f94bc03d08566f9cedc7425",
"values-night": "5a06270bd24836937f44060231ee4b79bc90bb0c72b206272fbdfac9c592231d"
"values": "d2348851901de75dc303661982169b60683aa098e7d9855657453239bc51ae2a",
"values-night": "efadec8a16da9f8371c9411f91447323681e0261a7df12dd3b6557c2677bc186"
}
}