知了 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: with the mic on in a hybrid meeting, the talk key now works while the other side is talking
wqugurubc82c1242a21
diff --git a/.claude/skills/audio-test/references/room.md b/.claude/skills/audio-test/references/room.mdindex 4648e7b..010b031 100644--- a/.claude/skills/audio-test/references/room.md+++ b/.claude/skills/audio-test/references/room.md@@ -31,6 +31,8 @@ What cb7762c was measured with. `scripts/room-round.sh <label> [mac|music|none]| Then speakers again | `room-round.sh s56b mac 56` | `english_room` 0 (the measurement starts over) || Table alone | `room-round.sh alone none` | 6/6 |-Lines over the online side are lost on speakers by design (the gate). With macOS echo cancellation (`ECHO=on`) echo was 0 too but gaps fell to 0–25 %: why it is off.+Lines over the online side are lost on speakers by design (the gate). With macOS echo cancellation (`ECHO=on`) echo was 0 too but gaps fell to 0–25 %: why its processing is off for the room.++2026-11-10, `ECHO=bypass` (the default: the unit with processing off, gated like the plain mic, so the talk key can turn processing on): s25 / s56 ×4 / s100 `english_room` 0, gaps 88–100 % but one 38 %; headphones `echo=false`, over 100/100/100 %. The plain mic (`ECHO=off`) the same hour: gaps 12–100 %, `english_room` 2 in two of four rounds, and 0 % on every sentence while 同声传译's unit was made (it starves the plain mic).Also: `lsctl roomMicSilent:on` then `mic:on` shows 麦克风没声音 after about 10 s (log `room mic: silent since it started`, then `still silent`); `roomEchoSim:<on|off|real>` fixes the measurement for UI work.diff --git a/.claude/skills/audio-test/references/speak.md b/.claude/skills/audio-test/references/speak.mdindex a617eba..a418809 100644--- a/.claude/skills/audio-test/references/speak.md+++ b/.claude/skills/audio-test/references/speak.md@@ -32,7 +32,12 @@ What 279d045, 08f316b and 7106021 were measured with. `scripts/speak-round.sh <l| Silent, meeting playing | `speak-round.sh sm silent 56` | sent 0 || Silent, quiet room | `speak-round.sh sq silent 0` | sent 0 (see below) || Room mic on, quiet | `MIC=on speak-round.sh mq quiet 56` | as quiet; `in_room_lines` 0 % |-| Room mic on, meeting playing | `MIC=on speak-round.sh mm meeting 56` | sent 0 (log `played through … (echo)`): the plain room mic leaves the talk key no echo cancellation, so a press over the meeting is dropped, as on the ports |+| Room mic on, meeting playing | `MIC=on speak-round.sh mm meeting 56` (and at 100) | as meeting playing (log `voice mic: processing on` / `off` per press) |+| Room mic on, silent, meeting playing | `MIC=on speak-round.sh msm silent 100` | sent 0 |++2026-11-10: the room mic is heard through the echo-cancelling unit with processing off (`roomEcho:bypass`, the default) and a press turns it on. Room mic on, meeting playing went from 0/3 (the plain mic, `played through 100 % … (echo)`) to 3/3 at 100/100/100 % in seven rounds at 56 and 100 %; silent presses 0 sent. `roomEcho:off` brings back the plain mic and the old drop. Run `lsctl source:auto` first if the dev build listens to a fixed language: the room is recognized in it, and the table's Chinese scores 0 %.++Two rounds right after room rounds had every press at 0.0 s (unit setting changed while running; fixed by stop, set, start) and once more without a cause in the log; the log line `voice mic: N renders since the last change` says whether the unit kept running.What it found: with the plain mic (`VP=off`) the meeting's English came back from the speakers and Ming interpreted it as me — my sentences 50/27/23 %, the meeting sent back into itself, and a silent press sent the meeting back 3 of 3 times. Through echo cancellation: 86–100 %, none of the meeting. A silent press in a quiet room came back as 嗯 → "Hmm." until PressSpeech and the filler check.diff --git a/.claude/skills/audio-test/scripts/room-round.sh b/.claude/skills/audio-test/scripts/room-round.shindex 8b7e1d1..5c7c27d 100755--- a/.claude/skills/audio-test/scripts/room-round.sh+++ b/.claude/skills/audio-test/scripts/room-round.sh@@ -2,7 +2,7 @@# One room-test round on the Mac dev build, scored. Usage:# room-round.sh <label> [mac|music|none] [volume 0-100]# Env: OUT (output device name part, default "MacBook Pro Speakers"; "BlackHole" stands in for-# headphones), ECHO (roomEcho on|off, default off), GATE (roomGate on|off, default on),+# headphones), ECHO (roomEcho bypass|on|off, default bypass as in the app), GATE (roomGate on|off, default on),# TABLE (on|off: play table.wav on the ESP32, default on), WORK (clips and tools, default# $TMPDIR/cicada-room-test).# Prints: mac/room line counts, echoes dropped, English room lines (echo that got through), and@@ -11,7 +11,7 @@ set -ehere=${0:A:h}repo=${here:h:h:h:h}label=${1:?label}; play=${2:-mac}; vol=${3:-56}-OUT=${OUT:-MacBook Pro Speakers}; ECHO=${ECHO:-off}; GATE=${GATE:-on}; TABLE=${TABLE:-on}+OUT=${OUT:-MacBook Pro Speakers}; ECHO=${ECHO:-bypass}; GATE=${GATE:-on}; TABLE=${TABLE:-on}WORK=${WORK:-${TMPDIR:-/tmp}/cicada-room-test}TV=~/workshop/15.experiment/m5-stopwatch/tablevoice/tv.pyLOG=/tmp/livesubs-dev-debug.logdiff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex 55327b1..dd334ac 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -23,10 +23,13 @@ final class AppModel: ObservableObject {/// 电脑和会议室: the microphone side, its own engine (language, pauses, model), as Feishu keeps the/// online and the room streams apart instead of mixing them into one track.lazy var roomListen = ListenEngine(settings: settings, role: .room)- /// Debug (`roomEcho:on`, `roomGate:off`): the room through the echo-cancelling unit, or without- /// the gate, to try each defence alone. Next meeting. The unit is off by default: it let no echo- /// through, but lost most of what people at the table said (`EchoGate`).- var roomEchoCancel = false+ /// Debug (`roomEcho:on|off|bypass`, `roomGate:off`), next meeting. By default the room is heard+ /// through the echo-cancelling unit with its processing off (`bypass`): the plain mic's sound and+ /// the gate, as `RoomMic` (processing on let no echo through but lost most of what people at the+ /// table said), while the talk key turns processing on for a press. With the plain mic the press+ /// had no echo cancellation and was dropped whenever the other side was talking.+ var roomEchoCancel = true+ var roomEchoBypass = truevar roomEchoGate = true/// The Mac's lines of late (wall clock), and room lines waiting to be told apart from their echo.private var recentOnline: [EchoMatch.Heard] = []@@ -1382,12 +1385,13 @@ final class AppModel: ObservableObject {// macOS 14/15: two live recognizers interrupt each other (docs/macos-legacy-plan.md 2, 10).guard !roomListen.isRunning, !Recognition.legacy else { return }roomListen.echoCancelled = roomEchoCancel+ roomListen.echoBypassed = roomEchoBypass// Last meeting's measurement may be another room or another output: assume echo until measured.roomListen.echoGate.reset()// A, the gate: only the plain room mic heeds it (echo cancellation keeps talk over a remote speaker).listen.router.setOnLoud(roomEchoGate ? { [gate = roomListen.echoGate] in gate.hold() } : nil)roomListen.start()- debugLog("hybrid: room side started (echo cancellation \(roomEchoCancel ? "on" : "off"), gate \(roomEchoGate ? "on" : "off"))")+ debugLog("hybrid: room side started (echo cancellation \(roomEchoBypass ? "bypassed" : roomEchoCancel ? "on" : "off"), gate \(roomEchoGate ? "on" : "off"))")}private func stopRoomSide() {@@ -2218,7 +2222,10 @@ final class AppModel: ObservableObject {debugLog("voiceMicRun: \(ok && voiceMic.attach("debug", input: d.id) { _ in } ? "running" : "failed")")}}- case "roomEcho": roomEchoCancel = arg != "off"+ case "roomEcho":+ // roomEcho:<on|off|bypass>: bypass = through the unit with processing off, on only for a press.+ roomEchoCancel = arg != "off"+ roomEchoBypass = arg == "bypass"case "roomGate": roomEchoGate = arg != "off"case "hybridState":debugLog("hybrid state source=\(settings.listenSource) main=\(listen.isRunning) room=\(roomListen.isRunning) "diff --git a/Sources/Cicada/ListenEngine.swift b/Sources/Cicada/ListenEngine.swiftindex fad1d83..2d81af6 100644--- a/Sources/Cicada/ListenEngine.swift+++ b/Sources/Cicada/ListenEngine.swift@@ -516,7 +516,8 @@ final class ListenEngine {}// 电脑和会议室: the remote voices from the speakers are taken out of the mic (`VoiceMic`).if role == .room, echoCancelled, let voiceMic, let device = roomDevice?() {- let mic = EchoCancelledRoomMic(mic: voiceMic, device: device)+ let mic = EchoCancelledRoomMic(mic: voiceMic, device: device, processing: !echoBypassed)+ if echoBypassed { mic.echoGate = echoGate }mic.muted = roomMutedlet router = self.routermic.onAudio = { pcm in router.push(pcm) }@@ -566,6 +567,9 @@ final class ListenEngine {/// 电脑和会议室: take the online voices out of the room mic with the echo-cancelling unit. Off,/// or when the unit can't be had, the plain mic is gated while the Mac plays speech (`gateEcho`).var echoCancelled = true+ /// With `echoCancelled`: the room through the unit with processing off (the plain mic's sound,+ /// gated as `RoomMic` is), so a talk-key press can turn it on (`VoiceMic.attach(processing:)`).+ var echoBypassed = falsevar voiceMic: VoiceMic?/// Whether the plain room mic is open: the echo-cancelling unit would starve it, so it lets the/// unit go each time it starts (`startRoomMic`).diff --git a/Sources/Cicada/VoiceMic.swift b/Sources/Cicada/VoiceMic.swiftindex 7c5ca13..2102ab1 100644--- a/Sources/Cicada/VoiceMic.swift+++ b/Sources/Cicada/VoiceMic.swift@@ -39,8 +39,16 @@ final class VoiceMic: @unchecked Sendable {private var building = false/// Who hears the unit; it runs while there is anyone.private var consumers: [String: (AVAudioPCMBuffer) -> Void] = [:]+ /// The consumers that want the echo taken out. With none of them attached the unit runs bypassed:+ /// the plain mic's sound, from the same unit, so the talk key can turn processing on mid-meeting+ /// without making or letting go of a unit (each of which silences the rest of the audio).+ private var processed: Set<String> = []+ private var bypassed: Bool?private var waiting: [(Bool) -> Void] = []private var scratch = [Float](repeating: 0, count: 8192)+ /// Render calls since the last processing change, and the last error (debug, real-time thread).+ private nonisolated(unsafe) var renders = 0+ private nonisolated(unsafe) var renderError: OSStatus = noErr/// After a unit is made or let go of: audio already flowing in this process goes silent for good/// (measured: an output engine playing into BlackHole, and the system audio tap), and must be/// started anew.@@ -74,7 +82,7 @@ final class VoiceMic: @unchecked Sendable {let (ok, told) = lock.withLock { () -> (Bool, [(Bool) -> Void]) inif let old = unit, consumers.isEmpty { AudioComponentInstanceDispose(old); state = .none }var ok = false- if let made, unit == nil { state = .ready(made, input: input, output: output); ok = true } else if let made { AudioComponentInstanceDispose(made) }+ if let made, unit == nil { state = .ready(made, input: input, output: output); bypassed = nil; ok = true } else if let made { AudioComponentInstanceDispose(made) }building = falsedefer { waiting = [] }return (ok, waiting)@@ -89,13 +97,15 @@ final class VoiceMic: @unchecked Sendable {/// `key` hears `input` from now on, if the unit is ready for it and the current output (it starts/// with the first consumer). Otherwise false: the caller uses the plain mic this time, after/// `release` when nobody else is attached; a new unit is made later, not while the plain mic runs.- func attach(_ key: String, input: AudioObjectID, onAudio: @escaping (AVAudioPCMBuffer) -> Void) -> Bool {+ func attach(_ key: String, input: AudioObjectID, processing: Bool = true, onAudio: @escaping (AVAudioPCMBuffer) -> Void) -> Bool {guard let output = SystemAudioTap.defaultOutputDevice() else { return false }lock.lock()guard case .ready(let unit, let i, let o) = state, (i, o) == (input, output) else { lock.unlock(); return false }let first = consumers.isEmptyconsumers[key] = onAudio+ if processing { processed.insert(key) } else { processed.remove(key) }lock.unlock()+ applyBypass(unit)guard first else { return true }let status = AudioOutputUnitStart(unit)if status != noErr {@@ -111,17 +121,48 @@ final class VoiceMic: @unchecked Sendable {func detach(_ key: String) {lock.lock()guard consumers.removeValue(forKey: key) != nil else { lock.unlock(); return }- guard consumers.isEmpty, let unit else { lock.unlock(); return }+ processed.remove(key)+ guard consumers.isEmpty, let unit else {+ let u = unit+ lock.unlock()+ if let u { applyBypass(u) }+ return+ }lock.unlock()AudioOutputUnitStop(unit)debugLog("voice mic: stopped (\(key) was the last)")}+ /// Processing on while a consumer wants it, else bypassed (only the room is attached, unprocessed).+ private func applyBypass(_ unit: AudioUnit) {+ let change: Bool? = lock.withLock {+ let b = processed.isEmpty+ if bypassed == b { return nil }+ bypassed = b+ return b+ }+ guard let bypass = change else { return }+ debugLog("voice mic: \(renders) renders since the last change, last error \(renderError)")+ renders = 0+ renderError = noErr+ var value: UInt32 = bypass ? 1 : 0+ // Set on a running unit, it stopped delivering any audio: stop, set, start (~40 ms).+ var running: UInt32 = 0+ var size = UInt32(MemoryLayout<UInt32>.size)+ AudioUnitGetProperty(unit, kAudioOutputUnitProperty_IsRunning, kAudioUnitScope_Global, 0, &running, &size)+ let stopped = running != 0 ? AudioOutputUnitStop(unit) : noErr+ let status = AudioUnitSetProperty(unit, kAUVoiceIOProperty_BypassVoiceProcessing, kAudioUnitScope_Global, 0,+ &value, UInt32(MemoryLayout<UInt32>.size))+ let started = running != 0 ? AudioOutputUnitStart(unit) : noErr+ debugLog("voice mic: processing \(bypass ? "off" : "on") (running \(running), stop \(stopped), set \(status), start \(started))")+ }+/// Lets go of the unit (not while anyone is attached), so the plain mic hears again.func release() {let old: AudioUnit? = lock.withLock {guard consumers.isEmpty, let u = unit else { return nil }state = .none+ bypassed = nilreturn u}if let old {@@ -171,6 +212,8 @@ final class VoiceMic: @unchecked Sendable {return AudioUnitRender(unit, flags, ts, 1, frames, &list)}let listeners = lock.withLock { Array(consumers.values) }+ renders += 1+ if status != noErr { renderError = status }guard status == noErr, !listeners.isEmpty, let out = AVAudioPCMBuffer(pcmFormat: Self.format, frameCapacity: frames),let dst = out.floatChannelData?[0] else { return status }out.frameLength = frames@@ -199,20 +242,28 @@ final class EchoCancelledRoomMic: AudioSource, @unchecked Sendable {var deviceName: String { device.name }var deviceUID: String { device.uid }- init(mic: VoiceMic, device: OutputDevice) {+ /// Off: the room hears the unit bypassed, the plain mic's sound and `echoGate` as with `RoomMic`+ /// (echo cancellation lost most of what people at the table said); the unit is then running for+ /// the talk key to turn processing on for a press.+ private let processing: Bool+ /// With `processing` off: silence while the Mac plays speech.+ var echoGate: EchoGate?++ init(mic: VoiceMic, device: OutputDevice, processing: Bool = true) {self.mic = micself.device = device+ self.processing = processing}func start() throws {mic.prepare(input: device.id) { [weak self] ok inguard let self, !self.lock.withLock({ self.stopped }) else { return }- let attached = ok && self.mic.attach("room", input: self.device.id) { [weak self] buf in self?.deliver(buf) }+ let attached = ok && self.mic.attach("room", input: self.device.id, processing: self.processing) { [weak self] buf in self?.deliver(buf) }if !attached {debugLog("room mic: echo cancellation unavailable, plain mic instead")self.onFailed?()} else {- debugLog("room mic started with echo cancellation: \(self.device.name)")+ debugLog("room mic started \(self.processing ? "with echo cancellation" : "through the unit, bypassed"): \(self.device.name)")}}}@@ -223,7 +274,20 @@ final class EchoCancelledRoomMic: AudioSource, @unchecked Sendable {}private func deliver(_ buf: AVAudioPCMBuffer) {- if muted, let d = buf.floatChannelData?[0] { d.update(repeating: 0, count: Int(buf.frameLength)) }+ let n = Int(buf.frameLength)+ if let gate = echoGate, let d = buf.floatChannelData?[0], n > 0 {+ var sum: Float = 0+ for i in 0..<n { sum += d[i] * d[i] }+ gate.roomLevel((sum / Float(n)).squareRoot(), seconds: Double(n) / buf.format.sampleRate)+ }+ // Silence in a buffer of its own: `buf` is the one every consumer gets, the talk key's press too.+ if muted || echoGate?.closed() == true {+ guard let quiet = AVAudioPCMBuffer(pcmFormat: buf.format, frameCapacity: buf.frameLength) else { return }+ quiet.frameLength = buf.frameLength+ if let d = quiet.floatChannelData?[0] { d.update(repeating: 0, count: n) }+ onAudio?(quiet)+ return+ }onAudio?(buf)}}diff --git a/site/changelog.json b/site/changelog.jsonindex 2d36177..b9a5dfc 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -45,6 +45,14 @@],"title": "对方说话时按住右 ⌥ 说的话,不会再被当成没说话而丢掉。","text": "会议声音从扬声器外放时,残留的回声会抬高“有没有人说话”的门槛,离麦克风稍远的声音过不了线,按了也没反应。现在声音偏小时先看本机识别有没有听出一句话,听出来就照常翻译播出;真的没听清,字幕条会说“没听清你说的,没有说出去”,不再一声不响。"+ },+ {+ "kind": "fixed",+ "platforms": [+ "mac"+ ],+ "title": "打开麦克风开混合会议时,对方正在说话也能按住右 ⌥ 同声传译了。",+ "text": "以前打开麦克风后,说话键用的是没有回声消除的麦克风,对方的声音从扬声器传进来,只要对方在说,按下去的话一律不说出去。现在会议室麦克风改走回声消除的通道、平时不做处理,按住说话键时才打开回声消除:对方说话时说的也能完整翻译播出,会议室那边听到的不变。"}]},diff --git a/tools/README.md b/tools/README.mdindex 7425586..aaff152 100644--- a/tools/README.md+++ b/tools/README.md@@ -10,7 +10,7 @@- 状态:`state[:<分区>,…]` 把当前状态以 JSON 输出(`schema`、`at`,分区 `build` `permissions` `listen` `room` `display` `notes` `speak` `ai` `import` `update` `records` `problem`),直接从各引擎读;没有 key 和 token,原文只在调试模式下给。`ping` 只回 `build`- 等待:`lsctl --wait '<路径> <==|!=|>|<|>=|<=> <值>'` 反复取 `state` 直到成立(默认最多 10 秒,超时退出 2 并写出当时的值),如 `lsctl start:user && lsctl --wait 'display.notesWindow.visible == true'`。布尔值只能用 `==` / `!=` 比 `true` / `false`- 开关字幕:`start` / `stop`(`start:user` 当作用户点了开始听,纪要窗口立即出现;`start` 当作自动开始,等到有人说话)- - 麦克风:`mic:<on|off>` 等于点“打开麦克风”/“关闭麦克风”(没在听时打开会开始听;旧的 `listenSource:<system|room|both>` 也还能用),`hybridState` 把两边的状态写进日志,含 `echo=` 和测量值(扬声器传到麦克风没有)、`music=`、`micSilent=`;`roomEcho:on` / `roomGate:off` 下一场会议用系统回声消除 / 不在电脑放人声时关麦克风,单独试每道防线,日志 `hybrid: room line dropped as an echo` / `kept`、`room echo: speakers reach the mic` / `none`;`roomEchoSim:<on|off|real>` 假装测出(或没测出)回声;`roomMicSilent:<on|off>` 让麦克风从下次打开起只给 0(日志 `room mic: silent since it started`,再 `still silent`,纪要窗口出“麦克风没声音”);`voiceMicRun:<on|off>` 只开回声消除单元看它对别的声音有没有影响;念译文时 `room mic muted` / `open`;`micDeniedSim:<on|off>` 让麦克风当作被拒(纪要窗口顶部提示、字幕条橙色标签、菜单栏橙点,纪要窗口收起 10 秒后发一次通知,日志 `problem:` 和 `menu bar: badge=`)。实测回声、桌边的话和同声传译:`.claude/skills/audio-test`+ - 麦克风:`mic:<on|off>` 等于点“打开麦克风”/“关闭麦克风”(没在听时打开会开始听;旧的 `listenSource:<system|room|both>` 也还能用),`hybridState` 把两边的状态写进日志,含 `echo=` 和测量值(扬声器传到麦克风没有)、`music=`、`micSilent=`;`roomEcho:<bypass|on|off>` 下一场会议的会议室麦克风:默认 `bypass` 经回声消除单元但关掉处理(按住说话键时才打开,日志 `voice mic: processing on` / `off`),`on` 一直消除回声,`off` 普通麦克风(说话键这时没有回声消除,对方在说时按下会被丢掉);`roomGate:off` 不在电脑放人声时关麦克风,单独试每道防线,日志 `hybrid: room line dropped as an echo` / `kept`、`room echo: speakers reach the mic` / `none`;`roomEchoSim:<on|off|real>` 假装测出(或没测出)回声;`roomMicSilent:<on|off>` 让麦克风从下次打开起只给 0(日志 `room mic: silent since it started`,再 `still silent`,纪要窗口出“麦克风没声音”);`voiceMicRun:<on|off>` 只开回声消除单元看它对别的声音有没有影响;念译文时 `room mic muted` / `open`;`micDeniedSim:<on|off>` 让麦克风当作被拒(纪要窗口顶部提示、字幕条橙色标签、菜单栏橙点,纪要窗口收起 10 秒后发一次通知,日志 `problem:` 和 `menu bar: badge=`)。实测回声、桌边的话和同声传译:`.claude/skills/audio-test`- 打开界面:`open`(主窗口)、`panel`(菜单栏面板)、`settings[:speak]`(设置,可指定栏目)- 虚拟麦克风:`micTest` 试音(往虚拟麦克风播一句再听回来,结果写进日志),`micNext` 做清单里的下一步- 会议软件的麦克风:`micUsers` 把每个读麦克风的进程和列表写进日志,`micGuide:<bundle id 或名字>` 打开怎么改,`micGuideRender:<bundle id>=<png>`