知了 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
fix(android): when your AI service can't be reached, lines it would translate go straight to Google instead of waiting seconds for it each time
wquguru7ad8fd53e3ed
diff --git a/android/cli/src/main/kotlin/cicada/cli/Tests.kt b/android/cli/src/main/kotlin/cicada/cli/Tests.ktindex a3cc894..caef6b9 100644--- a/android/cli/src/main/kotlin/cicada/cli/Tests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/Tests.kt@@ -31,6 +31,7 @@ object Tests {"theLiveMeetingCantBeDeleted" to ::theLiveMeetingCantBeDeleted,"followSystemLikeTheMac" to ::followSystemLikeTheMac,"anUntranslatedSentenceIsNeitherSentNorRecorded" to ::anUntranslatedSentenceIsNeitherSentNorRecorded,+ "anUnreachableServiceIsTriedOncePer15s" to ::anUnreachableServiceIsTriedOncePer15s,"storeSavesAndDropsEmptyMeetings" to ::storeSavesAndDropsEmptyMeetings,"closesInterruptedMeetings" to ::closesInterruptedMeetings,"exportsLikeTheMac" to ::exportsLikeTheMac,@@ -1003,6 +1004,27 @@ object Tests {} finally { LingClient.spacing = old }}+ fun anUnreachableServiceIsTriedOncePer15s() {+ // The service doesn't answer; Google does.+ val fake = Fake { body -> if (body.contains("Subtitle:")) Transport.Response(500, "") else Transport.Response(200, "[[[\"你好\",\"Hello\"]]]") }+ val old = LingClient.spacing+ LingClient.spacing = 0.0+ try {+ val ling = client(fake)+ val translator = Translator(ling, fake)+ fun lingCalls() = synchronized(fake.calls) { fake.calls.count { it.second.contains("Subtitle:") } }+ translator.translate("Hello.", "en", "zh-CN", Translator.Kind.Sentence)+ equal(1, lingCalls(), "tried while the check says nothing")+ ling.simulateCheck = AICheck.Reason.Unreachable+ ling.check()+ equal(AICheck.Reason.Unreachable, ling.aiCheck.failure?.reason, "the check says unreachable")+ equal("你好", translator.translate("Hello.", "en", "zh-CN", Translator.Kind.Sentence), "Google")+ equal(2, lingCalls(), "one line still goes to the service")+ equal("你好", translator.translate("Hello again.", "en", "zh-CN", Translator.Kind.Sentence), "Google at once")+ equal(2, lingCalls(), "the next lines within 15 s don't wait for it")+ } finally { LingClient.spacing = old }+ }+fun anUntranslatedSentenceIsNeitherSentNorRecorded() {// Ming hears me but returns no translation, and Ling and Google both fail.val fake = Fake { body ->diff --git a/android/core/src/main/kotlin/cicada/Translator.kt b/android/core/src/main/kotlin/cicada/Translator.ktindex f2c260e..35a60c3 100644--- a/android/core/src/main/kotlin/cicada/Translator.kt+++ b/android/core/src/main/kotlin/cicada/Translator.kt@@ -32,10 +32,23 @@ class Translator(private val ling: LingClient, private val transport: Transportenum class Kind { Draft, Sentence }+ @Volatile private var lastUnreachableTry = 0L++ /// A service that answers nothing costs a line its timeout before Google gets it (a hear model+ /// on its own server still hearing, 我说's fallback). While the check says unreachable, one line+ /// in 15 s still goes to it, so a service that is back is noticed without waiting for a check.+ @Synchronized private fun lingWorthTrying(): Boolean {+ if (ling.aiCheck.failure?.reason != AICheck.Reason.Unreachable) return true+ val now = System.currentTimeMillis()+ if (now - lastUnreachableTry < 15_000) return false+ lastUnreachableTry = now+ return true+ }+/// The AI service (finished sentences only) → Google. Null when both fail.fun translate(text: String, source: String, target: String, kind: Kind): String? {if (source == target) return text- if (kind != Kind.Draft && ling.usable) {+ if (kind != Kind.Draft && ling.usable && lingWorthTrying()) {try {val from = if (source == "auto") "the spoken language" else Languages.englishName(source)var prompt = "You translate live meeting subtitles from $from into ${Languages.englishName(target)}.\n" +