知了 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 and the meeting on the speakers, the talk key no longer sends the other side's own words back into the meeting
wqugurue41a6890c357
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.stringsindex afe740d..ffd1050 100644--- a/Resources/en.lproj/Localizable.strings+++ b/Resources/en.lproj/Localizable.strings@@ -847,6 +847,7 @@"无法准备语音识别:%@" = "Can't prepare speech recognition: %@";"语音识别仍在准备中,请再按一次" = "Speech recognition is still getting ready; press again";"这句没翻译成 · 没有说出去" = "This line wasn't translated · nothing was said";+"对方在说话时说的,没有说出去" = "Said while they were talking, 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 ebb9496..555e910 100644--- a/Resources/ja.lproj/Localizable.strings+++ b/Resources/ja.lproj/Localizable.strings@@ -847,6 +847,7 @@"无法准备语音识别:%@" = "音声認識を準備できません: %@";"语音识别仍在准备中,请再按一次" = "音声認識はまだ準備中です。もう一度押してください";"这句没翻译成 · 没有说出去" = "この文は翻訳できず · 発話していません";+"对方在说话时说的,没有说出去" = "相手が話している間の発言なので、送っていません";/* SpeakTest */"语音识别还没准备好,请稍后再试" = "音声認識の準備がまだです。少し待ってから再試行してください";diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.stringsindex 0f11c05..67bf59c 100644--- a/Resources/ko.lproj/Localizable.strings+++ b/Resources/ko.lproj/Localizable.strings@@ -847,6 +847,7 @@"无法准备语音识别:%@" = "음성 인식을 준비할 수 없습니다: %@";"语音识别仍在准备中,请再按一次" = "음성 인식을 준비하는 중입니다. 다시 눌러 주세요";"这句没翻译成 · 没有说出去" = "이 문장은 번역되지 않음 · 말하지 않았습니다";+"对方在说话时说的,没有说出去" = "상대방이 말하는 중이라 보내지 않았어요";/* SpeakTest */"语音识别还没准备好,请稍后再试" = "음성 인식이 아직 준비되지 않았습니다. 잠시 후 다시 시도하세요";diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.stringsindex 201dad8..a497b46 100644--- a/Resources/zh-Hans.lproj/Localizable.strings+++ b/Resources/zh-Hans.lproj/Localizable.strings@@ -847,6 +847,7 @@"无法准备语音识别:%@" = "无法准备语音识别:%@";"语音识别仍在准备中,请再按一次" = "语音识别仍在准备中,请再按一次";"这句没翻译成 · 没有说出去" = "这句没翻译成 · 没有说出去";+"对方在说话时说的,没有说出去" = "对方在说话时说的,没有说出去";/* SpeakTest */"语音识别还没准备好,请稍后再试" = "语音识别还没准备好,请稍后再试";diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex 864d9ea..4b3374a 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -184,6 +184,9 @@ final class AppModel: ObservableObject {guard let self else { return false }return self.roomListen.holdsPlainMic || self.listen.holdsPlainMic}+ speak.playedShare = { [gate = roomListen.echoGate] from, to in+ gate.playedShare(from: from.timeIntervalSinceReferenceDate, to: to.timeIntervalSinceReferenceDate)+ }roomListen.onStateChange = { [weak self] in self?.refresh() }listen.onSubtitle = { [weak self] src, dst inguard let self else { return }diff --git a/Sources/Cicada/RoomMic.swift b/Sources/Cicada/RoomMic.swiftindex 85c61b7..3a5df5d 100644--- a/Sources/Cicada/RoomMic.swift+++ b/Sources/Cicada/RoomMic.swift@@ -151,6 +151,8 @@ final class EchoGate: @unchecked Sendable {private var during: [(t: Double, rms: Float, s: Double)] = []private var quiet: [(t: Double, rms: Float, s: Double)] = []private var _echo = true+ /// When the Mac's loud blocks came, for `playedShare`.+ private var loud: [Double] = []/// Debug (`roomEchoSim:<on|off>`): pretend the measurement says this.var forced: Bool?@@ -168,6 +170,8 @@ final class EchoGate: @unchecked Sendable {/// A loud block of the Mac's audio, on the main engine's audio queue.func hold(now: Double = CFAbsoluteTimeGetCurrent()) {lock.withLock {+ loud.append(now)+ loud.removeAll { $0 < now - Self.window * 3 }if now - lastLoud > Self.stretchGap { stretchStart = now }lastLoud = nowguard !musicLocked(now), echoLocked else { return }@@ -188,6 +192,21 @@ final class EchoGate: @unchecked Sendable {lock.withLock { now < until }}+ /// The share of `from`…`to` the Mac played something loud through, when its speakers reach the+ /// mic (0 on headphones). The talk key on the plain mic hears that as much as you.+ func playedShare(from: Double, to: Double) -> Double {+ lock.withLock {+ guard echoLocked, to > from else { return 0 }+ let steps = max(1, Int((to - from) / 0.1))+ var hit = 0+ for i in 0..<steps {+ let t = from + (Double(i) + 0.5) * (to - from) / Double(steps)+ if loud.contains(where: { $0 <= t + Self.hang && $0 >= t - Self.hang }) { hit += 1 }+ }+ return Double(hit) / Double(steps)+ }+ }+/// Whether the speakers reach the room mic, as last measured.var echo: Bool { lock.withLock { echoLocked } }/// Whether the Mac is playing something loud that has no words in it.diff --git a/Sources/Cicada/SpeakEngine.swift b/Sources/Cicada/SpeakEngine.swiftindex 14ff3df..3c3b914 100644--- a/Sources/Cicada/SpeakEngine.swift+++ b/Sources/Cicada/SpeakEngine.swift@@ -131,8 +131,16 @@ final class SpeakEngine {private var finals: [String] = []private var volatile = ""private var pressStarted = Date()+ /// The press went to the plain mic: echo cancellation wasn't to be had (打开麦克风 holds the mic+ /// without it, and lets go of the unit the press would need).+ private var pressPlain = false/// Whether the plain room mic holds the mic (打开麦克风 without echo cancellation).var micTaken: (() -> Bool)?+ /// The share of a stretch the Mac played its meeting through to the mic (`EchoGate.playedShare`).+ var playedShare: ((Date, Date) -> Double)?+ /// Over this share, what the plain mic heard is the meeting's echo as much as you: Ming sent the+ /// other side's own words back to them (as the ports drop it, Windows `EchoShare`).+ static let echoShare = 0.5private nonisolated(unsafe) var micRecorder: AVAudioFile?private nonisolated(unsafe) var micRecordURL: URL?/// This press's audio as 16 kHz mono 16-bit samples for Ming; only touched on `micQueue`.@@ -367,8 +375,9 @@ final class SpeakEngine {}}debugLog("speak: mic \(started ? "with echo cancellation" : "plain, echo cancellation not ready")")- if started { return }+ if started { pressPlain = false; return }}+ pressPlain = true// A unit left over (toggled off mid-press, a virtual mic) would starve the plain mic; one the// room is using stays (the talk key is then on another mic).if !voiceMic.inUse { voiceMic.release() }@@ -476,6 +485,16 @@ final class SpeakEngine {onLive?(.idle, "", "")return}+ // 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))+ Task { _ = await u.text.value }+ finals = []+ volatile = ""+ phase = .idle+ onLive?(.idle, "", L("对方在说话时说的,没有说出去"))+ return+ }probe?.pressWAV = wavlet from = settings.speakFromLang.codelet to = targetCodediff --git a/Tests/CicadaTests/HybridTests.swift b/Tests/CicadaTests/HybridTests.swiftindex 765c4ac..4104c72 100644--- a/Tests/CicadaTests/HybridTests.swift+++ b/Tests/CicadaTests/HybridTests.swift@@ -58,6 +58,18 @@ import Testing}}+ @Test func thePressShareTheMacPlayedThrough() {+ let g = EchoGate()+ // The meeting loud through 0–4 s (a block every 0.1 s), then quiet.+ for i in 0..<40 { g.hold(now: 1000 + Double(i) * 0.1) }+ #expect(g.playedShare(from: 1000, to: 1004) > 0.9)+ #expect(g.playedShare(from: 1006, to: 1010) == 0)+ #expect(abs(g.playedShare(from: 1002, to: 1006) - 0.6) < 0.1)+ // Headphones: the speakers don't reach the mic, so nothing played counts.+ g.forced = false+ #expect(g.playedShare(from: 1000, to: 1004) == 0)+ }+@Test func musicStopsClosingTheGate() {let g = EchoGate()var t = 0.0diff --git a/site/changelog.json b/site/changelog.jsonindex 42f7347..da03188 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -6,6 +6,14 @@"summary": "刚开完会就换 AI 服务时,设置里不再把连不上的新服务显示成已连接;长会议生成完整纪要时,不再丢掉某个话题;AI 服务一直出错时会提示;Windows、Linux、Android 上开头轻声的一句短话不再被漏掉;真实麦克风和虚拟麦克风格式不同时,按住说话不再闪退。","image": null,"items": [+ {+ "kind": "fixed",+ "platforms": [+ "mac"+ ],+ "title": "打开麦克风、会议在扬声器上播放时,按住说话键不再把对方刚说的话翻译后又说回会议里。",+ "text": "这时说话键用不上回声消除;按住的这段里电脑一直在放对方的声音,就不发出去,并提示“对方在说话时说的,没有说出去”。对方停下的空当里说照常发出。"+ },{"kind": "fixed","platforms": [