知了 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: the room mic no longer goes silent when the system input is a virtual mic with a different format
wquguru813bc64fce00
diff --git a/Sources/Cicada/RoomMic.swift b/Sources/Cicada/RoomMic.swiftindex 167fad2..298214e 100644--- a/Sources/Cicada/RoomMic.swift+++ b/Sources/Cicada/RoomMic.swift@@ -218,8 +218,10 @@ final class RoomMic: AudioSource {startedAt = Date()AudioDevices.pinInput(engine, to: device)let input = engine.inputNode- let format = input.outputFormat(forBus: 0)- guard format.sampleRate > 0,+ // The hardware format: after pinning, the client format can still be the system mic's,+ // and a tap in that format raises an Objective-C exception (issue #12).+ let format = input.inputFormat(forBus: 0)+ guard format.sampleRate > 0, format.channelCount > 0,let mono = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: format.sampleRate, channels: 1, interleaved: false) else {throw NSError(domain: "RoomMic", code: -1, userInfo: [NSLocalizedDescriptionKey: L("没有可用的麦克风")])}diff --git a/Tests/CicadaTests/SpeakMicTests.swift b/Tests/CicadaTests/SpeakMicTests.swiftindex 8d6a62f..7738962 100644--- a/Tests/CicadaTests/SpeakMicTests.swift+++ b/Tests/CicadaTests/SpeakMicTests.swift@@ -16,17 +16,23 @@ private final class MicFrames: RecognitionStream, @unchecked Sendable {func cancel() async {}}-@MainActor @Suite struct SpeakMicTests {- // Requires microphone permission and a virtual system input with a different format from- // the real mic. Opt in locally: CI has neither these devices nor microphone permission.- @Test(.enabled(if: ProcessInfo.processInfo.environment["CICADA_TEST_MIC"] == "1"))- func repeatedPressesCaptureFromTheRealMic() async throws {+// Requires microphone permission and a virtual system input with a different format from+// the real mic. Opt in locally: CI has neither these devices nor microphone permission.+@MainActor @Suite(.enabled(if: ProcessInfo.processInfo.environment["CICADA_TEST_MIC"] == "1"))+struct SpeakMicTests {+ /// The system input (BlackHole) and this Mac's own microphone.+ private func devices() throws -> (original: OutputDevice, mic: OutputDevice) {let original = try #require(AudioDevices.defaultInput)try #require(original.isVirtualMic, "Select BlackHole as the system input before this hardware test")// A continuity microphone may be listed first: hardware tests must only open this Mac's mic.- let device = try #require(AudioDevices.inputs().first {+ let mic = try #require(AudioDevices.inputs().first {AudioDevices.transport($0.id) == kAudioDeviceTransportTypeBuiltIn})+ return (original, mic)+ }++ @Test func repeatedPressesCaptureFromTheRealMic() async throws {+ let (original, device) = try devices()let frames = MicFrames()let previousHost = Recognition.hostRecognition.host = { _, _ in frames }@@ -48,4 +54,16 @@ private final class MicFrames: RecognitionStream, @unchecked Sendable {}#expect(AudioDevices.defaultInput?.uid == original.uid)}++ @Test func roomMicCapturesFromTheRealMic() async throws {+ let (original, device) = try devices()+ let room = RoomMic(device: device)+ let frames = MicFrames()+ room.onAudio = { frames.append($0) }+ try room.start()+ try await Task.sleep(for: .milliseconds(500))+ room.stop()+ #expect(frames.count > 0)+ #expect(AudioDevices.defaultInput?.uid == original.uid)+ }}