Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

feat(android): while listening, the notification and the live screen say when the AI key, credit or model needs fixing, with a button that opens AI settings

wquguru93a563f2f453
diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/AiCheckViews.kt b/android/app/src/main/kotlin/com/wquguru/cicada/AiCheckViews.kt
index c6625d3..41a41b0 100644
--- a/android/app/src/main/kotlin/com/wquguru/cicada/AiCheckViews.kt
+++ b/android/app/src/main/kotlin/com/wquguru/cicada/AiCheckViews.kt
@@ -162,19 +162,9 @@ object AiCheckViews {
if (!ling.hasKey || !c.needsUser || c.running) return null
val name = ling.serviceName
val cfg = ling.config()
- val stops = L("修好之前听不了")
- val notesStop = L("字幕照常,纪要先停下")
val f = c.failure ?: return c.balanceLine(name)?.let { it to L("用完后就听不了了") }
- return when (f.reason) {
- Reason.Unreachable -> LF("连不上 %@", name) to stops
- Reason.InvalidKey, Reason.MgmtKey -> LF("%@ 的 key 用不了", name) to stops
- Reason.NoCredit -> LF("%@ 账户余额不足。", name) to stops
- Reason.NoModel -> LF("%@ 上找不到 %@ 这个模型。", name, AiServiceActivity.short(cfg.textModel)) to notesStop
- Reason.Deaf -> LF("%@ 听不了声音。", AiServiceActivity.short(cfg.hearModel)) to stops
- Reason.BadAddress -> L("AI 服务的设置要改一下") to stops
- Reason.NoJSON -> L("AI 服务的设置要改一下") to notesStop
- Reason.Busy, Reason.ServerError -> null
- }
+ if (f.reason == Reason.Unreachable) return LF("连不上 %@", name) to L("修好之前听不了")
+ return c.blocking(name, cfg.textModel, cfg.hearModel)
}
fun card(a: Activity, ui: Ui): View? {
diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/ListenService.kt b/android/app/src/main/kotlin/com/wquguru/cicada/ListenService.kt
index b0ca022..1a1c329 100644
--- a/android/app/src/main/kotlin/com/wquguru/cicada/ListenService.kt
+++ b/android/app/src/main/kotlin/com/wquguru/cicada/ListenService.kt
@@ -98,6 +98,9 @@ class ListenService : Service() {
val stop = PendingIntent.getService(context, 1, Intent(context, ListenService::class.java).setAction(ACTION_STOP), PendingIntent.FLAG_IMMUTABLE)
val ending = app.ending
val file = app.importing
+ // Something only the user can fix (a key, the credit, a model): said here, where it is
+ // seen with Cicada in the background, with the way to fix it. No second notification.
+ val blocking = if (file == null) app.ling.blocking else null
val title = when {
file != null -> L("知了 · 正在转写") + " " + (session?.sourceFile ?: "")
ending != null -> app.endingTitle(ending)
@@ -105,7 +108,7 @@ class ListenService : Service() {
else -> L("知了 · 正在听手机里的声音")
}
val text = if (file != null) "${cicada.Languages.clock(file.done)} / ${cicada.Languages.clock(file.total)}"
- else if (ending != null) app.endingDetail(ending) else listen.problem ?: line?.let { it.dst ?: it.src } ?: L("等有人说话…")
+ else if (ending != null) app.endingDetail(ending) else blocking ?: listen.problem ?: line?.let { it.dst ?: it.src } ?: L("等有人说话…")
val b = Notification.Builder(context, CHANNEL)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
@@ -120,7 +123,17 @@ class ListenService : Service() {
val keep = PendingIntent.getService(context, 2, Intent(context, ListenService::class.java).setAction(ACTION_KEEP), PendingIntent.FLAG_IMMUTABLE)
b.addAction(Notification.Action.Builder(null, L("继续记录"), keep).build())
b.addAction(Notification.Action.Builder(null, L("现在结束"), stop).build())
- } else b.addAction(Notification.Action.Builder(null, L("结束"), stop).build())
+ } else {
+ if (blocking != null) {
+ // 设置 › AI 服务 over 首页, as the home card opens it.
+ val fix = android.app.TaskStackBuilder.create(context)
+ .addNextIntent(Intent(context, MainActivity::class.java))
+ .addNextIntent(Intent(context, AiServiceActivity::class.java))
+ .getPendingIntent(3, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
+ b.addAction(Notification.Action.Builder(null, L("打开设置"), fix).build())
+ }
+ b.addAction(Notification.Action.Builder(null, L("结束"), stop).build())
+ }
return b.setCategory(Notification.CATEGORY_SERVICE).build()
}
@@ -129,7 +142,7 @@ class ListenService : Service() {
val app = context.cicada
if (!app.listen.listening || (app.listen.sourceKind == "file" && app.importing == null)) { lastText = null; return }
val text = app.importing?.let { "${it.done.toInt()}" } + app.listen.sessionId?.let { app.store.lines(it).lastOrNull()?.let { l -> l.dst ?: l.src } } + "|" + app.listen.problem +
- "|" + app.ending?.let { app.endingLeft(it) }
+ "|" + app.ling.blocking + "|" + app.ending?.let { app.endingLeft(it) }
if (text == lastText) return
lastText = text
if (context.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED && Build.VERSION.SDK_INT >= 33) return
diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.kt b/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.kt
index 7a7beac..74f3aa3 100644
--- a/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.kt
+++ b/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.kt
@@ -31,7 +31,7 @@ object NotesViews {
val line = listen.sessionId?.let { app.store.lines(it).lastOrNull() }
return listOf(listen.listening, listen.sourceKind, listen.sessionId, listen.pending > 0, listen.problem, app.startProblem, silent(app), app.micSilenced,
line?.id, line?.src, line?.dst, app.notes.status, app.notes.notes.updatedAt, app.notes.notes.covered,
- app.ending?.deadline).joinToString("|")
+ app.ending?.deadline, app.ling.blocking).joinToString("|")
}
/// "正在听 · 03:12" / "面对面 · 03:12".
@@ -97,11 +97,14 @@ object NotesViews {
fun banner(ui: Ui, app: CicadaApp, onMic: (() -> Unit)?): View? {
val problem = app.listen.problem
val network = app.listen.problemKind == "network"
+ // A key, the credit or a model: before the hearing's own words ("Ling key 无效"), which say less.
+ val blocking = app.ling.blocking
val (iconRes, text) = when {
network -> R.drawable.i_wifi_off to
(if (app.ling.provider.id == "ling") L("连不上 Ling,联网后继续出字幕")
else LF("连不上 %@,这段时间的纪要先停在 %@。网络恢复后自动继续。", app.ling.serviceName, notesClock(app)))
app.micSilenced && app.listen.listening -> R.drawable.i_mic to L("麦克风正被通话或其他 app 占用,用完后接着听")
+ blocking != null -> R.drawable.i_info to blocking
problem != null -> R.drawable.i_info to problem
silent(app) -> R.drawable.i_speaker_off to L("20 秒没听到声音。通话和会议 app 的声音系统不让录")
else -> return null
@@ -114,9 +117,11 @@ object NotesViews {
minimumHeight = ui.dp(56)
addView(ui.icon(R.drawable.i_info, 22, Palette.link).apply { setImageDrawable(ui.drawable(iconRes, Palette.link)) })
addView(ui.text(text, 14f, Palette.ink), ui.weight().apply { leftMargin = ui.dp(12) })
- if (silent(app) && onMic != null) addView(ui.textButton(L("换成面对面"), onClick = onMic))
+ if (silent(app) && text != blocking && onMic != null) addView(ui.textButton(L("换成面对面"), onClick = onMic))
// The network or the proxy, not the notes: 设置 says which (only on Cicada's own screens).
- if (network && onMic != null && app.ling.provider.id != "ling")
+ if (blocking != null && text == blocking && onMic != null)
+ addView(ui.textButton(L("打开设置")) { ui.context.startActivity(android.content.Intent(ui.context, AiServiceActivity::class.java)) })
+ else if (network && onMic != null && app.ling.provider.id != "ling")
addView(ui.textButton(L("设置")) { ui.context.startActivity(android.content.Intent(ui.context, AiServiceActivity::class.java)) })
accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE
}
diff --git a/android/cli/src/main/kotlin/cicada/cli/AICheckTests.kt b/android/cli/src/main/kotlin/cicada/cli/AICheckTests.kt
index 6a92104..6cef472 100644
--- a/android/cli/src/main/kotlin/cicada/cli/AICheckTests.kt
+++ b/android/cli/src/main/kotlin/cicada/cli/AICheckTests.kt
@@ -26,6 +26,7 @@ object AICheckTests {
"aiCheckUnreachableAsksTheProxyAndTheNetworkLooksAgain" to ::clientUnreachable,
"aiCheckRealRequestsKeepTheStepsCurrent" to ::clientPassive,
"aiCheckSimulatedReasonsForScreenshots" to ::simulated,
+ "aiCheckOnlyWhatTheUserMustFixIsSaidBeyondSettings" to ::blocking,
)
private fun check(ok: Boolean, what: String) { if (!ok) throw AssertionError(what) }
@@ -78,6 +79,22 @@ object AICheckTests {
equal(Reason.NoModel, m.failure?.reason, "a missing text model stays missing")
}
+ fun blocking() {
+ // The Mac's AIServiceStrip.blocking, plus the port's deaf hear model: a key, the credit, a
+ // model or the settings. The network, a busy service and a server error fix themselves.
+ val needs = setOf(Reason.InvalidKey, Reason.MgmtKey, Reason.NoCredit, Reason.NoModel, Reason.NoJSON, Reason.BadAddress, Reason.Deaf)
+ for (r in Reason.values()) {
+ val b = AICheck.simulated(r).blocking("Ling", "openai/gpt-x", "google/omni-y")
+ equal(r in needs, b != null, "blocking $r")
+ }
+ equal(null, AICheck().blocking("Ling", "t", "h"), "nothing known yet")
+ equal("Ling 的 key 用不了" to "修好之前听不了", AICheck.simulated(Reason.InvalidKey).blocking("Ling", "t", "h"), "key")
+ equal("ZenMux 上找不到 gpt-x 这个模型。" to "字幕照常,纪要先停下", AICheck.simulated(Reason.NoModel).blocking("ZenMux", "openai/gpt-x", "h"), "short model, notes only")
+ equal("omni-y 听不了声音。", AICheck.simulated(Reason.Deaf).blocking("ZenMux", "t", "google/omni-y")?.first, "deaf")
+ // A heard segment after a bad key clears it: back to normal.
+ equal(null, AICheck.simulated(Reason.InvalidKey).pass(StepID.Hear, 1.0).blocking("Ling", "t", "h"), "fixed")
+ }
+
fun busyPasses() {
val c = AICheck().pass(StepID.Text, null).with(StepID.Text, State.Busy).copy(at = 1)
check(c.passed && c.busy && !c.needsUser, "busy passes")
diff --git a/android/core/src/main/kotlin/cicada/AICheck.kt b/android/core/src/main/kotlin/cicada/AICheck.kt
index 3292e7a..4ecf851 100644
--- a/android/core/src/main/kotlin/cicada/AICheck.kt
+++ b/android/core/src/main/kotlin/cicada/AICheck.kt
@@ -123,6 +123,25 @@ data class AICheck(
}
}
+ /// What stops listening or the notes until the user changes something (the Mac's
+ /// AIServiceStrip.blocking): (what's wrong, what it stops). Not the network, a busy service or
+ /// a server error: those fix themselves. Said beyond 设置, on the listening notification and the
+ /// live screens. Models by their short name (after the last "/").
+ fun blocking(service: String, textModel: String, hearModel: String): Pair<String, String>? {
+ val f = failure ?: return null
+ val stops = L("修好之前听不了")
+ val notesStop = L("字幕照常,纪要先停下")
+ return when (f.reason) {
+ Reason.InvalidKey, Reason.MgmtKey -> LF("%@ 的 key 用不了", service) to stops
+ Reason.NoCredit -> LF("%@ 账户余额不足。", service) to stops
+ Reason.NoModel -> LF("%@ 上找不到 %@ 这个模型。", service, textModel.substringAfterLast('/')) to notesStop
+ Reason.Deaf -> LF("%@ 听不了声音。", hearModel.substringAfterLast('/')) to stops
+ Reason.BadAddress -> L("AI 服务的设置要改一下") to stops
+ Reason.NoJSON -> L("AI 服务的设置要改一下") to notesStop
+ Reason.Unreachable, Reason.Busy, Reason.ServerError -> null
+ }
+ }
+
/// The proxy line under "can't reach": what this phone's proxy looks like, and what to do.
fun proxyLine(service: String, host: String): String? {
if (failure?.reason != Reason.Unreachable) return null
diff --git a/android/core/src/main/kotlin/cicada/Ling.kt b/android/core/src/main/kotlin/cicada/Ling.kt
index 8d694cc..b117fa0 100644
--- a/android/core/src/main/kotlin/cicada/Ling.kt
+++ b/android/core/src/main/kotlin/cicada/Ling.kt
@@ -272,6 +272,14 @@ class LingClient(
/// The failed (or busy) step's sentence, for the screens.
fun checkMessage(): String? = config().let { aiCheck.message(serviceName, serviceHost, it.textModel, it.hearModel) }
+ /// Something only the user can fix, in one line ("Ling 的 key 用不了 · 修好之前听不了"): the
+ /// listening notification and the live screens. Null without a key (onboarding asks for it).
+ val blocking: String? get() {
+ if (!hasKey) return null
+ val (what, stops) = config().let { aiCheck.blocking(serviceName, it.textModel, it.hearModel) } ?: return null
+ return what.trimEnd('。', '.') + " · " + stops
+ }
+
/// The key, the service or its models changed: forget what the last check found.
fun keyChanged() {
key.reload()