知了 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(linux): when the AI service keeps answering a meeting's audio with a server error, the notes window says so instead of leaving the subtitles silently empty
wquguru38464e26fb20
diff --git a/linux/cicada/app/notes_window.py b/linux/cicada/app/notes_window.pyindex 8f51340..19159b5 100644--- a/linux/cicada/app/notes_window.py+++ b/linux/cicada/app/notes_window.py@@ -807,8 +807,10 @@ class NotesWindow(Gtk.Window):if listen.listening:hearing = listen.pending > 0 or listen.level >= 0.01room = listen.source_kind == "room"+ # Busy or erring before anything was heard: said here, or it reads as a quiet meeting.+ trouble = listen.problem if kind == "busy" else Noneself._state_card(box, "audio-input-microphone-symbolic" if room else "audio-speakers-symbolic", "grey",- L("正在识别…") if hearing else L("等有人说话"),+ trouble or (L("正在识别…") if hearing else L("等有人说话")),L("正在用麦克风听会议室,有人说话后约 3 秒出字幕") if roomelse L("正在听电脑播放的声音,有声音后约 3 秒出字幕"))else:diff --git a/linux/cicada/core/listen.py b/linux/cicada/core/listen.pyindex f4a2c5c..790c58f 100644--- a/linux/cicada/core/listen.py+++ b/linux/cicada/core/listen.py@@ -79,6 +79,7 @@ class ListenEngine:self.problem = None # the last error worth showing, cleared by the next good reply# What kind of problem, for a state the UI can draw: "key", "busy", "network", "source".self.problem_kind = None+ self._server_errors = 0 # stretches in a row the service answered with a 5xxself.loudness = None # SpeakEngine's LoudnessLog: when the system audio was loud (the echo check)# 说话人识别: a voiceprint per segment on its own thread while Ming hears it, labelled in order.self.speakers = None # speakers.Tagger, set by the app@@ -189,6 +190,7 @@ class ListenEngine:self._in_flight.clear()self._line_count = 0self.problem = self.problem_kind = None+ self._server_errors = 0self.notes.begin(session.id)if self.speakers is not None:self.speakers.reset()@@ -376,9 +378,17 @@ class ListenEngine:started = time.monotonic()try:heard = self.translator.hear(wav, seg.asked, lang)+ with self._gate:+ self._server_errors = 0self.problem = self.problem_kind = Noneexcept LingError as e:- self.problem_kind, self.problem = problem(e, self.ling.provider.name, self.ling.config().hear_model)+ # A server error (a gateway's 502) is said from the third in a row, as on the Mac: one+ # isn't worth a banner, but a meeting with no subtitles and no reason is worse.+ with self._gate:+ self._server_errors = self._server_errors + 1 if server_error(e) else 0+ shown = not server_error(e) or self._server_errors >= SERVER_ERRORS_SHOWN+ if shown:+ self.problem_kind, self.problem = problem(e, self.ling.provider.name, self.ling.config().hear_model)Log.d("listen: segment %d failed %s" % (seg.index, e))except Exception as e: # noqa: BLE001Log.d("listen: segment %d failed %s" % (seg.index, type(e).__name__))@@ -561,14 +571,25 @@ def join(a: str, b: str, lang: str) -> str:return a.rstrip() + b.lstrip() if cjk else a.rstrip() + " " + b.lstrip()+# Server errors in a row before listening says so (ListenEngine.swift's cloudFailures).+SERVER_ERRORS_SHOWN = 3+++def server_error(e: LingError) -> bool:+ return e.kind == LingError.HTTP and e.status >= 500++def problem(e: LingError, service: str, hear_model: str = ""):"""(kind, what to say) for a stretch that couldn't be heard. Ling keeps its own words; anotherservice is named. A hear model that refuses audio (400 / 404 / 415 / 422) is a key-like problem:- 设置 fixes it, in the words of the settings' 听对方 step."""+ 设置 fixes it, in the words of the settings' 听对方 step. A 5xx is the service's own trouble."""L, LF = strings.L, strings.LFling = service == "Ling"if e.kind == LingError.HTTP and e.status in (400, 404, 415, 422) and not ling:return "key", LF("%@ 听不了声音。", hear_model or service)+ # It answered, with an error: like busy, it passes by itself (AICheck's serverError words).+ if server_error(e):+ return "busy", LF("%@ 暂时出错(HTTP %lld),稍后再试。", service, e.status)kind = {LingError.NO_KEY: "key", LingError.INVALID_KEY: "key", LingError.RATE_LIMITED: "busy",LingError.NETWORK: "network", LingError.TIMEOUT: "network"}.get(e.kind)if ling:diff --git a/linux/tests/test_core.py b/linux/tests/test_core.pyindex c74a73f..e5f4e1d 100644--- a/linux/tests/test_core.py+++ b/linux/tests/test_core.py@@ -984,6 +984,63 @@ class Listening(Base):self.assertEqual("h1-1", s.lines[0].id)self.assertIsNotNone(s.endedAt)+ def test_server_errors_in_a_row_are_said_and_clear_on_the_next_line(self):+ # A gateway answering 502 to every stretch: no subtitles, so from the third in a row the notes+ # window says the service is erring (not the network); the next stretch heard clears it.+ heard = []+ seen = []++ def respond(body):+ if "Ming-3.0-audio-flash" in body:+ heard.append(1)+ if len(heard) <= 3:+ return Response(502, "Bad Gateway")+ return reply("LANG: en\nORIGINAL: Back again.\nTRANSLATION: 回来了。")+ return reply("{}")+ LingClient.spacing = 0.05+ ling = client(Fake(respond))+ store = SessionStore()+ engine = ListenEngine(ling, Translator(ling), store, NotesEngine(ling, store), AppSettings(target="zh-CN"))+ engine.on_change(lambda: seen.append(engine.problem))+ # Four times real time: each reply is back before the next stretch goes, as in a meeting.+ src = PcmAudioSource(lambda: concat(*[x for _ in range(4) for x in (tone(1.0), silence(3.0))]), speed=4)+ ended = threading.Event()+ src.on_ended = lambda why: ended.set()+ engine.start(src, "file")+ ended.wait(15)+ time.sleep(0.3)+ engine.stop()+ self.assertEqual(4, len(heard))+ said = [p for p in seen if p]+ self.assertTrue(said, "three 502s in a row are said")+ self.assertEqual({"Ling 暂时出错(HTTP 502),稍后再试。"}, set(said))+ self.assertIsNone(engine.problem, "the next stretch heard clears it")+ self.assertEqual(["Back again."], [l.src for l in store.get(engine.session_id).lines])++ def test_one_server_error_is_not_said(self):+ calls = []++ def respond(body):+ if "Ming-3.0-audio-flash" in body:+ calls.append(1)+ return Response(502, "") if len(calls) <= 2 else reply("LANG: en\nORIGINAL: Fine.\nTRANSLATION: 好。")+ return reply("{}")+ LingClient.spacing = 0.05+ ling = client(Fake(respond))+ store = SessionStore()+ engine = ListenEngine(ling, Translator(ling), store, NotesEngine(ling, store), AppSettings(target="zh-CN"))+ seen = []+ engine.on_change(lambda: seen.append(engine.problem))+ src = PcmAudioSource(lambda: concat(tone(1.0), silence(3.0), tone(1.0), silence(3.0)), speed=4)+ ended = threading.Event()+ src.on_ended = lambda why: ended.set()+ engine.start(src, "file")+ ended.wait(10)+ time.sleep(0.3)+ engine.stop()+ self.assertEqual(2, len(calls))+ self.assertEqual([], [p for p in seen if p], "two blips: nothing to say yet")+def test_follow_system_translates_my_own_language_into_the_next(self):# They speak Chinese, my language: the first stretch was asked for Chinese (nothing heard# yet), so its translation is dropped for the text translation; the next is asked for English.diff --git a/linux/tests/test_providers.py b/linux/tests/test_providers.pyindex 52ffc6c..509d164 100644--- a/linux/tests/test_providers.py+++ b/linux/tests/test_providers.py@@ -263,6 +263,9 @@ class Words(Base):self.assertIn("ZenMux", problem(LingError(LingError.NETWORK), "ZenMux")[1])self.assertEqual(("network", "连不上 Ling"), problem(LingError(LingError.TIMEOUT), "Ling"))self.assertIsNone(problem(LingError(LingError.HTTP, 400), "Ling")[0])+ # A gateway's 502 in front of the server: the service's trouble, not the network or the key.+ self.assertEqual(("busy", "ZenMux 暂时出错(HTTP 502),稍后再试。"), problem(LingError(LingError.HTTP, 502), "ZenMux"))+ self.assertEqual(("busy", "Ling 暂时出错(HTTP 503),稍后再试。"), problem(LingError(LingError.HTTP, 503), "Ling"))def test_final_notes_keep_retrying_for_about_a_minute(self):from cicada.core.ling import NOTES, retry_waits