知了 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: when Cicada isn't allowed on the local network, AI Service says so and opens the right System Settings pane instead of showing a dead server
wquguru13fb423d5f86
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.stringsindex 0a37105..7d275b2 100644--- a/Resources/en.lproj/Localizable.strings+++ b/Resources/en.lproj/Localizable.strings@@ -1218,3 +1218,9 @@"听不到会议室 · 麦克风没允许" = "Can't hear the room · microphone not allowed";"听不到会议室" = "Can't hear the room";"麦克风没允许,现在只在记电脑声音。点按去设置" = "The microphone isn't allowed, so only the Mac's audio is being recorded. Click to open Settings";+"知了没有本地网络权限,连不上 %@。" = "Cicada isn't allowed on the local network, so it can't reach %@.";+"知了没有本地网络权限,连不上 %@,开会时先用本机识别。" = "Cicada isn't allowed on the local network, so it can't reach %@. Meetings use this Mac's recognition for now.";+"打开系统设置" = "Open System Settings";+"知了没有本地网络权限" = "Cicada isn't allowed on the local network";+"没有本地网络权限" = "Local network not allowed";+"局域网里的服务器:macOS 会问一次能否访问本地网络,点“允许”。" = "A server on your local network: macOS asks once whether Cicada may use the local network. Click Allow.";diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.stringsindex 6038543..2b50859 100644--- a/Resources/ja.lproj/Localizable.strings+++ b/Resources/ja.lproj/Localizable.strings@@ -1218,3 +1218,9 @@"听不到会议室 · 麦克风没允许" = "会議室が聞こえません · マイクが未許可";"听不到会议室" = "会議室が聞こえません";"麦克风没允许,现在只在记电脑声音。点按去设置" = "マイクが許可されていないため、Mac の音声だけを記録しています。クリックして設定を開く";+"知了没有本地网络权限,连不上 %@。" = "Cicada にローカルネットワークの許可がないため、%@ に接続できません。";+"知了没有本地网络权限,连不上 %@,开会时先用本机识别。" = "Cicada にローカルネットワークの許可がないため、%@ に接続できません。会議ではこの Mac の認識を使います。";+"打开系统设置" = "システム設定を開く";+"知了没有本地网络权限" = "Cicada にローカルネットワークの許可がありません";+"没有本地网络权限" = "ローカルネットワーク未許可";+"局域网里的服务器:macOS 会问一次能否访问本地网络,点“允许”。" = "ローカルネットワーク上のサーバーです。macOS がローカルネットワークへのアクセスを一度確認するので、「許可」を押してください。";diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.stringsindex 07adb1b..d015ba9 100644--- a/Resources/ko.lproj/Localizable.strings+++ b/Resources/ko.lproj/Localizable.strings@@ -1218,3 +1218,9 @@"听不到会议室 · 麦克风没允许" = "회의실을 들을 수 없음 · 마이크 미허용";"听不到会议室" = "회의실을 들을 수 없음";"麦克风没允许,现在只在记电脑声音。点按去设置" = "마이크가 허용되지 않아 Mac 소리만 기록하고 있습니다. 클릭하여 설정 열기";+"知了没有本地网络权限,连不上 %@。" = "Cicada에 로컬 네트워크 권한이 없어 %@에 연결할 수 없습니다.";+"知了没有本地网络权限,连不上 %@,开会时先用本机识别。" = "Cicada에 로컬 네트워크 권한이 없어 %@에 연결할 수 없습니다. 회의에서는 이 Mac의 인식을 사용합니다.";+"打开系统设置" = "시스템 설정 열기";+"知了没有本地网络权限" = "Cicada에 로컬 네트워크 권한이 없습니다";+"没有本地网络权限" = "로컬 네트워크 권한 없음";+"局域网里的服务器:macOS 会问一次能否访问本地网络,点“允许”。" = "로컬 네트워크의 서버입니다. macOS가 로컬 네트워크 접근을 한 번 묻습니다. '허용'을 누르세요.";diff --git a/Sources/Cicada/AICheck.swift b/Sources/Cicada/AICheck.swiftindex ebf6d79..6170895 100644--- a/Sources/Cicada/AICheck.swift+++ b/Sources/Cicada/AICheck.swift@@ -47,6 +47,9 @@ struct AICheck: Equatable {/// The newest result came from a real request in a meeting, not from a check.var passive = falsevar proxy: ProxyHint?+ /// The service is on the local network and macOS holds the connection back: the local network+ /// permission is off, so the fix is in System Settings, not the server.+ var localNetworkDenied = false/// OpenRouter only: dollars left (the smaller of the key's limit and the account's credits).var balance: Double?/// A custom service: how long one real sentence took, and whether the model thought first.@@ -66,6 +69,8 @@ struct AICheck: Equatable {enum Hearing: Equatable {case ok(seconds: Double)case unreachable+ /// Its server is on the local network and the local network permission is off.+ case localNetworkDeniedcase fail(code: Int?)var ok: Bool { if case .ok = self { true } else { false } }}@@ -107,7 +112,7 @@ struct AICheck: Equatable {else if after { steps[i].state = .skipped }else if reached, !Self.isOK(steps[i].state) { steps[i].state = .ok(seconds: nil) }}- if reason != .unreachable { proxy = nil }+ if reason != .unreachable { proxy = nil; localNetworkDenied = false }}/// One request proved every step up to `step` (a chat proves the address, the key and the@@ -125,6 +130,12 @@ struct AICheck: Equatable {}}proxy = nil+ localNetworkDenied = false+ }++ /// Something only System Settings › Privacy & Security › Local Network fixes.+ var needsLocalNetwork: Bool {+ (failure?.reason == .unreachable && localNetworkDenied) || hear == .localNetworkDenied}static func isOK(_ s: State) -> Bool { if case .ok = s { true } else { false } }@@ -197,6 +208,7 @@ struct AICheck: Equatable {func message(service: String, host: String, model: String) -> String? {guard let f = failure else { return busy ? L("\(service) 现在很忙,key 没问题。开会时会自动重试。") : nil }switch f.reason {+ case .unreachable where localNetworkDenied: return L("知了没有本地网络权限,连不上 \(host)。")case .unreachable: return L("这台 Mac 访问不到 \(host)。")case .badAddress: return L("地址要用 https;这台 Mac 和局域网里的服务可以用 http。")case .invalidKey: return L("\(service) 说这个 key 无效,可能没复制全,或已删除。")@@ -221,6 +233,7 @@ struct AICheck: Equatable {func hearLine(host: String, model: String) -> String? {switch hear {case .unreachable?: return L("这台 Mac 访问不到 \(host),开会时先用本机识别。")+ case .localNetworkDenied?: return L("知了没有本地网络权限,连不上 \(host),开会时先用本机识别。")case .fail(let code)?: return L("\(model) 没接受音频(HTTP \(code ?? 0)),开会时先用本机识别。")default: return nil}@@ -257,7 +270,7 @@ struct AICheck: Equatable {case .untested: "untested"}return "\(s.id.rawValue)=\(v)"- }.joined(separator: " ") + (proxy.map { " proxy=\($0)" } ?? "") + (balance.map { " balance=\(String(format: "%.2f", $0))" } ?? "")+ }.joined(separator: " ") + (proxy.map { " proxy=\($0)" } ?? "") + (localNetworkDenied ? " localNetwork=denied" : "") + (balance.map { " balance=\(String(format: "%.2f", $0))" } ?? "")+ (passive ? " passive" : "")+ (translate.map { " translate=\(String(format: "%.1f", $0.seconds))s\($0.thinks ? " thinks" : "")" } ?? "")+ (hear.map { " hear=\($0)" } ?? "")diff --git a/Sources/Cicada/AICheckView.swift b/Sources/Cicada/AICheckView.swiftindex 4183955..01e20ae 100644--- a/Sources/Cicada/AICheckView.swift+++ b/Sources/Cicada/AICheckView.swift@@ -85,6 +85,8 @@ struct AICheckSteps: View {let p = ling.providerlet recheck = recheckInStep ? [Action(title: L("重新检查")) { Task { await ling.check() } }] : []switch f.reason {+ case .unreachable where check.localNetworkDenied:+ return [Action(title: L("打开系统设置")) { model.openLocalNetworkSettings() }] + recheckcase .unreachable:// A proxy has nothing to do with a server on this Mac or the local network.if AIProvider.isNearby(host) { return recheck }@@ -154,7 +156,7 @@ struct AIServiceStrip: View {guard let f = c.failure else {return c.balanceLine(service: name).map { ($0, L("用完后纪要会停下")) }}- if f.reason == .unreachable { return (L("连不上 \(name)"), stopped) }+ if f.reason == .unreachable { return (c.localNetworkDenied ? L("知了没有本地网络权限") : L("连不上 \(name)"), stopped) }return Self.blocking(ling, textModel: model.settings.textModel).map { ($0, stopped) }}diff --git a/Sources/Cicada/AISettings.swift b/Sources/Cicada/AISettings.swiftindex 8e5cf1f..dfabf65 100644--- a/Sources/Cicada/AISettings.swift+++ b/Sources/Cicada/AISettings.swift@@ -107,6 +107,18 @@ struct AISettingsView: View {.buttonStyle(.plain)}+ /// Under an address on the local network (not this Mac): macOS asks once before the first+ /// connection, and a "Don't Allow" there reads like a dead server.+ @ViewBuilder private func localNetworkNote(_ address: String) -> some View {+ // Once it said no, macOS won't ask again: the check's own line says what to do then.+ if !ling.aiCheck.needsLocalNetwork, let host = AIProvider.customBase(address)?.host,+ AIProvider.isNearby(host), !AIProvider.isLocal(host) {+ Text("局域网里的服务器:macOS 会问一次能否访问本地网络,点“允许”。")+ .font(.system(size: 11)).foregroundStyle(Palette.tertiary)+ .fixedSize(horizontal: false, vertical: true).padding(.leading, 42)+ }+ }+private var textHost: String { AIProvider.customBase(baseDraft)?.host ?? settings.aiConfig.base?.host ?? "" }@ViewBuilder private var textSection: some View {@@ -123,6 +135,8 @@ struct AISettingsView: View {if !baseDraft.isEmpty, AIProvider.customBase(baseDraft) == nil {Text("地址要用 https;这台 Mac 和局域网里的服务可以用 http。").font(.system(size: 11)).foregroundStyle(Palette.error).padding(.leading, 42)+ } else {+ localNetworkNote(baseDraft)}HStack(spacing: 8) {Text("模型").font(.system(size: 12)).foregroundStyle(Palette.secondary).frame(minWidth: 34, alignment: .leading).fixedSize()@@ -224,6 +238,7 @@ struct AISettingsView: View {settings.aiCustomVoiceBase = $0model.applyAIService()}+ localNetworkNote(settings.aiCustomVoiceBase)}.padding(.leading, 34).padding(.trailing, 16).padding(.bottom, 14)}@@ -263,10 +278,17 @@ struct AISettingsView: View {settings.aiCustomHearBase = $0model.applyAIService()}+ localNetworkNote(settings.aiCustomHearBase)if hearModel.isEmpty {Text("填上模型才会用它识别。").font(.system(size: 12)).foregroundStyle(Palette.warn)} else if let line = ling.aiCheck.hearLine(host: host, model: hearModel) {Text(line).font(.system(size: 12)).foregroundStyle(Palette.error).fixedSize(horizontal: false, vertical: true)+ if hear == .localNetworkDenied {+ HStack(spacing: 8) {+ SoftButton(L("打开系统设置"), dark: true) { model.openLocalNetworkSettings() }+ SoftButton(L("重新检查")) { Task { await ling.check() } }+ }+ }} else if case .ok(let s)? = hear {Text(L("听一秒音频 \(String(format: "%.1f", s)) 秒")).font(.system(size: 11)).foregroundStyle(Palette.tertiary)}@@ -441,7 +463,7 @@ struct AISettingsView: View {// Named after the step that failed: a missing model is not a connection problem.if let f = ling.aiCheck.failure, f.reason != .busy, !ling.aiCheck.running {switch f.step {- case .reach: return L("暂时连不上")+ case .reach: return ling.aiCheck.localNetworkDenied ? L("没有本地网络权限") : L("暂时连不上")case .key: return L("这个 key 用不了")case .text: return L("模型用不了")}diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex 8781bad..d6a4d28 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -234,6 +234,7 @@ final class AppModel: ObservableObject {}ling.onCall = { [weak self] in self?.diagnostics.record($0) }ling.proxyHint = { await ProxyProbe.hint() }+ ling.localNetworkProbe = { await LocalNetworkProbe.denied($0) }watchNetwork()translator.onDraft = { [weak self] in self?.diagnostics.recordDraft(seconds: $0, ok: $1) }@@ -627,6 +628,8 @@ final class AppModel: ObservableObject {}}+ func openLocalNetworkSettings() { openSettingsPane("Privacy_LocalNetwork") }+private func openSettingsPane(_ anchor: String) {if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?\(anchor)") {NSWorkspace.shared.open(url)@@ -1093,6 +1096,10 @@ final class AppModel: ObservableObject {}}networkMonitor.start(queue: DispatchQueue(label: "cicada.ai-network"))+ // Turning the local network permission on doesn't change the path: look again on coming back.+ NotificationCenter.default.addObserver(forName: NSApplication.didBecomeActiveNotification, object: nil, queue: .main) { [weak self] _ in+ MainActor.assumeIsolated { self?.ling.recheckLocalNetwork() }+ }}/// One click on "换成推荐的": the service's first recommended text model, then a fresh check.@@ -1900,9 +1907,14 @@ final class AppModel: ObservableObject {+ " check=[\(ling.aiCheck.summary)]")case "aiCheckSim":// aiCheckSim:<reason|lowBalance|off>: every check ends this way (screenshots of each state).- ling.simulateCheck = AICheck.Reason(rawValue: arg)+ // localNetwork: can't reach it, and the local network permission is off.+ ling.simulateCheck = arg == "localNetwork" ? .unreachable : AICheck.Reason(rawValue: arg)ling.simulateBalance = arg == "lowBalance" ? 0.4 : nil+ ling.simulateLocalNetwork = arg == "localNetwork"Task { await ling.check() }+ case "localNetworkProbe":+ // localNetworkProbe:<url>: whether the local network permission holds back a connection to it (log).+ if let url = URL(string: arg) { Task { _ = await LocalNetworkProbe.denied(url) } }// AI service: aiProvider:<ling|openrouter|zenmux|openai|custom>, aiTextModel:<id>, aiVoiceModel:<id|"">,// aiCustomBase:<url>, aiCustomVoiceBase:<url|"">, aiCustomVoice:<name>, aiCustomHearModel:<name>,// aiCustomHearBase:<url|"">, aiCustomRecognize:on|off.diff --git a/Sources/Cicada/Ling.swift b/Sources/Cicada/Ling.swiftindex 733f646..bdaead6 100644--- a/Sources/Cicada/Ling.swift+++ b/Sources/Cicada/Ling.swift@@ -168,11 +168,16 @@ final class LingClient: ObservableObject {private var listed: Set<String>?/// Reads this device's proxy settings to word the "can't reach" hint (never used to connect).var proxyHint: (() async -> AICheck.ProxyHint)?+ /// Whether the local network permission holds back a connection to this address (Mac only;+ /// asked only after a request to a local network server failed).+ var localNetworkProbe: ((URL) async -> Bool)?/// Debug control only: the next checks end this way (for screenshots of every state).var simulateCheck: AICheck.Reason?/// Debug control only: report this OpenRouter balance instead of the real one.var simulateBalance: Double?+ /// Debug control only: a server that can't be reached is held back by the local network permission.+ var simulateLocalNetwork = false/// The service in use, its address and models. Set by the app from settings.var config: () -> AIConfig = { AIConfig(provider: .ling, base: AIProvider.ling.base, textModel: "Ling-3.1-flash",voiceModel: "Ming-3.0-tts-0.5B", voiceBase: AIProvider.ling.base) }@@ -331,7 +336,10 @@ final class LingClient: ObservableObject {do { _ = try await postChat(json, key: key, timeout: 30) } catch Failure.http(let code) {r.fail(.text, .noJSON, code: code)}- if r.failure == nil, c.transcribes { r.hear = await checkHearing(c, key: key) }+ if r.failure == nil, c.transcribes {+ r.hear = await checkHearing(c, key: key)+ if r.hear == .unreachable, await localNetworkDenied(c.hearBase) { r.hear = .localNetworkDenied }+ }}} catch let failure as Failure {if let (step, reason, code) = AICheck.classify(failure, at: AICheck.firstStep(c.provider.id)) {@@ -356,7 +364,8 @@ final class LingClient: ObservableObject {private func finishCheck(_ result: AICheck, _ c: AIConfig, _ generation: Int) async {var r = result- if r.failure?.reason == .unreachable, r.proxy == nil { r.proxy = await proxyHint?() }+ if r.failure?.reason == .unreachable, !r.localNetworkDenied { r.localNetworkDenied = await localNetworkDenied(c.base) }+ if r.failure?.reason == .unreachable, r.proxy == nil, !r.localNetworkDenied { r.proxy = await proxyHint?() }guard generation == checkGeneration else {debugLog("ai \(c.provider.id.rawValue): an older check finished late, dropped")return@@ -421,16 +430,40 @@ final class LingClient: ObservableObject {let wasUnreachable = aiCheck.failure?.reason == .unreachabler.at = Date()r.passive = true- if r.failure?.reason != .unreachable { r.proxy = nil }+ if r.failure?.reason != .unreachable { r.proxy = nil; r.localNetworkDenied = false }if r.steps == aiCheck.steps, aiCheck.passive { aiCheck.at = r.at; return }aiCheck = rsyncKeyState()debugLog("ai: from a real request → \(r.summary)")- if r.failure?.reason == .unreachable, !wasUnreachable, let proxyHint {- Task { let hint = await proxyHint(); if aiCheck.failure?.reason == .unreachable { aiCheck.proxy = hint } }+ if r.failure?.reason == .unreachable, !wasUnreachable {+ let base = config().base+ Task {+ let denied = await localNetworkDenied(base)+ let hint = denied ? nil : await proxyHint?()+ guard aiCheck.failure?.reason == .unreachable else { return }+ aiCheck.localNetworkDenied = denied+ aiCheck.proxy = hint+ syncKeyState()+ }}}+ /// A server on the local network (not this Mac) that failed: is it the permission?+ private func localNetworkDenied(_ url: URL?) async -> Bool {+ if simulateLocalNetwork { return true }+ guard let url, let host = url.host, AIProvider.isNearby(host), !AIProvider.isLocal(host),+ let localNetworkProbe else { return false }+ return await localNetworkProbe(url)+ }++ /// Back from System Settings (or from the permission prompt): look again if the local network+ /// permission was what stopped it; turning it on doesn't change the network path.+ func recheckLocalNetwork() {+ guard hasKey, aiCheck.needsLocalNetwork, !aiCheck.running else { return }+ debugLog("ai: back while the local network was denied, checking again")+ Task { await check() }+ }+/// The network came back (or changed) while the service was unreachable: look again.func networkChanged() {guard hasKey, aiCheck.failure?.reason == .unreachable, !aiCheck.running else { return }diff --git a/Sources/Cicada/LocalNetwork.swift b/Sources/Cicada/LocalNetwork.swiftnew file mode 100644index 0000000..65d5d26--- /dev/null+++ b/Sources/Cicada/LocalNetwork.swift@@ -0,0 +1,46 @@+import Foundation+import Network++/// Tells "macOS won't let Cicada reach the local network" apart from "the server is down": both+/// fail a request the same way, but only one is fixed in System Settings. Asked only after a+/// request to a server on the local network failed, so it never brings up the permission prompt+/// for anyone who doesn't use one.+enum LocalNetworkProbe {+ /// The path to `url`'s host and port is held back because the local network permission is off.+ /// Nothing is sent; the connection is dropped as soon as the path is known, or after 2 s.+ static func denied(_ url: URL) async -> Bool {+ guard let host = url.host, !host.isEmpty,+ let port = NWEndpoint.Port(rawValue: UInt16(url.port ?? (url.scheme == "https" ? 443 : 80))) else { return false }+ let conn = NWConnection(host: NWEndpoint.Host(host), port: port, using: .tcp)+ let (denied, seen): (Bool, String) = await withCheckedContinuation { cont in+ let once = Once()+ func finish(_ seen: String) {+ guard once.take() else { return }+ let denied = conn.currentPath?.unsatisfiedReason == .localNetworkDenied+ conn.cancel()+ cont.resume(returning: (denied, seen))+ }+ conn.stateUpdateHandler = { state in+ switch state {+ case .ready, .waiting, .failed: finish("\(state)")+ default: break+ }+ }+ conn.start(queue: .global())+ DispatchQueue.global().asyncAfter(deadline: .now() + 2) { finish("timeout") }+ }+ debugLog("local network: \(host):\(port) denied=\(denied) (\(seen))")+ return denied+ }++ private final class Once: @unchecked Sendable {+ private let lock = NSLock()+ private var done = false+ func take() -> Bool {+ lock.lock(); defer { lock.unlock() }+ if done { return false }+ done = true+ return true+ }+ }+}diff --git a/Tests/CicadaTests/AICheckTests.swift b/Tests/CicadaTests/AICheckTests.swiftindex 5747192..b63ce04 100644--- a/Tests/CicadaTests/AICheckTests.swift+++ b/Tests/CicadaTests/AICheckTests.swift@@ -91,4 +91,23 @@ struct AICheckTests {m.fail(.text, .noModel, code: 404)#expect(m.message(service: "ZenMux", host: "zenmux.ai", model: "x/y")?.contains("x/y") == true)}++ @Test func theLocalNetworkPermissionIsItsOwnFixAndClearsOnTheNextResult() {+ var c = AICheck()+ c.fail(.reach, .unreachable)+ c.localNetworkDenied = true+ #expect(c.needsLocalNetwork)+ #expect(c.message(service: "s", host: "192.168.1.20", model: "m") == "知了没有本地网络权限,连不上 192.168.1.20。")+ #expect(c.proxyLine(service: "s", host: "192.168.1.20") == nil)+ c.pass(upTo: .text, seconds: 1)+ #expect(!c.localNetworkDenied && !c.needsLocalNetwork)+ c.fail(.reach, .unreachable)+ c.localNetworkDenied = true+ c.fail(.text, .noModel)+ #expect(!c.localNetworkDenied)+ var h = AICheck()+ h.hear = .localNetworkDenied+ #expect(h.needsLocalNetwork)+ #expect(h.hearLine(host: "192.168.1.20", model: "m")?.contains("本地网络") == true)+ }}