知了 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): with your own AI service, meeting audio and text can stay off Google Translate
wquguru3b337934aa7d
diff --git a/android/README.md b/android/README.mdindex 1927203..7f3f166 100644--- a/android/README.md+++ b/android/README.md@@ -45,7 +45,7 @@ scripts/shot.sh # 截图:悬浮窗应是黑块;capture oscripts/tap.sh "开始听" # 按屏幕上的文字点(系统对话框也行),用来走真实界面```-`cicadactl.sh` 的命令见 `app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt`(state、start、stop、feed、sample、view、capture、overlay show|hide|collapse|expand、target、ui、show main|live|records|record|settings|ai|onboarding、import、provider、ai-model、key import、voice-try、updatefeed、update check|download|job|notify)。只有开发版有,且只接受 adb。开发版默认不检查更新(点设置里的“检查更新”或用下面的命令后才查):`cicadactl.sh push feed.json && cicadactl.sh updatefeed feed.json` 指向一份测试用的 release JSON(不带参数就是 GitHub),`adb shell cmd jobscheduler run -f com.wquguru.cicada.dev 7` 立刻跑一次后台检查。+`cicadactl.sh` 的命令见 `app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt`(state、start、stop、feed、sample、view、capture、overlay show|hide|collapse|expand、target、ui、show main|live|records|record|settings|ai|onboarding、import、provider、ai-model、ai-custom-only on|off、key import、voice-try、updatefeed、update check|download|job|notify)。只有开发版有,且只接受 adb。开发版默认不检查更新(点设置里的“检查更新”或用下面的命令后才查):`cicadactl.sh push feed.json && cicadactl.sh updatefeed feed.json` 指向一份测试用的 release JSON(不带参数就是 GitHub),`adb shell cmd jobscheduler run -f com.wquguru.cicada.dev 7` 立刻跑一次后台检查。界面按 claude.ai 上的设计画布实现:首页、正在听、悬浮窗(纪要卡片 / 字幕条 / 小圆点)、三步引导、会议记录、会议详情、设置。文案用 Gemini(`google/gemini-4-argon`)审过一遍,与 Mac 共用的文案沿用 Mac 的译法。diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/AiServiceActivity.kt b/android/app/src/main/kotlin/com/wquguru/cicada/AiServiceActivity.ktindex 2b910c4..bdc3b3c 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/AiServiceActivity.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/AiServiceActivity.kt@@ -181,15 +181,39 @@ class AiServiceActivity : Activity() {hearSection(app, c, opened, rows)voiceSection(app, c, opened, rows)page.addView(ui.group(rows))+ page.addView(ui.group(listOf(onlyRow(app))).apply {+ layoutParams = LinearLayout.LayoutParams(-1, -2).apply { topMargin = ui.dp(16) }+ })val host = c.base?.let { Uri.parse(it).host } ?: L("你填的地址")page.addView(ui.helper(LF("加密存在这台手机上,只发给 %@", host)).apply { setPadding(ui.dp(16), ui.dp(8), ui.dp(16), 0) })// Never "按所选模型计费" here: the user runs it, or their provider bills it its own way.val nearby = c.base?.let(Providers::isNearby) ?: falseval foot = (if (nearby) L("跑在你自己的机器上,不按量计费。") else L("费用以这个服务为准。")) +- LF("听的时候,声音会发给 %@。", ling.hearHost.ifEmpty { host })+ if (app.settings.aiCustomOnly) LF("会议的语音和文字只发给 %@,不经过 Google 等外部服务。", customHosts(c))+ else LF("听的时候,声音会发给 %@。", ling.hearHost.ifEmpty { host })page.addView(ui.helper(foot).apply { setPadding(ui.dp(16), ui.dp(12), ui.dp(16), 0) })}+ /// 语音和文字只发给你的服务 (AISettings.swift › onlyRow): Google is never asked. The grey line says+ /// what it costs, and while the service can't be reached, that new subtitles are the original+ /// only (a phone has no on-device translation to stand in).+ private fun onlyRow(app: CicadaApp): View {+ val on = app.settings.aiCustomOnly+ val check = app.ling.aiCheck+ val failure = check.failure+ val down = on && app.ling.hasKey && !check.running && failure != null && failure.reason != AICheck.Reason.Busy+ val detail = if (down) L("现在连不上:新字幕暂时只有原文") else L("不用 Google 翻译;说话时要等整句说完才出译文")+ return ui.switchRow(L("语音和文字只发给你的服务"), detail, on) { app.setCustomOnly(it) }+ }++ /// Where the custom service's audio and text go: one host when every use shares it. On a phone+ /// the hear model always listens, so its address always counts.+ private fun customHosts(c: AIConfig): String {+ val hosts = listOfNotNull(c.base, c.hearBase, c.voiceBase?.takeIf { c.hasVoices })+ .map { Uri.parse(it).host }.toSet()+ return hosts.singleOrNull() ?: L("你填的地址")+ }+/// A row that opens to its fields: a state dot, the use, what it runs on, and how it's doing.private fun useRow(id: String, open: MutableSet<String>, title: String, detail: String, dot: Int, trailing: String?,trailingColor: Int = Palette.tertiary): View {@@ -265,7 +289,7 @@ class AiServiceActivity : Activity() {ui.listRow(if (check.running) L("正在检查…") else L("重新检查"), null,leading = ui.icon(R.drawable.i_restore, 22, if (check.running) Palette.tertiary else Palette.body), chevron = false,onClick = if (check.running || k == null) null else ({ app.recheck() })),- check.slowLine()?.let { note(it, AiCheckViews.warn) },+ check.slowLine(app.translator.googleOff)?.let { note(it, AiCheckViews.warn) },if (steps) AiCheckViews.steps(this, ui, recheck = false) { editKey(this, ui) } else null,facts?.let { note(it, Palette.tertiary) },))diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/App.kt b/android/app/src/main/kotlin/com/wquguru/cicada/App.ktindex f4b8a66..fb4125f 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/App.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/App.kt@@ -89,6 +89,7 @@ class CicadaApp : Application() {background.execute { val t = System.currentTimeMillis(); store.load(); Log.d("store: loaded ${store.all().size} in ${System.currentTimeMillis() - t} ms") }notes = NotesEngine(ling, store)translator = Translator(ling)+ translator.googleOff = settings.customOnlylisten = ListenEngine(ling, translator, store, notes, settings)listen.encoder = { pcm ->val t = System.currentTimeMillis()@@ -432,11 +433,23 @@ class CicadaApp : Application() {/// The service, its address, models or key changed: forget the old check and check again.fun aiChanged(check: Boolean = true) {+ // 语音和文字只发给你的服务 acts on the custom service only: another service brings Google back.+ translator.googleOff = settings.customOnlyling.keyChanged()if (check && ling.hasKey) background.execute { ling.check() }changed()}+ /// 语音和文字只发给你的服务: kept for every service, in effect for the custom one. The service is+ /// the same, so its check stays (not aiChanged, which forgets it).+ fun setCustomOnly(on: Boolean) {+ settings.aiCustomOnly = on+ settings.save()+ translator.googleOff = settings.customOnly+ Log.d("ai: custom only ${if (on) "on" else "off"}")+ changed()+ }+/// 重新检查.fun recheck() { if (ling.hasKey && !ling.aiCheck.running) background.execute { ling.check() } }@@ -454,6 +467,7 @@ class CicadaApp : Application() {fun switchService(id: String, key: String) {settings.aiProvider = idsettings.save()+ translator.googleOff = settings.customOnlyLog.d("ai: provider $id (the key's own)")if (!this.key.save(key)) returnaiChanged()diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt b/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.ktindex 33257b7..fc17fb5 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/DebugReceiver.kt@@ -108,6 +108,8 @@ class DebugReceiver : BroadcastReceiver() {app.setAiModel(kind, model)return mapOf("ok" to true, "ai" to ai(app))}+ // 语音和文字只发给你的服务 (the Mac's aiCustomOnly:on|off): `ai-custom-only on|off`.+ "ai-custom-only" -> { app.setCustomOnly(arg == "on"); return mapOf("ok" to true, "ai" to ai(app)) }"voice-try" -> app.background.execute {val r = app.voice.speakCloud(app.ling, "Could you send the revised quote by Friday? We can sign next week.", {}, {})Log.d("debug: voice-try -> $r")@@ -146,7 +148,9 @@ class DebugReceiver : BroadcastReceiver() {return mapOf("provider" to c.provider.id, "base" to c.base, "text" to c.textModel, "hear" to c.hearModel, "hearBase" to c.hearBase, "voice" to c.voiceModel,"state" to l.keyState.name, "hears" to l.hears, "speaks" to l.speaks, "check" to l.aiCheck.summary,"voice" to l.lastVoice?.first, "sim" to l.simulateCheck?.name,- "catalog" to listOf(l.textCatalog.size, l.hearCatalog.size), "keyFile" to app.key.path.name)+ "catalog" to listOf(l.textCatalog.size, l.hearCatalog.size), "keyFile" to app.key.path.name,+ "customOnly" to app.settings.aiCustomOnly, "googleOff" to app.translator.googleOff,+ "untranslated" to app.translator.sentencesUntranslated)}fun state(app: CicadaApp): Map<String, Any?> {diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.kt b/android/app/src/main/kotlin/com/wquguru/cicada/NotesViews.ktindex 1995daf..72dd2d3 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, listen.problemKind, app.ling.provider.id).joinToString("|")+ app.ending?.deadline, app.ling.blocking, listen.problemKind, app.ling.provider.id, customOnlyUntranslated(app)).joinToString("|")}/// "正在听 · 03:12" / "面对面 · 03:12".@@ -110,6 +110,9 @@ object NotesViews {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" })+ // 语音和文字只发给你的服务: heard, but the user's service didn't translate and Google isn't+ // asked. It picks up by itself; no 改用 Ling, which would send the meeting elsewhere.+ customOnlyUntranslated(app) -> return statusLine(ui, Tone.Waiting, LF("译文等 %@ 恢复 · 字幕先显示原文", serviceLabel(app)))!silent(app) -> return null}val (iconRes, text) = if (micTaken) R.drawable.i_mic to L("麦克风正被通话或其他 app 占用,用完后接着听")@@ -157,6 +160,10 @@ object NotesViews {/// #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")+ /// Finished sentences going untranslated with 语音和文字只发给你的服务 in effect (the Mac's googleOff banner).+ private fun customOnlyUntranslated(app: CicadaApp) =+ app.listen.listening && app.translator.googleOff && app.translator.sentencesUntranslated+/// 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 =diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/SettingsActivity.kt b/android/app/src/main/kotlin/com/wquguru/cicada/SettingsActivity.ktindex 6288578..1d5d2ff 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/SettingsActivity.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/SettingsActivity.kt@@ -3,14 +3,12 @@ package com.wquguru.cicadaimport android.app.Activityimport android.content.ClipboardManagerimport android.content.Intent-import android.content.res.ColorStateListimport android.net.Uriimport android.os.Bundleimport android.provider.Settingsimport android.view.Gravityimport android.view.Viewimport android.widget.LinearLayout-import android.widget.Switchimport cicada.AIKeyimport cicada.Languagesimport cicada.Log@@ -72,19 +70,19 @@ class SettingsActivity : Activity() {// on the Mac or Windows; the helper says so.page.addView(ui.sectionLabel(L("听对方")))page.addView(ui.group(listOf(- switchRow(L("说话人识别"), L("显示 Mac 和 Windows 上分出的说话人;这台手机还不能按声音分人"), s.speakerVoices) { s.speakerVoices = it; app.saveSettings() },- switchRow(L("保存会议录音"), L("只存在这台手机上,会议记录里能回放原声"), s.recordAudio) { s.recordAudio = it; app.saveSettings() })))+ ui.switchRow(L("说话人识别"), L("显示 Mac 和 Windows 上分出的说话人;这台手机还不能按声音分人"), s.speakerVoices) { s.speakerVoices = it; app.saveSettings() },+ ui.switchRow(L("保存会议录音"), L("只存在这台手机上,会议记录里能回放原声"), s.recordAudio) { s.recordAudio = it; app.saveSettings() })))page.addView(ui.sectionLabel(L("我说 · 面对面")))page.addView(ui.group(listOf(- switchRow(L("把我说的翻译给对方"), L("按住说话,松开后用对方的语言读出来"), s.speakBack) { s.speakBack = it; app.saveSettings() },+ ui.switchRow(L("把我说的翻译给对方"), L("按住说话,松开后用对方的语言读出来"), s.speakBack) { s.speakBack = it; app.saveSettings() },ui.listRow(L("试一句"), AiServiceActivity.cloudVoice(app)?.let { Strings.LF("用 %@ 的声音读一句英语", it) } ?: L("用手机的声音读一句英语"), trailing = ui.icon(R.drawable.i_play, 20, Palette.ink), chevron = false) { tryVoice() })))page.addView(ui.sectionLabel(L("在其他应用上")))val rows = mutableListOf<View>(- switchRow(L("悬浮窗"), L("切到其他应用时,在上面显示字幕或纪要"), s.overlay) { s.overlay = it; app.saveSettings(); if (!it) app.overlay.hide() },+ ui.switchRow(L("悬浮窗"), L("切到其他应用时,在上面显示字幕或纪要"), s.overlay) { s.overlay = it; app.saveSettings(); if (!it) app.overlay.hide() },choiceRow(L("样式"), listOf("notes" to L("实时纪要"), "subtitles" to L("字幕条")), s.view) { app.setView(it) },- switchRow(L("共享屏幕时让对方看到"), L("关闭时,截图和录屏里看不到悬浮窗"), s.showInCapture) { s.showInCapture = it; app.saveSettings(); app.overlay.rebuild() })+ ui.switchRow(L("共享屏幕时让对方看到"), L("关闭时,截图和录屏里看不到悬浮窗"), s.showInCapture) { s.showInCapture = it; app.saveSettings(); app.overlay.rebuild() })if (!app.canOverlay) rows.add(0, ui.listRow(L("开启“显示在其他应用上层”"), null, leading = ui.icon(R.drawable.i_pip, 22, Palette.link)) {OverlayGuideActivity.open(this, direct = true)})@@ -137,34 +135,6 @@ class SettingsActivity : Activity() {ui.choose(this, label, options, selected) { changed(it); shown = null; build() }}- /// A row with a switch; the whole row toggles it.- private fun switchRow(label: String, helper: String, on: Boolean, changed: (Boolean) -> Unit): LinearLayout {- val sw = Switch(this).apply {- isChecked = on- val states = arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf())- thumbTintList = ColorStateList(states, intArrayOf(android.graphics.Color.WHITE, Palette.secondary))- trackTintList = ColorStateList(states, intArrayOf(Palette.ink, Palette.outline))- // The framework track is drawn faded; SRC paints the tint at full strength.- trackTintMode = android.graphics.PorterDuff.Mode.SRC- importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO- isClickable = false- }- lateinit var row: LinearLayout- row = ui.listRow(label, helper, trailing = sw, chevron = false) {- sw.isChecked = !sw.isChecked- changed(sw.isChecked)- row.stateDescription = if (sw.isChecked) L("已开启") else L("已关闭")- }- row.stateDescription = if (on) L("已开启") else L("已关闭")- row.accessibilityDelegate = object : View.AccessibilityDelegate() {- override fun onInitializeAccessibilityNodeInfo(host: View, info: android.view.accessibility.AccessibilityNodeInfo) {- super.onInitializeAccessibilityNodeInfo(host, info)- info.className = "android.widget.Switch"; info.isCheckable = true; info.isChecked = sw.isChecked- }- }- return row- }-/// A sample of how my words will sound to them (the Mac's 试一句), in English.private fun tryVoice() {val app = cicadadiff --git a/android/app/src/main/kotlin/com/wquguru/cicada/Ui.kt b/android/app/src/main/kotlin/com/wquguru/cicada/Ui.ktindex 36d949e..fc5c587 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/Ui.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/Ui.kt@@ -107,6 +107,34 @@ class Ui(val context: Context) {setPadding(dp(padding), dp(padding), dp(padding), dp(padding))}+ /// A row with a switch; the whole row toggles it.+ fun switchRow(label: String, helper: String, on: Boolean, changed: (Boolean) -> Unit): LinearLayout {+ val sw = android.widget.Switch(context).apply {+ isChecked = on+ val states = arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf())+ thumbTintList = ColorStateList(states, intArrayOf(android.graphics.Color.WHITE, Palette.secondary))+ trackTintList = ColorStateList(states, intArrayOf(Palette.ink, Palette.outline))+ // The framework track is drawn faded; SRC paints the tint at full strength.+ trackTintMode = android.graphics.PorterDuff.Mode.SRC+ importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO+ isClickable = false+ }+ lateinit var row: LinearLayout+ row = listRow(label, helper, trailing = sw, chevron = false) {+ sw.isChecked = !sw.isChecked+ changed(sw.isChecked)+ row.stateDescription = if (sw.isChecked) cicada.Strings.L("已开启") else cicada.Strings.L("已关闭")+ }+ row.stateDescription = if (on) cicada.Strings.L("已开启") else cicada.Strings.L("已关闭")+ row.accessibilityDelegate = object : View.AccessibilityDelegate() {+ override fun onInitializeAccessibilityNodeInfo(host: View, info: android.view.accessibility.AccessibilityNodeInfo) {+ super.onInitializeAccessibilityNodeInfo(host, info)+ info.className = "android.widget.Switch"; info.isCheckable = true; info.isChecked = sw.isChecked+ }+ }+ return row+ }+/// A white group of rows with thin dividers (lists, settings).fun group(rows: List<View>, radius: Int = 22) = LinearLayout(context).apply {orientation = LinearLayout.VERTICALdiff --git a/android/cli/src/main/kotlin/cicada/cli/ProviderTests.kt b/android/cli/src/main/kotlin/cicada/cli/ProviderTests.ktindex 0878dc7..1abb5a8 100644--- a/android/cli/src/main/kotlin/cicada/cli/ProviderTests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/ProviderTests.kt@@ -12,6 +12,10 @@ object ProviderTests {"aiChosenModelsAndACustomService" to ::chosenAndCustom,"aiCustomAddress" to ::customAddress,"aiSettingsKeepTheServiceAcrossARestart" to ::settingsRoundTrip,+ "aiCustomOnlyActsOnTheCustomServiceAlone" to ::customOnlySetting,+ "aiCustomOnlyPartialLinesNeverGoToGoogle" to ::customOnlyDrafts,+ "aiCustomOnlySentencesGoToTheServiceAlone" to ::customOnlySentences,+ "aiCustomOnlyFlippingItForgetsTheGoogleBackoff" to ::customOnlyClearsBackoff,"aiEachServiceTurnsThinkingOffItsOwnWay" to ::shape,"aiAudioGoesInTheFormEachModelTakes" to ::audioPart,"aiCatalogListsChatModelsAndThoseThatHear" to ::catalog,@@ -154,6 +158,11 @@ object ProviderTests {check(AICheck.Speed(6.4, false).slow, "slow")val c = AICheck(at = 1).pass(AICheck.StepID.Text, 4.2).copy(translate = AICheck.Speed(4.2, true))check(c.slow && c.slowLine()!!.contains("4.2"), "the slow line says how long")+ check("Google" in c.slowLine()!!, "Google stands in for a slow sentence")+ val off = c.slowLine(googleOff = true)!!+ check("4.2" in off && "Google" !in off && "不等它了" in off, "语音和文字只发给你的服务: no word of Google")+ val plain = AICheck(at = 1).pass(AICheck.StepID.Text, 6.4).copy(translate = AICheck.Speed(6.4, false)).slowLine(googleOff = true)!!+ check("Google" !in plain && "更小的模型" in plain, "a slow model that doesn't think, without Google")check(AICheck(at = 1).pass(AICheck.StepID.Text, 0.5).copy(translate = AICheck.Speed(0.5, false)).slowLine() == null, "nothing to say")check("translate=4.2s thinks" in c.summary, "in the summary (the settings repaint on it)")}@@ -255,13 +264,72 @@ object ProviderTests {fun settingsRoundTrip() {try {- AppSettings(aiProvider = "zenmux", aiHearModels = mutableMapOf("zenmux" to "bytedance/doubao-seed-2.0-mini")).save()+ AppSettings(aiProvider = "zenmux", aiHearModels = mutableMapOf("zenmux" to "bytedance/doubao-seed-2.0-mini"), aiCustomOnly = true).save()val back = AppSettings.load()equal("zenmux", back.aiProvider, "service")equal("bytedance/doubao-seed-2.0-mini", back.aiConfig().hearModel, "hear model")+ check(back.aiCustomOnly, "语音和文字只发给你的服务 kept")} finally { Paths.settings.delete() }}+ // MARK: 语音和文字只发给你的服务 (issue #15; the Mac's GoogleOffTests)++ private fun custom(on: Boolean = true) = AppSettings(aiProvider = "custom", aiCustomBase = "http://127.0.0.1:8000/v1",+ aiModels = mutableMapOf("custom" to "qwen3:14b"), aiHearModels = mutableMapOf("custom" to "qwen3-omni"), aiCustomOnly = on)++ private fun google(url: String) = "translate.googleapis.com" in url+ private val googleReply = Transport.Response(200, "[[[\"我们周五发布\",\"We ship on Friday\"]]]")++ fun customOnlySetting() {+ check(custom().customOnly, "in effect with the custom service")+ check(!custom(on = false).customOnly, "off")+ val other = custom().apply { aiProvider = "zenmux" }+ check(other.aiCustomOnly && !other.customOnly, "kept, but inert, for another service")+ }++ fun customOnlyDrafts() {+ val fake = Fake({ url, _ -> if (google(url)) googleReply else reply("我们周五发布") })+ val t = Translator(client(fake, custom()), fake)+ t.googleOff = true+ for (i in 0 until 3) equal(null, t.translate("We ship on Friday", "en", "zh-CN", Translator.Kind.Draft), "draft $i shows the original")+ equal(0, fake.sent.size, "partial text goes nowhere: not Google, never the AI service")+ // Off, partial text still never reaches the AI service: only Google.+ t.googleOff = false+ equal("我们周五发布", t.translate("We ship on Friday", "en", "zh-CN", Translator.Kind.Draft), "draft via Google when off")+ check(fake.sent.all { google(it.first) }, "a draft never goes to the AI service")+ }++ fun customOnlySentences() {+ var up = true+ val fake = Fake({ url, _ -> if (google(url)) googleReply else if (up) reply("我们周五发布") else Transport.Response(500, "{}") })+ val t = Translator(client(fake, custom()), fake)+ t.googleOff = true+ equal("我们周五发布", t.translate("We ship on Friday", "en", "zh-CN", Translator.Kind.Sentence), "the service translates")+ check(!t.sentencesUntranslated, "translated")+ up = false+ equal(null, t.translate("We ship on Friday", "en", "zh-CN", Translator.Kind.Sentence), "service down: the original only")+ check(t.sentencesUntranslated, "says the sentence went untranslated")+ check(fake.sent.none { google(it.first) }, "Google is never asked")+ // Off again, Google stands in as before.+ t.googleOff = false+ check(!t.sentencesUntranslated, "flipping forgets the last sentence")+ equal("我们周五发布", t.translate("We ship on Friday", "en", "zh-CN", Translator.Kind.Sentence), "Google stands in when off")+ check(fake.sent.any { google(it.first) }, "Google asked when off")+ }++ fun customOnlyClearsBackoff() {+ var googleUp = false+ val fake = Fake({ url, _ -> if (google(url)) (if (googleUp) googleReply else Transport.Response(429, "")) else reply("") })+ val t = Translator(client(fake, custom(on = false), key = null), fake)+ equal(null, t.translate("Hello", "en", "zh-CN", Translator.Kind.Draft), "Google busy")+ googleUp = true+ val asked = fake.sent.size+ equal(null, t.translate("Hello", "en", "zh-CN", Translator.Kind.Draft), "backing off")+ equal(asked, fake.sent.size, "not asked while backing off")+ t.googleOff = true; t.googleOff = false+ equal("我们周五发布", t.translate("Hello", "en", "zh-CN", Translator.Kind.Draft), "the backoff went with the flip")+ }+fun shape() {for ((id, field, value) in listOf(Triple("ling", "thinking", mapOf("type" to "disabled")),Triple("zenmux", "reasoning", mapOf("enabled" to false)),diff --git a/android/core/src/main/kotlin/cicada/AICheck.kt b/android/core/src/main/kotlin/cicada/AICheck.ktindex 2d8275d..0f73534 100644--- a/android/core/src/main/kotlin/cicada/AICheck.kt+++ b/android/core/src/main/kotlin/cicada/AICheck.kt@@ -156,9 +156,12 @@ data class AICheck(}/// Why translations are slow, and what to do (a custom service).- fun slowLine(): String? {+ /// `googleOff`: 语音和文字只发给你的服务 is on, so a sentence that takes too long isn't handed to Google.+ fun slowLine(googleOff: Boolean = false): String? {val t = translate?.takeIf { slow } ?: return nullval secs = String.format(Strings.locale, "%.1f", t.seconds)+ if (googleOff) return if (t.thinks) LF("这个模型先思考再回答,翻一句要 %@ 秒,超过 6 秒这句就不等它了。在服务端关掉思考,或换一个不思考的模型。", secs)+ else LF("翻一句要 %@ 秒,超过 6 秒这句就不等它了。换一个更小的模型会快一些。", secs)return if (t.thinks) LF("这个模型先思考再回答,翻一句要 %@ 秒,超过 6 秒会改用 Google。在服务端关掉思考,或换一个不思考的模型。", secs)else LF("翻一句要 %@ 秒,超过 6 秒会改用 Google。换一个更小的模型会快一些。", secs)}diff --git a/android/core/src/main/kotlin/cicada/ListenEngine.kt b/android/core/src/main/kotlin/cicada/ListenEngine.ktindex e5a028c..58df4d2 100644--- a/android/core/src/main/kotlin/cicada/ListenEngine.kt+++ b/android/core/src/main/kotlin/cicada/ListenEngine.kt@@ -229,7 +229,7 @@ class ListenEngine(if (heard == null) { sayProblem = Strings.L("没听清,再说一次"); return }if (PressSpeech.filler(heard.original)) { Log.d("listen: only a filler heard, not said"); return }var dst = heard.translation- if (dst == null && !Languages.same(heard.lang, their)) dst = translator.translate(heard.original, heard.lang, their, Translator.Kind.Sentence)+ if (dst == null && !Languages.same(heard.lang, their)) dst = translator.translate(heard.original, heard.lang, their, Translator.Kind.Speak)val sameLanguage = Languages.same(heard.lang, their)val probe = TranscriptLine(speaker = "me", src = heard.original, dst = dst, srcLang = heard.lang, dstLang = their)val text = speakable(probe)@@ -358,6 +358,8 @@ class ListenEngine(lastEnd = seg.start + seg.seconds}val copy = synchronized(gate) { line.copy() }+ // A line the hear model translated itself: finished sentences are being translated again.+ if (!joined && heard.translation != null) translator.sentencesUntranslated = falseif (joined) store.replace(id, copy) else store.append(id, copy)onWords?.invoke()@@ -366,6 +368,8 @@ class ListenEngine(val src = line.srcpool.execute {val dst = translator.translate(src, line.srcLang, target, Translator.Kind.Sentence)+ // Untranslated: the live screens may now say why (translator.sentencesUntranslated).+ if (dst == null) { changed(); return@execute }val updated = synchronized(gate) {if (dst == null || line.src != src) return@executeline.dst = dstdiff --git a/android/core/src/main/kotlin/cicada/Settings.kt b/android/core/src/main/kotlin/cicada/Settings.ktindex fd4984d..b70351a 100644--- a/android/core/src/main/kotlin/cicada/Settings.kt+++ b/android/core/src/main/kotlin/cicada/Settings.kt@@ -21,6 +21,9 @@ class AppSettings(var aiCustomVoice: String = "",/// The custom service's hear model's own address (the Mac's aiCustomHearBase); empty: the text model's.var aiCustomHearBase: String = "",+ /// 语音和文字只发给你的服务: with the custom service, Google Translate is never asked. Kept when+ /// another service is picked, but only acts on the custom one (`customOnly`).+ var aiCustomOnly: Boolean = false,/// "notes" (live notes, default) or "subtitles" (the subtitle bar), for the floating window.var view: String = "notes",/// 共享屏幕时让对方看到: let the floating window show up in screenshots and screen recording.@@ -60,12 +63,15 @@ class AppSettings(/// The AI service in use, its address and models (what LingClient calls with).fun aiConfig(): AIConfig = Providers.configFrom(this)+ /// 语音和文字只发给你的服务 in effect: on, and the custom service in use.+ val customOnly: Boolean get() = aiCustomOnly && aiProvider == "custom"+fun toJson(): Map<String, Any?> = mapOf("target" to target, "notesLanguage" to notesLanguage, "model" to model, "view" to view,"aiProvider" to aiProvider, "aiModels" to aiModels.toSortedMap(), "aiHearModels" to aiHearModels.toSortedMap(),"aiVoiceModels" to aiVoiceModels.toSortedMap(), "aiCustomBase" to aiCustomBase,"aiCustomVoiceBase" to aiCustomVoiceBase, "aiCustomVoice" to aiCustomVoice,- "aiCustomHearBase" to aiCustomHearBase,+ "aiCustomHearBase" to aiCustomHearBase, "aiCustomOnly" to aiCustomOnly,"showInCapture" to showInCapture, "onboarded" to onboarded, "uiLanguage" to uiLanguage,"source" to source, "overlay" to overlay, "silenceEnd" to silenceEnd, "silenceMinutes" to silenceMinutes,"speakerVoices" to speakerVoices, "recordAudio" to recordAudio, "speakBack" to speakBack,@@ -97,7 +103,7 @@ class AppSettings(aiModels = strings(o["aiModels"]), aiHearModels = strings(o["aiHearModels"]),aiVoiceModels = strings(o["aiVoiceModels"]), aiCustomBase = o["aiCustomBase"].str() ?: "",aiCustomVoiceBase = o["aiCustomVoiceBase"].str() ?: "", aiCustomVoice = o["aiCustomVoice"].str() ?: "",- aiCustomHearBase = o["aiCustomHearBase"].str() ?: "",+ aiCustomHearBase = o["aiCustomHearBase"].str() ?: "", aiCustomOnly = o["aiCustomOnly"].bool() ?: false,showInCapture = o["showInCapture"].bool() ?: false, onboarded = o["onboarded"].bool() ?: false,uiLanguage = o["uiLanguage"].str() ?: d.uiLanguage, source = o["source"].str() ?: d.source,overlay = o["overlay"].bool() ?: true,diff --git a/android/core/src/main/kotlin/cicada/Translator.kt b/android/core/src/main/kotlin/cicada/Translator.ktindex 35a60c3..1e64e22 100644--- a/android/core/src/main/kotlin/cicada/Translator.kt+++ b/android/core/src/main/kotlin/cicada/Translator.kt@@ -12,6 +12,21 @@ data class Heard(val lang: String, val original: String, val translation: Stringclass Translator(private val ling: LingClient, private val transport: Transport = UrlTransport) {@Volatile private var googleBackoffUntil = 0L+ /// 语音和文字只发给你的服务 (the Mac's googleOff; set by the app for the custom service only):+ /// Google is never asked, so the text stays with the user's service. Flipping it forgets a+ /// Google backoff and what the last sentence did.+ @Volatile var googleOff = false+ set(value) {+ if (value == field) return+ field = value+ googleBackoffUntil = 0L+ sentencesUntranslated = false+ }++ /// The last finished sentence sent here came back untranslated (the Mac's+ /// TranslationHealth.sentencesUntranslated): with googleOff, the user's service can't be reached.+ @Volatile var sentencesUntranslated = false+/// Names and terms the notes have settled on, e.g. "江充 (…; misheard as 江松)".@Volatile var glossary: () -> List<String> = { emptyList() }@@ -30,7 +45,8 @@ class Translator(private val ling: LingClient, private val transport: Transport// MARK: Text- enum class Kind { Draft, Sentence }+ /// Speak: my words for 我说 (the Mac's .speak), which don't count as the meeting's subtitles.+ enum class Kind { Draft, Sentence, Speak }@Volatile private var lastUnreachableTry = 0L@@ -45,9 +61,17 @@ class Translator(private val ling: LingClient, private val transport: Transportreturn true}- /// The AI service (finished sentences only) → Google. Null when both fail.+ /// The AI service (finished sentences only) → Google (never with googleOff). Null when both fail.fun translate(text: String, source: String, target: String, kind: Kind): String? {if (source == target) return text+ // Partial text only ever goes to Google: left out, it shows the original until the sentence ends.+ if (kind == Kind.Draft && googleOff) return null+ val out = chain(text, source, target, kind)+ if (kind == Kind.Sentence) sentencesUntranslated = out == null+ return out+ }++ private fun chain(text: String, source: String, target: String, kind: Kind): String? {if (kind != Kind.Draft && ling.usable && lingWorthTrying()) {try {val from = if (source == "auto") "the spoken language" else Languages.englishName(source)@@ -60,7 +84,7 @@ class Translator(private val ling: LingClient, private val transport: TransportcleanTranslation(out, target)?.let { return it }} catch (e: LingException) { Log.d("translate ling failed: ${e.message}") }}- if (System.currentTimeMillis() < googleBackoffUntil) return null+ if (googleOff || System.currentTimeMillis() < googleBackoffUntil) return nulltry {val url = "https://translate.googleapis.com/translate_a/single?client=gtx" +"&sl=${enc(source)}&tl=${enc(target)}&dt=t&q=${enc(text)}"