知了 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
feat(ios): a meeting nobody speaks in ends by itself after a countdown, and saving meeting audio can be turned off
wquguru4d65e4164360
diff --git a/ios/Sources/Cicada/AutoEnd.swift b/ios/Sources/Cicada/AutoEnd.swiftnew file mode 100644index 0000000..2a892a4--- /dev/null+++ b/ios/Sources/Cicada/AutoEnd.swift@@ -0,0 +1,114 @@+import SwiftUI++/// 结束会议 by itself, as on the Mac and Android: the shared `MeetingEndWatch` ticked every two+/// seconds (every second while counting down). iOS can't see another app's microphone, so only+/// silence counts: nothing recognised for 多久算没人说话 → the countdown, then the meeting ends+/// where the words did and its notes are written. A meeting started from the Action Button or the+/// lock screen and forgotten would otherwise listen to an empty room for hours.+extension AppModel {+ var endConfig: MeetingEndWatch.Config {+ let d = UserDefaults.standard+ return MeetingEndWatch.Config(+ followApps: false,+ silence: MeetingEndWatch.Silence(rawValue: d.string(forKey: Pref.silenceEnd) ?? "prompt") ?? .prompt,+ silenceAfter: endTimesOverride?.0 ?? d.double(forKey: Pref.silenceMinutes) * 60,+ countdown: endTimesOverride?.1 ?? 60)+ }++ func watchEnd() {+ guard endWatch == nil else { return }+ endWatch = MeetingEndWatch(config: endConfig, start: Date())+ endHeard = (room.lines.count, room.draft)+ scheduleEndTick(2)+ }++ func stopWatchingEnd() {+ endTimer?.invalidate()+ endTimer = nil+ endWatch = nil+ if ending != nil { ending = nil }+ }++ private func scheduleEndTick(_ seconds: TimeInterval) {+ endTimer?.invalidate()+ endTimer = Timer.scheduledTimer(withTimeInterval: seconds, repeats: false) { [weak self] _ in+ MainActor.assumeIsolated { self?.endTick() }+ }+ }++ private func endTick() {+ guard var w = endWatch, room.isRunning else { return }+ let now = Date()+ w.config = endConfig+ // Words, not sound: a new line, or the line being said changing (paused: nothing counts).+ if !room.paused, room.lines.count != endHeard.lines || (room.draft != endHeard.draft && !room.draft.isEmpty) {+ w.heard(at: now)+ }+ endHeard = (room.lines.count, room.draft)+ // Paused by the user: they chose to stop listening for now, so it isn't silence.+ if room.paused { w.keepGoing(at: now) }+ let reason = w.tick(at: now, calls: [:], said: !room.lines.isEmpty)+ endWatch = w+ if w.pending != ending {+ if let p = w.pending { debugLog("meeting end: pending \(p.reason), ends in \(Int(p.deadline.timeIntervalSince(now))) s") }+ else if ending != nil { debugLog("meeting end: pending cleared") }+ ending = w.pending+ }+ if let reason { autoEnd(reason, w); return }+ scheduleEndTick(w.pending != nil ? 1 : 2)+ }++ /// 继续记录 on the countdown.+ func keepRecording() {+ endWatch?.keepGoing(at: Date())+ ending = nil+ debugLog("meeting end: kept going")+ }++ /// Ends where the meeting really ended: a little after the last words.+ private func autoEnd(_ reason: MeetingEndWatch.Reason, _ w: MeetingEndWatch) {+ stopWatchingEnd()+ if reason == .nobodySpoke {+ debugLog("meeting end: nobody spoke for \(Int(w.config.silenceAfter)) s, stopped")+ room.stop()+ return+ }+ debugLog("meeting end: ended by itself (\(reason)), end time \(Int(Date().timeIntervalSince(w.lastSpeech) - 5)) s ago")+ room.stop(endedAt: w.lastSpeech.addingTimeInterval(5))+ }++ func endingTitle(_ p: MeetingEndWatch.Pending) -> String {+ L("已经 \(max(1, Int((endConfig.silenceAfter / 60).rounded()))) 分钟没人说话")+ }+}++/// The countdown above 正在听's pages: 已经 10 分钟没人说话 · 60 秒后结束会议并整理纪要 · 继续记录.+struct EndingStrip: View {+ @EnvironmentObject var model: AppModel++ var body: some View {+ if let p = model.ending {+ HStack(spacing: 12) {+ VStack(alignment: .leading, spacing: 2) {+ Text(verbatim: model.endingTitle(p)).font(.subheadline.weight(.semibold)).foregroundStyle(Ink.ink)+ // Counts down by itself; the watch decides when it is over.+ TimelineView(.periodic(from: .now, by: 1)) { t in+ Text(L("\(max(0, Int(p.deadline.timeIntervalSince(t.date).rounded()))) 秒后结束会议并整理纪要"))+ .font(.footnote).foregroundStyle(Ink.secondary).monospacedDigit()+ }+ }+ Spacer(minLength: 8)+ Button { model.keepRecording() } label: {+ Text("继续记录").font(.subheadline.weight(.semibold)).foregroundStyle(.white)+ .padding(.horizontal, 14).frame(minHeight: 36)+ .background(Ink.ink, in: Capsule())+ }+ .buttonStyle(.plain)+ .frame(minHeight: 44)+ }+ .padding(.leading, 16).padding(.trailing, 10).padding(.vertical, 8)+ .background(Color.white, in: RoundedRectangle(cornerRadius: 18, style: .continuous))+ .overlay { RoundedRectangle(cornerRadius: 18, style: .continuous).strokeBorder(Ink.accent.opacity(0.35), lineWidth: 1.5) }+ }+ }+}diff --git a/ios/Sources/Cicada/CicadaApp.swift b/ios/Sources/Cicada/CicadaApp.swiftindex 8bf6fa9..cb854fc 100644--- a/ios/Sources/Cicada/CicadaApp.swift+++ b/ios/Sources/Cicada/CicadaApp.swift@@ -46,6 +46,11 @@ enum Pref {static let myLang = "iosMyLang"/// 第一次打开's three steps are done (or skipped).static let welcomed = "iosWelcomed"+ /// 保存会议录音, the Mac's and Android's recordAudio.+ static let recordAudio = "recordAudio"+ /// 没人说话时: "prompt" (count down, then end), "end" or "off"; 多久算没人说话 in minutes. The Mac's names.+ static let silenceEnd = "silenceEnd"+ static let silenceMinutes = "silenceMinutes"static var speakerMode: Bool { UserDefaults.standard.string(forKey: hear) == "speaker" }/// 对方说 on iOS: one language the user picks (detecting it comes later); the Mac's "auto" reads as English.@@ -145,6 +150,13 @@ final class AppModel: ObservableObject {/// 词表 and 改正听错的词, the Mac's own engines.let vocabulary = Vocabulary(url: Vocabulary.defaultURL)lazy var fixes = makeFixes()+ /// 结束会议 by itself (AutoEnd.swift): the countdown on screen, and the watch behind it.+ @Published var ending: MeetingEndWatch.Pending?+ var endWatch: MeetingEndWatch?+ var endTimer: Timer?+ var endHeard = (lines: 0, draft: "")+ /// Debug (`endTimes:<silence>,<countdown>`): seconds instead of minutes, to test it.+ var endTimesOverride: (Double, Double)?/// 正在听's 字幕 / 纪要 switch, so a debug command can flip it.@Published var livePage: LivePage = .subtitles/// The record page's picked speaker (scheme A: only they are drawn in ink).@@ -181,7 +193,8 @@ final class AppModel: ObservableObject {init() {UserDefaults.standard.register(defaults: [Pref.source: "en-US", Pref.voices: true, Pref.model: LingClient.models[0], Pref.notesLanguage: "mine",- Pref.fixMisheard: true, Pref.askNames: true])+ Pref.fixMisheard: true, Pref.askNames: true, Pref.recordAudio: true,+ Pref.silenceEnd: "prompt", Pref.silenceMinutes: 10.0])TranscriptExport.voices = UserDefaults.standard.bool(forKey: Pref.voices)// Ling only for now: the Mac's other services (AIProvider) come to iOS with their settings.ling.config = {@@ -256,8 +269,10 @@ final class AppModel: ObservableObject {pip.setEnabled(room.isRunning && room.speakerMode)if room.isRunning, let start = room.startedAt {liveActivity.start(startedAt: start, pair: Pref.pairText(room.languagePair.source, room.languagePair.target))+ watchEnd()} else if !room.isRunning {liveActivity.end()+ stopWatchingEnd()}}diff --git a/ios/Sources/Cicada/LiveViews.swift b/ios/Sources/Cicada/LiveViews.swiftindex 538d8a4..1a26835 100644--- a/ios/Sources/Cicada/LiveViews.swift+++ b/ios/Sources/Cicada/LiveViews.swift@@ -328,6 +328,7 @@ struct LivePad: View {var body: some View {VStack(spacing: 0) {+ EndingStrip().frame(maxWidth: 560).padding(.horizontal, 20).padding(.top, 18)TranslateDownCard().frame(maxWidth: 560).padding(.horizontal, 20).padding(.top, 18)if let id = room.sessionID {FixAskCard(fixes: model.fixes, session: id).frame(maxWidth: 560).padding(.horizontal, 20).padding(.top, 18)diff --git a/ios/Sources/Cicada/RoomListen.swift b/ios/Sources/Cicada/RoomListen.swiftindex 1eb7f7b..96515b0 100644--- a/ios/Sources/Cicada/RoomListen.swift+++ b/ios/Sources/Cicada/RoomListen.swift@@ -137,7 +137,9 @@ final class RoomListen: ObservableObject {audio.voices = voicesaudio.mix = speakerModeaudio.onInterruption = { [weak self] began in self?.interrupted(began) }- try audio.start(recognizer: stream, recording: AudioFileWriter.partial(store.systemAudioURL(s.id)))+ // 保存会议录音 off: nothing is written; voiceprints still read the last minute in memory.+ let keep = UserDefaults.standard.bool(forKey: Pref.recordAudio)+ try audio.start(recognizer: stream, recording: keep ? AudioFileWriter.partial(store.systemAudioURL(s.id)) : nil)heardVoice = falseaudio.onLevel = { [weak self] v inguard let self, !self.paused else { return }@@ -250,7 +252,8 @@ final class RoomListen: ObservableObject {onStateChange?()}- func stop() {+ /// `endedAt`: when the meeting really ended (结束会议 by itself: a little after the last words).+ func stop(endedAt: Date? = nil) {guard isRunning else { return }isRunning = falsepaused = false@@ -265,7 +268,7 @@ final class RoomListen: ObservableObject {reader?.cancel()notes.finish()// A meeting with no line is kept only when the microphone heard voices (its recording holds them).- store.end(heardSpeech: heardVoice)+ store.end(at: endedAt, heardSpeech: heardVoice)debugLog("room: stopped lines=\(lines.count)")sessionID = nilstartedAt = nil@@ -402,7 +405,7 @@ final class RoomAudio: @unchecked Sendable {var fedSeconds: Double { queue.sync { fed } }- func start(recognizer: RecognitionStream, recording: URL) throws {+ func start(recognizer: RecognitionStream, recording: URL?) throws {let session = AVAudioSession.sharedInstance()// .measurement: no voice processing, which would duck what the room says as "echo".// .defaultToSpeaker sends every app's sound to the speaker, not the earpiece, while we record.diff --git a/ios/Sources/Cicada/SettingsView.swift b/ios/Sources/Cicada/SettingsView.swiftindex aef9efa..60ec8d4 100644--- a/ios/Sources/Cicada/SettingsView.swift+++ b/ios/Sources/Cicada/SettingsView.swift@@ -11,6 +11,9 @@ struct SettingsView: View {@AppStorage(Pref.model) private var aiModel = LingClient.models[0]@AppStorage(Pref.target) private var target = "system"@AppStorage(Pref.voices) private var voices = true+ @AppStorage(Pref.recordAudio) private var recordAudio = true+ @AppStorage(Pref.silenceEnd) private var silenceEnd = "prompt"+ @AppStorage(Pref.silenceMinutes) private var silenceMinutes = 10.0@AppStorage(Pref.notesLanguage) private var notesLanguage = "mine"var body: some View {@@ -65,16 +68,52 @@ struct SettingsView: View {.labelsHidden().tint(Ink.ok)}+ Hairline()+ helped(row(Text("保存会议录音")) {+ Toggle(isOn: $recordAudio) { Text("保存会议录音") }+ .labelsHidden()+ .tint(Ink.ok)+ }, L("只存在这台手机上,会议记录里能回放原声"))}- SectionLabel(text: L("纪要"))+ // As on the Mac and Android, minus 会议应用挂断后结束: iOS can't see another app's microphone.+ SectionLabel(text: L("结束会议"))Card {- row(Text("纪要语言")) {- Picker(selection: $notesLanguage) {- Text(L("我的语言 · \(targetName(Pref.targetCode))")).tag("mine")- Text("会议原文").tag("source")- } label: { Text("纪要语言") }+ helped(row(Text("没人说话时")) {+ Picker(selection: $silenceEnd) {+ Text("提醒后结束").tag("prompt")+ Text("直接结束").tag("end")+ Text("一直记录").tag("off")+ } label: { Text("没人说话时") }.pickerStyle(.menu).tint(Ink.secondary)+ }, L("按识别出的话算,背景音乐不算"))+ if silenceEnd != "off" {+ Hairline()+ row(Text("多久算没人说话")) {+ Picker(selection: $silenceMinutes) {+ ForEach([5.0, 10, 15, 30], id: \.self) { Text(L("\(Int($0)) 分钟")).tag($0) }+ } label: { Text("多久算没人说话") }+ .pickerStyle(.menu)+ .tint(Ink.secondary)+ }+ }+ }+ SectionLabel(text: L("纪要"))+ Card {+ row(Text("纪要语言")) {+ // The menu names the language; the row only the choice, so it fits on one line in English.+ Menu {+ Picker(selection: $notesLanguage) {+ Text(L("我的语言 · \(targetName(Pref.targetCode))")).tag("mine")+ Text("会议原文").tag("source")+ } label: { Text("纪要语言") }+ } label: {+ HStack(spacing: 4) {+ Text(notesLanguage == "source" ? L("会议原文") : L("我的语言")).lineLimit(1)+ Image(systemName: "chevron.up.chevron.down").font(.caption2.weight(.semibold))+ }+ .foregroundStyle(Ink.secondary)+ }}}SectionLabel(text: L("面对面"))