知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
feat(android): when an AI service has trouble, the live screens say in one line what is waiting and what still works, with Use Ling one tap away
wquguru65d93f5bb78d
diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/App.kt b/android/app/src/main/kotlin/com/wquguru/cicada/App.ktindex e621940..f4b8a66 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/App.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/App.kt@@ -408,6 +408,15 @@ class CicadaApp : Application() {aiChanged(check)}+ /// "改用 Ling" where another service is out of reach: only when a Ling key is already saved,+ /// so the one tap works without a trip to the settings.+ val canSwitchToLing: Boolean get() = settings.aiProvider != "ling" && Paths.keyFile("ling").isFile++ fun switchToLing() {+ if (!canSwitchToLing) return+ setAiProvider("ling")+ }+/// A model chosen over the recommended one ("text", "hear" or "voice"; "" goes back to it).fun setAiModel(kind: String, model: String) {val s = settingsdiff --git a/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt b/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.ktindex e5da8c1..33257b7 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt@@ -92,6 +92,8 @@ class DebugReceiver : BroadcastReceiver() {return mapOf("ok" to true, "ai" to ai(app))} else { app.key.reload(); app.ling.keyChanged(); app.background.execute { app.ling.check() } }"provider" -> { app.setAiProvider(arg); return mapOf("ok" to true, "ai" to ai(app)) }+ // The 改用 Ling on a status line (says when it isn't offered).+ "switchToLing" -> { val offered = app.canSwitchToLing; app.switchToLing(); return mapOf("offered" to offered, "ai" to ai(app)) }// ai-check-sim <reason|lowBalance|off>: every check ends this way (screenshots of each state)."ai-check-sim" -> {app.ling.simulateCheck = cicada.AICheck.reasonNamed(arg)diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.kt b/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.ktindex d51f28f..1995daf 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, app.ling.blocking).joinToString("|")+ app.ending?.deadline, app.ling.blocking, listen.problemKind, app.ling.provider.id).joinToString("|")}/// "正在听 · 03:12" / "面对面 · 03:12".@@ -96,20 +96,24 @@ object NotesViews {fun banner(ui: Ui, app: CicadaApp, onMic: (() -> Unit)?): View? {val problem = app.listen.problem- val network = app.listen.problemKind == "network"+ val kind = app.listen.problemKind// 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,联网后继续出字幕")- // Hearing goes through the service too: the subtitles stopped with the notes, so no notes time.- else LF("连不上 %@,字幕和纪要暂停,连上后自动继续。", serviceLabel(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+ val micTaken = app.micSilenced && app.listen.listening+ // The service's trouble is a status line; the microphone taken or nothing heard is not.+ when {+ // Hearing goes through the service too: the subtitles wait with the notes. The network or+ // the proxy, not the notes: it picks up by itself, or 改用 Ling when that key is saved.+ kind == "network" -> return statusLine(ui, Tone.Waiting, LF("字幕和纪要等 %@ 恢复 · 连上后自动继续", serviceLabel(app)),+ if (app.canSwitchToLing) L("改用 Ling") to { app.switchToLing() } else null)+ micTaken -> {}+ blocking != null -> return statusLine(ui, Tone.NeedsYou, blocking, openSettings(ui, onMic))+ problem != null -> return statusLine(ui, when (kind) { "busy" -> Tone.Waiting; "key" -> Tone.NeedsYou; else -> Tone.Info },+ problem, openSettings(ui, onMic).takeIf { kind == "key" })+ !silent(app) -> return null}+ val (iconRes, text) = if (micTaken) R.drawable.i_mic to L("麦克风正被通话或其他 app 占用,用完后接着听")+ else R.drawable.i_speaker_off to L("20 秒没听到声音。通话和会议 app 的声音系统不让录")return LinearLayout(ui.context).apply {orientation = LinearLayout.HORIZONTALgravity = Gravity.CENTER_VERTICAL@@ -118,16 +122,41 @@ 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) && 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 (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)) })+ if (!micTaken && onMic != null) addView(ui.textButton(L("换成面对面"), onClick = onMic))accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE}}+ /// 打开设置 › AI 服务, on Cicada's own screens only (`onMic` set): not from the floating window.+ private fun openSettings(ui: Ui, onMic: (() -> Unit)?): Pair<String, () -> Unit>? = if (onMic == null) null+ else L("打开设置") to { ui.context.startActivity(android.content.Intent(ui.context, AiServiceActivity::class.java)) }++ /// How a status line reads at a glance, by its dot alone (a passing wait shouldn't look like a+ /// fault): Waiting comes back by itself, NeedsYou is the user's to fix, Info is just so you know.+ enum class Tone { Waiting, NeedsYou, Info }++ /// A service in trouble, said the same way wherever it shows (the Mac's StatusLine): a dot,+ /// "what waits for what · what still works", and at most one action. The text is child 1:+ /// the floating window's subtitle bar takes it from there.+ fun statusLine(ui: Ui, tone: Tone, text: String, action: Pair<String, () -> Unit>? = null): LinearLayout = LinearLayout(ui.context).apply {+ orientation = LinearLayout.HORIZONTAL+ gravity = Gravity.CENTER_VERTICAL+ background = ui.rounded(FILL, 10)+ setPadding(ui.dp(12), ui.dp(7), ui.dp(if (action != null) 4 else 12), ui.dp(7))+ minimumHeight = ui.dp(36)+ addView(ui.dot(when (tone) { Tone.Waiting -> WAITING; Tone.NeedsYou -> Palette.link; Tone.Info -> Palette.tertiary }, 6))+ addView(ui.text(text, 12f, Palette.secondary).apply { leading(1.4f) }, ui.weight().apply { leftMargin = ui.dp(8) })+ if (action != null) addView(ui.tappable(ui.text(action.first, 12f, Palette.ink, bold = true, lines = 1).apply {+ gravity = Gravity.CENTER+ minHeight = ui.dp(36)+ setPadding(ui.dp(8), 0, ui.dp(8), 0)+ }, 8, onClick = action.second), LinearLayout.LayoutParams(-2, -2).apply { leftMargin = ui.dp(4) })+ accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE+ }++ /// #C98A00, the Mac's waiting dot: AiCheckViews.warn is too dark to tell from the text at 6 dp.+ private val WAITING = android.graphics.Color.parseColor("#C98A00")+/// Where this meeting's notes stop: the time of the last line they cover./// Who the banner names: a custom service by its address, which says more than 这个服务.private fun serviceLabel(app: CicadaApp): String =@@ -254,6 +283,7 @@ object NotesViews {/// `heard`: this meeting's lines so far, for the listening placeholder.fun notesBody(ui: Ui, notes: MeetingNotes, status: NotesEngine.State, listening: Boolean, compact: Boolean = false, heard: Int = 0): LinearLayout {val body = ui.stack(0)+ notesTrouble(ui, notes, status, listening, actions = !compact)?.let { body.addView(it, LinearLayout.LayoutParams(-1, -2).apply { bottomMargin = ui.dp(12) }) }// Listening and no request out yet (the first waits for a few lines or 20 s): the notes'// own shape, kept after the first line is heard (the Mac's notesPane).if (notes.isEmpty && listening && (status == NotesEngine.State.Idle || status == NotesEngine.State.Failed)) {@@ -269,23 +299,12 @@ object NotesViews {if (notes.isEmpty) {val hint = when (status) {NotesEngine.State.NoKey -> CicadaApp.shared.noKeyText()- NotesEngine.State.InvalidKey -> CicadaApp.shared.ling.provider.let { p ->- if (p.id == "ling") L("这个 Ling key 无效,看看有没有复制全,或换一个新的")- else cicada.Strings.LF("%@ 说这个 key 无效,可能没复制全,或已删除。", L(p.name))- }- NotesEngine.State.RateLimited -> LF("%@ 很忙,纪要稍后补上。字幕照常。", serviceLabel(CicadaApp.shared))NotesEngine.State.Updating -> L("正在整理纪要…")else -> ""}if (hint.isNotEmpty()) body.addView(ui.text(hint, 14f, Palette.secondary))return body}- // A busy service: the notes catch up by themselves, the subtitles never stopped.- if (status == NotesEngine.State.RateLimited && listening)- body.addView(ui.text(LF("%@ 很忙,纪要稍后补上。字幕照常。", serviceLabel(CicadaApp.shared)), 13f, AiCheckViews.warn).apply {- background = ui.rounded(AiCheckViews.warnPale, 10)- setPadding(ui.dp(10), ui.dp(8), ui.dp(10), ui.dp(8))- }, LinearLayout.LayoutParams(-1, -2).apply { bottomMargin = ui.dp(12) })if (!compact) {val head = LinearLayout(ui.context).apply {orientation = LinearLayout.HORIZONTAL@@ -318,6 +337,29 @@ object NotesViews {return body}+ /// What went wrong with the notes' own request, as a status line (the Mac's notes banner), or+ /// null. What the live banner already says (the service unreachable, busy for the hearing too,+ /// a key it can't use) isn't said twice. `actions`: 换 key opens the settings, so not from the+ /// floating window.+ private fun notesTrouble(ui: Ui, notes: MeetingNotes, status: NotesEngine.State, listening: Boolean, actions: Boolean): View? {+ val app = CicadaApp.shared+ val shown = app.listen.problemKind.takeIf { listening }+ return when {+ status == NotesEngine.State.InvalidKey && !(listening && app.ling.blocking != null) -> {+ val stopped = currentLines(app).getOrNull(notes.covered - 1)?.t.takeIf { !notes.isEmpty }+ statusLine(ui, Tone.NeedsYou, if (stopped != null) LF("key 失效了 · 纪要停在 %@", Languages.clock(stopped)) else L("key 失效了 · 纪要等新的 key"),+ if (actions) L("换 key") to { ui.context.startActivity(android.content.Intent(ui.context, AiServiceActivity::class.java)) } else null)+ }+ // A busy notes request is its own: the hearing goes on unless it is busy too (then the banner says so).+ status == NotesEngine.State.RateLimited && (listening || notes.isEmpty) && shown != "busy" ->+ statusLine(ui, Tone.Waiting, LF("%@ 很忙 · 纪要稍后补上,字幕照常", serviceLabel(app)))+ // Nothing reached: the banner's 字幕和纪要等 … 恢复 covers this round too.+ status == NotesEngine.State.Failed && listening && shown != "network" ->+ statusLine(ui, Tone.Info, L("这轮纪要没写好 · 下轮自动补上"))+ else -> null+ }+ }+/// The Mac's NotesListeningView: a quiet status row, then the notes' shape waiting to be/// filled and what they will hold. `compact` (the floating window) keeps the status row only./// `generating`: the first request is out: a spinner and 正在生成纪要… instead of the sound bars,diff --git a/android/app/src/main/strings/en.lproj/Android.strings b/android/app/src/main/strings/en.lproj/Android.stringsindex 1ad380e..6e9d428 100644--- a/android/app/src/main/strings/en.lproj/Android.strings+++ b/android/app/src/main/strings/en.lproj/Android.strings@@ -24,13 +24,9 @@"句" = "lines";"%@ 个待办" = "To-dos: %@";"%@ 分钟前更新" = "Updated %@ min ago";-"连不上 Ling,检查网络" = "Can't reach Ling; check your network";-"连不上 Ling,联网后继续出字幕" = "Can't reach Ling. Subtitles will resume when back online.";-"连不上 %@,字幕和纪要暂停,连上后自动继续。" = "Can't reach %@. Subtitles and notes are paused and resume once it's back.";"20 秒没听到声音。通话和会议 app 的声音系统不让录" = "No sound for 20s. Call & meeting apps block audio capture.";"换成面对面" = "Switch to In person";"正在听下一句…" = "Listening for next line…";-"这个 Ling key 无效,看看有没有复制全,或换一个新的" = "Invalid Ling key. Check if it's complete, or create a new one.";"返回" = "Back";"要粘贴 sk- 开头的 Ling key" = "Paste a Ling key starting with sk-";"连不上 Ling,检查一下网络" = "Can't reach Ling. Check your connection.";@@ -224,3 +220,4 @@"没填,用手机的声音" = "Not set: the phone's voice";"本机和局域网服务可不填" = "Optional on this phone or your local network";"刚刚开会时用过" = "used in a meeting just now";+"这句没说出去 · 连不上 %@" = "This line wasn't said · can't reach %@";diff --git a/android/app/src/main/strings/ja.lproj/Android.strings b/android/app/src/main/strings/ja.lproj/Android.stringsindex b19f3e3..e3ac69f 100644--- a/android/app/src/main/strings/ja.lproj/Android.strings+++ b/android/app/src/main/strings/ja.lproj/Android.strings@@ -24,13 +24,9 @@"句" = "文";"%@ 个待办" = "ToDo %@件";"%@ 分钟前更新" = "%@分前に更新";-"连不上 Ling,检查网络" = "Ling に接続できません。ネットワークを確認してください";-"连不上 Ling,联网后继续出字幕" = "Lingに接続できません。通信が戻ると字幕を再開します";-"连不上 %@,字幕和纪要暂停,连上后自动继续。" = "%@ に接続できません。字幕とメモは一時停止中、つながると自動で再開します。";"20 秒没听到声音。通话和会议 app 的声音系统不让录" = "20秒間音声がありません。通話・会議アプリは録音できません";"换成面对面" = "対面に切り替える";"正在听下一句…" = "次の発言を聞いています…";-"这个 Ling key 无效,看看有没有复制全,或换一个新的" = "この Ling key は無効です。すべてコピーしたか確認するか、新しく作成してください";"返回" = "戻る";"要粘贴 sk- 开头的 Ling key" = "sk- で始まる Ling key を貼り付けてください";"连不上 Ling,检查一下网络" = "Lingに接続できません。通信環境を確認してください";@@ -224,3 +220,4 @@"没填,用手机的声音" = "未設定:スマホの声";"本机和局域网服务可不填" = "このスマホやローカルネットワークでは省略可";"刚刚开会时用过" = "さっき会議で使用";+"这句没说出去 · 连不上 %@" = "この文は発話していません · %@ に接続できません";diff --git a/android/app/src/main/strings/ko.lproj/Android.strings b/android/app/src/main/strings/ko.lproj/Android.stringsindex 330bcf1..a655e76 100644--- a/android/app/src/main/strings/ko.lproj/Android.strings+++ b/android/app/src/main/strings/ko.lproj/Android.strings@@ -24,13 +24,9 @@"句" = "문장";"%@ 个待办" = "할 일 %@개";"%@ 分钟前更新" = "%@분 전 업데이트";-"连不上 Ling,检查网络" = "Ling에 연결할 수 없습니다. 네트워크를 확인하세요";-"连不上 Ling,联网后继续出字幕" = "Ling에 연결할 수 없어요. 네트워크가 복구되면 자막이 다시 나와요";-"连不上 %@,字幕和纪要暂停,连上后自动继续。" = "%@에 연결할 수 없습니다. 자막과 노트가 멈췄고, 연결되면 자동으로 이어집니다.";"20 秒没听到声音。通话和会议 app 的声音系统不让录" = "20초 동안 소리가 안 들려요. 통화 및 회의 앱은 녹음할 수 없어요";"换成面对面" = "대면으로 전환";"正在听下一句…" = "다음 문장 듣는 중…";-"这个 Ling key 无效,看看有没有复制全,或换一个新的" = "유효하지 않은 Ling key예요. 끝까지 복사했는지 확인하거나 새로 만들어 보세요";"返回" = "뒤로";"要粘贴 sk- 开头的 Ling key" = "sk-로 시작하는 Ling key를 붙여넣어 주세요";"连不上 Ling,检查一下网络" = "Ling에 연결할 수 없어요. 네트워크를 확인해 보세요";@@ -224,3 +220,4 @@"没填,用手机的声音" = "설정 안 함: 휴대폰 음성";"本机和局域网服务可不填" = "이 휴대폰이나 로컬 네트워크에서는 생략 가능";"刚刚开会时用过" = "방금 회의에서 사용함";+"这句没说出去 · 连不上 %@" = "이 문장은 말하지 않았습니다 · %@에 연결할 수 없음";diff --git a/android/cli/src/main/kotlin/cicada/cli/ProviderTests.kt b/android/cli/src/main/kotlin/cicada/cli/ProviderTests.ktindex 2d350ad..0878dc7 100644--- a/android/cli/src/main/kotlin/cicada/cli/ProviderTests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/ProviderTests.kt@@ -433,7 +433,7 @@ object ProviderTests {fun problemsNameTheService() {equal("key", ListenEngine.problem(LingException(LingException.Kind.Http, 400), "ZenMux").first, "a deaf model is a settings problem")check(ListenEngine.problem(LingException(LingException.Kind.Network), "ZenMux").second!!.contains("ZenMux"), "named")- equal("network" to "连不上 Ling,检查网络", ListenEngine.problem(LingException(LingException.Kind.Timeout), "Ling"), "Ling's own words")+ equal("network" to "字幕和纪要等 Ling 恢复 · 连上后自动继续", ListenEngine.problem(LingException(LingException.Kind.Timeout), "Ling"), "what waits and that it goes on")equal(null, ListenEngine.problem(LingException(LingException.Kind.Http, 400), "Ling").first, "Ling's 400 is not the model")// A gateway's 502 in front of the server: the service erring, not the network or the key.equal("busy" to "ZenMux 暂时出错(HTTP 502),稍后再试。", ListenEngine.problem(LingException(LingException.Kind.Http, 502), "ZenMux"), "a 5xx is the service's trouble")diff --git a/android/cli/src/main/kotlin/cicada/cli/Tests.kt b/android/cli/src/main/kotlin/cicada/cli/Tests.ktindex de5866b..a3cc894 100644--- a/android/cli/src/main/kotlin/cicada/cli/Tests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/Tests.kt@@ -1022,7 +1022,7 @@ object Tests {engine.hold(); src.push(tone(1.2)); engine.release(); src.push(silence(0.3))val until = System.currentTimeMillis() + 4000while (engine.sayProblem == null && System.currentTimeMillis() < until) Thread.sleep(20)- equal("翻译失败,这句话未发送", engine.sayProblem, "the Mac's message")+ equal("这句没翻译成 · 没有说出去", engine.sayProblem, "the Mac's message")equal(null, spoken, "nothing spoken")check(store.get(engine.sessionId!!)!!.lines.none { it.speaker == "me" }, "nothing recorded")engine.stop()diff --git a/android/core/src/main/kotlin/cicada/ListenEngine.kt b/android/core/src/main/kotlin/cicada/ListenEngine.ktindex 071b6f0..95b4ccf 100644--- a/android/core/src/main/kotlin/cicada/ListenEngine.kt+++ b/android/core/src/main/kotlin/cicada/ListenEngine.kt@@ -234,7 +234,7 @@ class ListenEngine(Log.d("listen: said ${heard.lang} -> $their, ${if (text != null) "speaking" else "not spoken"}")// As on the Mac: a sentence that didn't translate is neither sent nor recorded. One// already in their language was heard as it is, so it is kept.- if (text == null && !sameLanguage) { sayProblem = Strings.L("翻译失败,这句话未发送"); return }+ if (text == null && !sameLanguage) { sayProblem = Strings.L("这句没翻译成 · 没有说出去"); return }val n = synchronized(gate) { ++saidCount }val line = TranscriptLine(id = "m$n", t = t, speaker = "me", src = heard.original, dst = dst,srcLang = heard.lang, dstLang = their)@@ -249,8 +249,9 @@ class ListenEngine(e.kind == LingException.Kind.Http && e.status in listOf(400, 404) && name != "Ling" -> Strings.L("这个模型听不了声音,换一个支持音频输入的")e.kind == LingException.Kind.NoKey || e.kind == LingException.Kind.InvalidKey ->if (name == "Ling") Strings.L("Ling key 无效") else Strings.LF("%@ 的 key 无效", Strings.L(name))+ // One held sentence: say it didn't go out and why; the meeting's own line covers the rest.e.kind == LingException.Kind.Network || e.kind == LingException.Kind.Timeout ->- if (name == "Ling") Strings.L("连不上 Ling,检查网络") else Strings.LF("连不上 %@", Strings.L(name))+ Strings.LF("这句没说出去 · 连不上 %@", Strings.L(name))else -> Strings.L("没听清,再说一次")}Log.d("listen: saying failed ${e.message}")@@ -399,7 +400,8 @@ class ListenEngine(LingException.Kind.NoKey -> if (ling) Strings.L("需要 Ling key 才能听") else Strings.LF("需要 %@ 的 key 才能听", name)LingException.Kind.InvalidKey -> if (ling) Strings.L("Ling key 无效") else Strings.LF("%@ 的 key 无效", name)LingException.Kind.RateLimited -> if (ling) Strings.L("Ling 太忙,稍后再试") else Strings.LF("%@ 太忙,稍后再试", name)- LingException.Kind.Network, LingException.Kind.Timeout -> if (ling) Strings.L("连不上 Ling,检查网络") else Strings.LF("连不上 %@", name)+ // Hearing goes through the service: the subtitles wait with the notes, then go on by themselves.+ LingException.Kind.Network, LingException.Kind.Timeout -> Strings.LF("字幕和纪要等 %@ 恢复 · 连上后自动继续", name)else -> null}return kind to text