Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

fix: when the room's microphone is unplugged, Cicada moves to another one and says so, or hears the Mac alone

wqugurue4cb18f8e947
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings
index b59e1db..e0f0288 100644
--- a/Resources/en.lproj/Localizable.strings
+++ b/Resources/en.lproj/Localizable.strings
@@ -650,6 +650,10 @@
/* RoomMic */
"线上有人说话时,先不听会议室" = "The room pauses while someone online speaks";
"用 Mac 麦克风听会议室" = "Hearing the room with the Mac's mic";
+"已改用 Mac 自带的麦克风" = "Now using the Mac's microphone";
+"已改用 %@" = "Now using %@";
+"只听电脑了" = "Hearing the Mac only";
+"没有别的麦克风,已暂停" = "No other microphone, so listening is paused";
"没有可用的麦克风" = "No microphone available";
/* SessionStore */
@@ -954,6 +958,7 @@
"去设置" = "Open Settings";
"听会议室要先允许麦克风" = "Allow the microphone to hear the room";
"电脑声音照常在记" = "The Mac's audio is still being recorded";
+"外接麦克风断开了" = "The microphone was disconnected";
"线上也有人?" = "Anyone online too?";
"%@ 正在通话" = "%@ is in a call";
"也听电脑" = "Hear the Mac too";
diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.strings
index d04b86f..933cb89 100644
--- a/Resources/ja.lproj/Localizable.strings
+++ b/Resources/ja.lproj/Localizable.strings
@@ -650,6 +650,10 @@
/* RoomMic */
"线上有人说话时,先不听会议室" = "オンラインの人が話す間は会議室を聞きません";
"用 Mac 麦克风听会议室" = "会議室は Mac のマイクで聞きます";
+"已改用 Mac 自带的麦克风" = "Mac 内蔵のマイクに切り替えました";
+"已改用 %@" = "%@ に切り替えました";
+"只听电脑了" = "パソコンの音だけを聞いています";
+"没有别的麦克风,已暂停" = "ほかのマイクがないため一時停止しました";
"没有可用的麦克风" = "使用できるマイクがありません";
/* SessionStore */
@@ -954,6 +958,7 @@
"去设置" = "設定を開く";
"听会议室要先允许麦克风" = "会議室を聞くにはマイクを許可してください";
"电脑声音照常在记" = "Mac の音声はそのまま記録中";
+"外接麦克风断开了" = "外付けマイクが外れました";
"线上也有人?" = "オンラインの参加者も?";
"%@ 正在通话" = "%@ で通話中";
"也听电脑" = "Mac も聞く";
diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.strings
index 44879e2..4f35c3e 100644
--- a/Resources/ko.lproj/Localizable.strings
+++ b/Resources/ko.lproj/Localizable.strings
@@ -650,6 +650,10 @@
/* RoomMic */
"线上有人说话时,先不听会议室" = "온라인에서 말하는 동안 회의실은 잠시 듣지 않아요";
"用 Mac 麦克风听会议室" = "회의실은 Mac 마이크로 들어요";
+"已改用 Mac 自带的麦克风" = "Mac 내장 마이크로 바꿨어요";
+"已改用 %@" = "%@(으)로 바꿨어요";
+"只听电脑了" = "컴퓨터 소리만 듣고 있어요";
+"没有别的麦克风,已暂停" = "다른 마이크가 없어 일시 정지했어요";
"没有可用的麦克风" = "사용할 수 있는 마이크가 없습니다";
/* SessionStore */
@@ -954,6 +958,7 @@
"去设置" = "설정 열기";
"听会议室要先允许麦克风" = "회의실을 들으려면 마이크를 허용하세요";
"电脑声音照常在记" = "Mac 소리는 계속 기록 중";
+"外接麦克风断开了" = "외장 마이크 연결이 끊겼어요";
"线上也有人?" = "온라인 참석자도 있나요?";
"%@ 正在通话" = "%@ 통화 중";
"也听电脑" = "Mac도 듣기";
diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.strings
index 8e4af08..980208c 100644
--- a/Resources/zh-Hans.lproj/Localizable.strings
+++ b/Resources/zh-Hans.lproj/Localizable.strings
@@ -650,6 +650,10 @@
/* RoomMic */
"线上有人说话时,先不听会议室" = "线上有人说话时,先不听会议室";
"用 Mac 麦克风听会议室" = "用 Mac 麦克风听会议室";
+"已改用 Mac 自带的麦克风" = "已改用 Mac 自带的麦克风";
+"已改用 %@" = "已改用 %@";
+"只听电脑了" = "只听电脑了";
+"没有别的麦克风,已暂停" = "没有别的麦克风,已暂停";
"没有可用的麦克风" = "没有可用的麦克风";
/* SessionStore */
@@ -954,6 +958,7 @@
"去设置" = "去设置";
"听会议室要先允许麦克风" = "听会议室要先允许麦克风";
"电脑声音照常在记" = "电脑声音照常在记";
+"外接麦克风断开了" = "外接麦克风断开了";
"线上也有人?" = "线上也有人?";
"%@ 正在通话" = "%@ 正在通话";
"也听电脑" = "也听电脑";
diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swift
index 6473b0e..f24fab2 100644
--- a/Sources/Cicada/AppModel.swift
+++ b/Sources/Cicada/AppModel.swift
@@ -90,6 +90,10 @@ final class AppModel: ObservableObject {
/// HybridNote under 听哪里.
@Published var hybridNote: String?
private var headsetCheck: (at: Date, on: Bool) = (.distantPast, false)
+ /// 外接麦克风断开了: what happened instead (RoomMicLoss), for a few seconds.
+ @Published var roomMicLost: String?
+ /// The debug command's pretend unplug: these inputs count as gone.
+ private var fakeGoneMics: Set<String> = []
/// Answered (or 听哪里 changed) in this meeting: not asked again until the next one.
var roomPromptDismissed = false
/// 线上也有人? answered this meeting. Its own flag: picking 会议室 by hand answers the question
@@ -263,8 +267,11 @@ final class AppModel: ObservableObject {
}
speak.roomLanguage = { [weak self] in self?.listen.activeLang?.code }
speak.inputDevice = { [weak self] in self?.systemMic.recordingDevice }
- listen.roomDevice = { AudioDevices.roomMic }
- roomListen.roomDevice = { AudioDevices.roomMic }
+ let roomMic = { [weak self] () -> OutputDevice? in
+ MainActor.assumeIsolated { AudioDevices.roomMic(excluding: self?.fakeGoneMics ?? []) }
+ }
+ listen.roomDevice = roomMic
+ roomListen.roomDevice = roomMic
applyVoice()
speak.onStatus = { [weak self] text in self?.status = text }
speak.onLive = { [weak self] phase, src, dst in
@@ -322,6 +329,7 @@ final class AppModel: ObservableObject {
MainActor.assumeIsolated {
self?.watchEnd()
self?.updateOnlinePrompt()
+ self?.watchRoomMic()
}
}
endTimer = watch
@@ -345,6 +353,25 @@ final class AppModel: ObservableObject {
if ask != onlinePrompt { onlinePrompt = ask }
}
+ /// The room's microphone unplugged: Core Audio moves the engine to the system default without a
+ /// word, which may be a headset or the virtual mic. Pick again the way the meeting started, and say so.
+ private func watchRoomMic() {
+ let both = settings.hearsBoth && roomListen.isRunning
+ guard let engine = both ? roomListen : settings.listensToRoom && listen.isRunning ? listen : nil,
+ let uid = engine.roomMicUID,
+ fakeGoneMics.contains(uid) || !AudioDevices.inputs().contains(where: { $0.uid == uid }) else { return }
+ let next = AudioDevices.roomMic(excluding: fakeGoneMics)
+ debugLog("room mic gone: \(uid) → \(next?.name ?? "none")")
+ if next != nil { engine.reconnectAudio() } else if both { stopRoomSide() } else { stop() }
+ let note = RoomMicLoss.detail(next: next?.name, builtIn: next.map { AudioDevices.transport($0.id) == kAudioDeviceTransportTypeBuiltIn } ?? false,
+ both: both)
+ roomMicLost = note
+ DispatchQueue.main.asyncAfter(deadline: .now() + 8) { [weak self] in
+ if self?.roomMicLost == note { self?.roomMicLost = nil }
+ }
+ refresh()
+ }
+
func pickLanguage(_ lang: Lang) { listen.pickLanguage(lang) }
func retryModel() { listen.retryModel() }
func startCloud() { listen.startCloud(); refresh() }
@@ -588,6 +615,7 @@ final class AppModel: ObservableObject {
speechHeard = false
roomPromptDismissed = false
onlinePromptDismissed = false
+ fakeGoneMics = []
meetingSubtitles = nil
autoEnded = false
endWatch = MeetingEndWatch(config: endConfig, start: Date())
@@ -1555,6 +1583,11 @@ final class AppModel: ObservableObject {
case "source": sourceSelection = arg
case "listenSource": listenSourceSelection = arg
case "roomPrompt": answerRoomPrompt(arg == "room")
+ case "roomMicGone":
+ // roomMicGone[:none]: pretend the room's microphone (or every one) was unplugged.
+ let uid = (settings.hearsBoth ? roomListen : listen).roomMicUID
+ fakeGoneMics = arg == "none" ? Set(AudioDevices.inputs().map(\.uid)) : Set([uid].compactMap { $0 })
+ watchRoomMic()
case "onlinePrompt":
if arg == "state" { debugLog("online prompt: \(onlinePrompt ?? "hidden")") } else { answerOnlinePrompt(arg == "both") }
case "open": openMainWindow?()
diff --git a/Sources/Cicada/ListenEngine.swift b/Sources/Cicada/ListenEngine.swift
index a55e34d..a5b40ac 100644
--- a/Sources/Cicada/ListenEngine.swift
+++ b/Sources/Cicada/ListenEngine.swift
@@ -492,6 +492,8 @@ final class ListenEngine {
var voiceMic: VoiceMic?
/// Whether the room is heard through the echo-cancelling unit right now.
var hearsEchoCancelled: Bool { audioTap is EchoCancelledRoomMic }
+ /// The microphone hearing the room right now, to notice it going away (nil: the default input).
+ var roomMicUID: String? { (audioTap as? RoomMic)?.deviceUID ?? (audioTap as? EchoCancelledRoomMic)?.deviceUID }
private func echoCancellationFailed(_ mic: EchoCancelledRoomMic) {
guard isRunning, audioTap === mic else { return }
diff --git a/Sources/Cicada/RoomMic.swift b/Sources/Cicada/RoomMic.swift
index 90a181e..167fad2 100644
--- a/Sources/Cicada/RoomMic.swift
+++ b/Sources/Cicada/RoomMic.swift
@@ -108,6 +108,16 @@ enum HybridNote {
}
}
+/// 外接麦克风断开了: the microphone hearing the room went away mid-meeting. Another takes over
+/// (`RoomMicPlan` among what's left); with none left, 电脑和会议室 goes on with the Mac alone and
+/// 会议室 pauses.
+enum RoomMicLoss {
+ static func detail(next: String?, builtIn: Bool, both: Bool) -> String {
+ guard let next else { return both ? L("只听电脑了") : L("没有别的麦克风,已暂停") }
+ return builtIn ? L("已改用 Mac 自带的麦克风") : L("已改用 \(next)")
+ }
+}
+
extension AudioDevices {
static func transport(_ device: AudioObjectID) -> UInt32 {
var value: UInt32 = 0
@@ -119,13 +129,17 @@ extension AudioDevices {
}
/// The microphone `RoomMicPlan` picks among the Mac's inputs right now.
- static var roomMic: OutputDevice? {
- let all = inputs()
+ static var roomMic: OutputDevice? { roomMic(excluding: []) }
+
+ /// `excluding`: inputs to treat as gone (the debug command's pretend unplug).
+ static func roomMic(excluding: Set<String>) -> OutputDevice? {
+ let all = inputs().filter { !excluding.contains($0.uid) }
let plan = all.map { d -> RoomMicPlan.Input in
let t = transport(d.id)
return .init(uid: d.uid, builtIn: t == kAudioDeviceTransportTypeBuiltIn,
bluetooth: t == kAudioDeviceTransportTypeBluetooth || t == kAudioDeviceTransportTypeBluetoothLE,
- virtual: d.isVirtualMic)
+ // The aggregate macOS makes for echo cancellation is no microphone of its own.
+ virtual: d.isVirtualMic || d.uid.hasPrefix("CADefaultDeviceAggregate"))
}
let uid = RoomMicPlan.pick(defaultUID: defaultInput?.uid, inputs: plan)
return all.first { $0.uid == uid }
@@ -198,6 +212,7 @@ final class RoomMic: AudioSource {
}
var deviceName: String { device?.name ?? AudioDevices.inputDevice(of: engine) }
+ var deviceUID: String? { device?.uid }
func start() throws {
startedAt = Date()
diff --git a/Sources/Cicada/Views.swift b/Sources/Cicada/Views.swift
index 44dd787..9d9d8e3 100644
--- a/Sources/Cicada/Views.swift
+++ b/Sources/Cicada/Views.swift
@@ -190,6 +190,7 @@ struct MenuPanelView: View {
if model.roomPrompt { roomPromptStrip }
if let app = model.onlinePrompt { onlinePromptStrip(app) }
if model.hybridMicDenied { hybridMicStrip }
+ if let next = model.roomMicLost { roomMicLostStrip(next) }
AIServiceStrip(model: model, ling: model.ling)
// Right under the header: below the settings it was easy to miss.
UpdateBanner(updates: model.updates, model: model)
@@ -334,6 +335,18 @@ extension MenuPanelView {
}
}
+extension MenuPanelView {
+ /// 外接麦克风断开了: what Cicada did instead. Goes away by itself.
+ func roomMicLostStrip(_ next: String) -> some View {
+ VStack(alignment: .leading, spacing: 2) {
+ Text("外接麦克风断开了").font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.ink)
+ Text(next).font(.system(size: 11)).foregroundStyle(Palette.secondary)
+ }
+ .padding(12).frame(maxWidth: .infinity, alignment: .leading)
+ .background(RoundedRectangle(cornerRadius: 11).fill(Palette.accentPale))
+ }
+}
+
extension MenuPanelView {
/// 线上也有人?: listening to the room while a meeting app here is in a call. Asked once a meeting.
func onlinePromptStrip(_ app: String) -> some View {
diff --git a/Sources/Cicada/VoiceMic.swift b/Sources/Cicada/VoiceMic.swift
index e9ab129..0828e76 100644
--- a/Sources/Cicada/VoiceMic.swift
+++ b/Sources/Cicada/VoiceMic.swift
@@ -188,6 +188,7 @@ final class EchoCancelledRoomMic: AudioSource, @unchecked Sendable {
set { lock.withLock { _muted = newValue } }
}
var deviceName: String { device.name }
+ var deviceUID: String { device.uid }
init(mic: VoiceMic, device: OutputDevice) {
self.mic = mic
diff --git a/Tests/CicadaTests/HybridRecordTests.swift b/Tests/CicadaTests/HybridRecordTests.swift
index 8a0a08b..181ebd0 100644
--- a/Tests/CicadaTests/HybridRecordTests.swift
+++ b/Tests/CicadaTests/HybridRecordTests.swift
@@ -29,6 +29,13 @@ import Testing
#expect(!RoomPrompt.asksOnline(roomOnly: false, bothAvailable: true, answered: false, inCall: true))
}
+ @Test func anUnpluggedMicSaysWhatTookOver() {
+ #expect(RoomMicLoss.detail(next: "MacBook Pro Microphone", builtIn: true, both: true) == L("已改用 Mac 自带的麦克风"))
+ #expect(RoomMicLoss.detail(next: "Jabra Speak 510", builtIn: false, both: false) == L("已改用 Jabra Speak 510"))
+ #expect(RoomMicLoss.detail(next: nil, builtIn: false, both: true) == L("只听电脑了"))
+ #expect(RoomMicLoss.detail(next: nil, builtIn: false, both: false) == L("没有别的麦克风,已暂停"))
+ }
+
@Test func noteSaysHowTheRoomIsHeard() {
#expect(HybridNote.line(roomRunning: true, echoCancelled: true, headsetDefault: false) == nil)
#expect(HybridNote.line(roomRunning: false, echoCancelled: false, headsetDefault: true) == nil)
diff --git a/site/changelog.json b/site/changelog.json
index a55be69..ccdda86 100644
--- a/site/changelog.json
+++ b/site/changelog.json
@@ -85,6 +85,14 @@
],
"title": "电脑和会议室时,面板会说明会议室是怎么听的。",
"text": "回声消除用不了时写“线上有人说话时,先不听会议室”;戴着蓝牙耳机时写“用 Mac 麦克风听会议室”;没允许麦克风时提示去设置,电脑声音照常在记。"
+ },
+ {
+ "kind": "improved",
+ "platforms": [
+ "mac"
+ ],
+ "title": "听会议室时外接麦克风被拔掉,知了自动改用剩下的麦克风,并在面板上说一声。",
+ "text": "一个麦克风都没剩时,电脑和会议室改成只听电脑,只听会议室就先暂停;原来会悄悄换到系统默认输入,可能是耳机或虚拟麦克风。"
}
]
},