知了 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: what you say with the talk key while the other side talks is no longer dropped as silence
wquguru3c6bb56db093
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.stringsindex 556d17d..499b2de 100644--- a/Resources/en.lproj/Localizable.strings+++ b/Resources/en.lproj/Localizable.strings@@ -866,6 +866,7 @@"没有虚拟麦克风 · 没有说出去" = "No virtual microphone · nothing was said";"这句没翻译成 · 没有说出去" = "This line wasn't translated · nothing was said";"对方在说话时说的,没有说出去" = "Said while they were talking, so not sent";+"没听清你说的,没有说出去" = "Didn't catch what you said, so not sent";/* SpeakTest */"语音识别还没准备好,请稍后再试" = "Speech recognition isn't ready yet; try again shortly";diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.stringsindex efaeea4..367857f 100644--- a/Resources/ja.lproj/Localizable.strings+++ b/Resources/ja.lproj/Localizable.strings@@ -866,6 +866,7 @@"没有虚拟麦克风 · 没有说出去" = "仮想マイクがありません · 発話していません";"这句没翻译成 · 没有说出去" = "この文は翻訳できず · 発話していません";"对方在说话时说的,没有说出去" = "相手が話している間の発言なので、送っていません";+"没听清你说的,没有说出去" = "聞き取れなかったので、送っていません";/* SpeakTest */"语音识别还没准备好,请稍后再试" = "音声認識の準備がまだです。少し待ってから再試行してください";diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.stringsindex 8e564c1..d5f40f2 100644--- a/Resources/ko.lproj/Localizable.strings+++ b/Resources/ko.lproj/Localizable.strings@@ -866,6 +866,7 @@"没有虚拟麦克风 · 没有说出去" = "가상 마이크 없음 · 말하지 않았습니다";"这句没翻译成 · 没有说出去" = "이 문장은 번역되지 않음 · 말하지 않았습니다";"对方在说话时说的,没有说出去" = "상대방이 말하는 중이라 보내지 않았어요";+"没听清你说的,没有说出去" = "잘 들리지 않아 보내지 않았어요";/* SpeakTest */"语音识别还没准备好,请稍后再试" = "음성 인식이 아직 준비되지 않았습니다. 잠시 후 다시 시도하세요";diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.stringsindex b0e977c..c3c0549 100644--- a/Resources/zh-Hans.lproj/Localizable.strings+++ b/Resources/zh-Hans.lproj/Localizable.strings@@ -866,6 +866,7 @@"没有虚拟麦克风 · 没有说出去" = "没有虚拟麦克风 · 没有说出去";"这句没翻译成 · 没有说出去" = "这句没翻译成 · 没有说出去";"对方在说话时说的,没有说出去" = "对方在说话时说的,没有说出去";+"没听清你说的,没有说出去" = "没听清你说的,没有说出去";/* SpeakTest */"语音识别还没准备好,请稍后再试" = "语音识别还没准备好,请稍后再试";diff --git a/Sources/Cicada/SpeakEngine.swift b/Sources/Cicada/SpeakEngine.swiftindex 36c84c1..a272d76 100644--- a/Sources/Cicada/SpeakEngine.swift+++ b/Sources/Cicada/SpeakEngine.swift@@ -285,7 +285,11 @@ final class SpeakEngine {// MARK: Push to talkfunc pressBegan() {- guard settings.speakEnabled || probe != nil, phase == .idle || phase == .speaking else { return }+ guard settings.speakEnabled || probe != nil else { return }+ guard phase == .idle || phase == .speaking else {+ debugLog("speak: press while \(phase) ignored")+ return+ }if probe == nil {// 只听会议室 (older macOS): everyone is at the table and hears you; there is no call to speak into.if settings.listensToRoom { onNotice?(L("同声传译是给线上会议用的")); return }@@ -439,7 +443,9 @@ final class SpeakEngine {defer { pressSamples = [] }return pressSamples}- let spoken = PressSpeech.spoken(samples)+ let measure = PressSpeech.measure(samples)+ let spoken = measure.spoken+ debugLog("speak: press of \(String(format: "%.1f", Double(samples.count) / 16_000)) s, \(measure.summary)")guard samples.count >= 16_000 / 4 else { return (nil, spoken) }var d = Data()func u32(_ v: UInt32) { withUnsafeBytes(of: v.littleEndian) { d.append(contentsOf: $0) } }@@ -482,16 +488,10 @@ final class SpeakEngine {releasedAt = nillet (wav, spoken) = takePressWAV()probe?.released = released- // A press nobody spoke in: Ming hears 嗯 in the room's hush and the meeting would hear "Hmm."- if wav != nil, !spoken, probe == nil {- debugLog("speak: nothing said in the press, nothing sent")- Task { _ = await u.text.value }- finals = []- volatile = ""- phase = .idle- onLive?(.idle, "", "")- return- }+ // A press too quiet for PressSpeech: nobody spoke (Ming would hear 嗯 in the room's hush and+ // the meeting "Hmm."), or a voice from across the desk under a line the meeting's leftover+ // echo raised. The on-device recognizer decides which once it has finished.+ let quiet = wav != nil && !spoken && probe == nil// The meeting playing through most of a press on the plain mic: don't send its echo back.if pressPlain, probe == nil, let share = playedShare?(pressStarted, released), share > Self.echoShare {debugLog(String(format: "speak: the Mac played through %.0f%% of the press (echo), nothing sent", share * 100))@@ -511,16 +511,33 @@ final class SpeakEngine {let route = route?(to) ?? .system(nil)if case .stream = route, let device = outputDevice() { configureOutput(format: Self.streamFormat, device: device); try? out.start() }// Ming hears the audio while the on-device transcriber finishes, so its fallback costs nothing.- let ming = Task { () -> (original: String, translation: String)? in+ // A quiet press waits for the transcriber first: most are nobody speaking, not worth a call.+ let interpret = self.interpret+ let startMing = { Task { () -> (original: String, translation: String)? inguard let wav, let interpret else { return nil }return await interpret(wav, from, to, trace)- }+ } }+ let early = quiet ? nil : startMing()Task {var text = await u.text.valuefinals = []volatile = ""+ if quiet {+ // Through echo cancellation the meeting's words don't reach the recognizer (none of+ // 43 at 60 % on the speakers), so a sentence it heard is you. The plain mic has no+ // such guarantee.+ // A tap is too short for a sentence: a 0.3 s one with the meeting's echo around+ // came back as two characters and went out.+ guard !pressPlain, released.timeIntervalSince(pressStarted) >= 1, !text.isEmpty, !PressSpeech.filler(text) else {+ debugLog("speak: nothing said in the press, nothing sent")+ phase = .idle+ onLive?(.idle, "", L("没听清你说的,没有说出去"))+ return+ }+ debugLog("speak: quiet press, but the on-device recognizer heard \(text.count) chars: sending")+ }if !text.isEmpty { onLive?(.translating, text, "") }- let heard = await ming.value+ let heard = await (early ?? startMing()).valuedebugLog("speak: on-device heard \(text.count) chars, Ming \(heard.map { "\($0.original.count)" } ?? "-") chars")if let heard { text = heard.original }// Ming answers recognition and translation together: its whole call counts as `recognize`.@@ -837,8 +854,23 @@ enum PressSpeech {}static let fillers: Set<String> = ["嗯", "啊", "呃", "哦", "唔", "额", "噢", "哎", "um", "uh", "hmm", "hm", "mm", "mhm", "ah", "oh", "er", "えー", "あの", "음", "어"]- static func spoken(_ samples: [Int16]) -> Bool {- guard samples.count >= frame else { return false }+ /// What the check saw: seconds over the line, the press's quiet and the line (RMS, 0–1).+ struct Measure: Equatable {+ var voiced: Double+ var floor: Float+ var line: Float+ var spoken: Bool { voiced >= PressSpeech.needed }+ /// For the log: a line held at its −36 dBFS cap means the press's quiet was loud.+ var summary: String {+ func db(_ v: Float) -> String { v > 0 ? String(format: "%.0f", 20 * log10(v)) : "-inf" }+ return "voiced \(String(format: "%.2f", voiced)) s, quiet \(db(floor)) dBFS, line \(db(line)) dBFS"+ }+ }++ static func spoken(_ samples: [Int16]) -> Bool { measure(samples).spoken }++ static func measure(_ samples: [Int16]) -> Measure {+ guard samples.count >= frame else { return Measure(voiced: 0, floor: 0, line: 0) }var levels: [Float] = []var i = 0while i + frame <= samples.count {@@ -852,7 +884,7 @@ enum PressSpeech {let floor = levels.sorted()[levels.count / 10]let line = min(0.016, max(0.0063, floor * 3))let voiced = Double(levels.filter { $0 >= line }.count) * Double(frame) / 16_000- return voiced >= needed+ return Measure(voiced: voiced, floor: floor, line: line)}}diff --git a/Tests/CicadaTests/PressSpeechTests.swift b/Tests/CicadaTests/PressSpeechTests.swiftindex 75153f9..62d3b37 100644--- a/Tests/CicadaTests/PressSpeechTests.swift+++ b/Tests/CicadaTests/PressSpeechTests.swift@@ -31,6 +31,16 @@ import Testing#expect(!PressSpeech.spoken(press(quiet: 2, noise: 0.003, seconds: 0.1, level: 0.2)))}+ /// The log's numbers: a loud quiet (the meeting's leftover echo) holds the line at its cap, and+ /// a voice just under it counts for nothing.+ @Test func theMeasureSaysWhyAPressWasQuiet() {+ let m = PressSpeech.measure(press(quiet: 2, noise: 0.008, seconds: 2, level: 0.01))+ #expect(m.line == 0.016)+ #expect(!m.spoken)+ #expect(m.summary.contains("line -36 dBFS"))+ #expect(PressSpeech.measure([]).voiced == 0)+ }+@Test func fillersAloneAreNotSent() {#expect(PressSpeech.filler("嗯。"))#expect(PressSpeech.filler("嗯嗯"))diff --git a/site/changelog.json b/site/changelog.jsonindex 15566a1..9b2be1c 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -29,6 +29,14 @@],"title": "装好 VB-Cable 后电脑不会再没声了。","text": "Windows 有时会把新装的 CABLE Input 设成默认播放设备,视频和会议就都听不到了。现在知了装完会自动改回原来的扬声器;之前装过的,启动时会提醒一次,点一下就能恢复,“设置 › 同声传译”里也有“恢复声音”。"+ },+ {+ "kind": "fixed",+ "platforms": [+ "mac"+ ],+ "title": "对方说话时按住右 ⌥ 说的话,不会再被当成没说话而丢掉。",+ "text": "会议声音从扬声器外放时,残留的回声会抬高“有没有人说话”的门槛,离麦克风稍远的声音过不了线,按了也没反应。现在声音偏小时先看本机识别有没有听出一句话,听出来就照常翻译播出;真的没听清,字幕条会说“没听清你说的,没有说出去”,不再一声不响。"}]},diff --git a/tools/README.md b/tools/README.mdindex d81f9d2..7425586 100644--- a/tools/README.md+++ b/tools/README.md@@ -18,7 +18,7 @@- 快捷键:`talkKey:right` 或 `talkKey:<keyCode>:<Carbon 修饰键>` 换说话键(被拒的原因写进日志),`toggleKey:…` 同理,`shortcuts` 把当前状态写进日志- 字幕条:`frame` 把位置写进日志,`place:x,y,宽,字号` 摆到指定位置- 系统麦克风:`sysMic` 把状态、默认输入、要换回的麦克风和知了实际在录的麦克风写进日志,`sysMicSet:<设备名片段>` 假装别人改了系统麦克风,`sysMicRestore` 还原,`sysMicSwitch` 换成虚拟麦克风,`sysMicAuto:<on|off>`,`speakMic:<设备名片段>` 固定知了用的麦克风(留空 = 自动)。会改本机的系统麦克风:测完 `sysMicRestore` 或退出 App- - 说话同传:`speakOn` / `speakOff` 开关,`speakAsk[:off]` 面板里第一次打开时的确认卡,`speakConfirmed:<on|off>` 是否已确认过,`speakFile:<音频>` 把文件按实时速度当作麦克风输入,`speakOut:<路径>` 把译文语音另存一份,`speakOutput:<设备名片段>` 改输出设备(留空 = 虚拟麦克风),`speakVP:<on|off>` 按键说话时用不用带回声消除的麦克风(默认开;日志 `voice mic: ready`、`speak: mic with echo cancellation`),`talkDown` / `talkUp` 用真麦克风按住、松开说话键(日志 `speak: on-device heard … Ming …`、没人说话时 `nothing said in the press`)+ - 说话同传:`speakOn` / `speakOff` 开关,`speakAsk[:off]` 面板里第一次打开时的确认卡,`speakConfirmed:<on|off>` 是否已确认过,`speakFile:<音频>` 把文件按实时速度当作麦克风输入,`speakOut:<路径>` 把译文语音另存一份,`speakOutput:<设备名片段>` 改输出设备(留空 = 虚拟麦克风),`speakVP:<on|off>` 按键说话时用不用带回声消除的麦克风(默认开;日志 `voice mic: ready`、`speak: mic with echo cancellation`),`talkDown` / `talkUp` 用真麦克风按住、松开说话键(日志 `speak: on-device heard … Ming …`、没人说话时 `nothing said in the press`;每次按键都写 `speak: press of … s, voiced … s, quiet … dBFS, line … dBFS`,声音偏小但本机识别听出一句时 `quiet press, but the on-device recognizer heard … chars: sending`)- 试一句:`speakTest:sample`(Mac 读一句示例)或 `speakTest:voice`(再发 `speakTestBegin` / `speakTestEnd` 当作按住、松开),结果以 `speak test:` 写进日志;`speakTestState`、`speakTestRender:<png>`、`speakTestClose`- 识别引擎:`recognizer:legacy` 在 macOS 26 上改用 14 / 15 的识别(`SFSpeechRecognizer`,第一次会要“语音识别”权限),`recognizer:cloud` 像 Intel Mac 那样全部交给 Ling 听(没有 key 就听不了),`recognizer:auto` 换回;下一次开始听起生效(或启动时 `open --env CICADA_RECOGNIZER=legacy`),日志里 `transcriber started recognizer=…`;`recordTrack:off` 让会议记录不再另用一遍不切句的识别(下一次开始听起生效,对比准确度用;`open --env CICADA_RECORD_TRACK=off` 同理),`recordState` 把还在校准的句数写进日志,打开 `debug` 后日志里有 `RECORD` 和 `REFINE`- 多开:两边都设 `CICADA_DEBUG_CHANNEL=x`(`open -n --env CICADA_DEBUG_CHANNEL=x build/Cicada.app`),命令只发给这一份,日志在 `/tmp/livesubs-dev-debug-x.log`