知了 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: a meeting's recording plays back in its record, a click on a line's time plays from there, and the line playing lights up and stays in view
wquguruacee2d251725
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.stringsindex 74e1c14..0e6c1d7 100644--- a/Resources/en.lproj/Localizable.strings+++ b/Resources/en.lproj/Localizable.strings@@ -1232,3 +1232,6 @@"在 Ling 开放平台点“创建令牌”,复制以 sk- 开头的那串。" = "On the Ling platform, click “Create token” and copy the string that starts with sk-.";"打开 Ling 开放平台 ↗" = "Open the Ling platform ↗";"Ling 提示此令牌无效,请检查是否复制完整,或重新创建一个" = "Ling says this token is invalid. Check that you copied all of it, or create a new one";+"找不到录音,没法播放" = "Can't find the recording to play";+"会议结束后可以回放录音" = "The recording plays back once the meeting ends";+"这场会议没存录音 ·" = "No recording of this meeting ·";diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.stringsindex 6551d4a..464c7b1 100644--- a/Resources/ja.lproj/Localizable.strings+++ b/Resources/ja.lproj/Localizable.strings@@ -1232,3 +1232,6 @@"在 Ling 开放平台点“创建令牌”,复制以 sk- 开头的那串。" = "Ling のプラットフォームで「トークンを作成」をクリックし、sk- で始まる文字列をコピーします。";"打开 Ling 开放平台 ↗" = "Ling プラットフォームを開く ↗";"Ling 提示此令牌无效,请检查是否复制完整,或重新创建一个" = "Ling がこのトークンは無効だと通知しました。全体をコピーできているか確認するか、新しく作成してください";+"找不到录音,没法播放" = "録音が見つからず再生できません";+"会议结束后可以回放录音" = "録音は会議が終わると再生できます";+"这场会议没存录音 ·" = "この会議の録音はありません ·";diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.stringsindex e6b077d..476d644 100644--- a/Resources/ko.lproj/Localizable.strings+++ b/Resources/ko.lproj/Localizable.strings@@ -1232,3 +1232,6 @@"在 Ling 开放平台点“创建令牌”,复制以 sk- 开头的那串。" = "Ling 개발자 플랫폼에서 “토큰 만들기”를 클릭하고 sk-로 시작하는 문자열을 복사하세요.";"打开 Ling 开放平台 ↗" = "Ling 개발자 플랫폼 열기 ↗";"Ling 提示此令牌无效,请检查是否复制完整,或重新创建一个" = "Ling에서 이 토큰이 유효하지 않다고 합니다. 전체를 복사했는지 확인하거나 새로 만드세요";+"找不到录音,没法播放" = "녹음이 없어 재생할 수 없음";+"会议结束后可以回放录音" = "회의가 끝나면 녹음을 다시 들을 수 있음";+"这场会议没存录音 ·" = "이 회의는 녹음이 없음 ·";diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.stringsindex a16fd57..201dad8 100644--- a/Resources/zh-Hans.lproj/Localizable.strings+++ b/Resources/zh-Hans.lproj/Localizable.strings@@ -1232,3 +1232,6 @@"在 Ling 开放平台点“创建令牌”,复制以 sk- 开头的那串。" = "在 Ling 开放平台点“创建令牌”,复制以 sk- 开头的那串。";"打开 Ling 开放平台 ↗" = "打开 Ling 开放平台 ↗";"Ling 提示此令牌无效,请检查是否复制完整,或重新创建一个" = "Ling 提示此令牌无效,请检查是否复制完整,或重新创建一个";+"找不到录音,没法播放" = "找不到录音,没法播放";+"会议结束后可以回放录音" = "会议结束后可以回放录音";+"这场会议没存录音 ·" = "这场会议没存录音 ·";diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex 7cb1bce..6793fef 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -1814,6 +1814,9 @@ final class AppModel: ObservableObject {try? png.write(to: URL(fileURLWithPath: arg))}case "mainShow": mainShow = arg+ case "play":+ // The shown record plays from <seconds>, as a click on a line's time does.+ if let t = Double(arg) { NotificationCenter.default.post(name: .debugPlay, object: t) }case "mainWindow":// Place the records window, floating above other apps' panels while testing clicks (no arg: back to normal).guard let w = NSApp.windows.first(where: { $0.contentView is NSHostingView<MainWindowView> }) else { break }diff --git a/Sources/Cicada/AudioRouter.swift b/Sources/Cicada/AudioRouter.swiftindex f131e6e..870de02 100644--- a/Sources/Cicada/AudioRouter.swift+++ b/Sources/Cicada/AudioRouter.swift@@ -78,6 +78,9 @@ final class AudioRouter: @unchecked Sendable {private var recordURL: URL?private var recorder: AVAudioFile?+ /// The recording keeps the meeting's clock (the lines' times): when it began and what is written.+ private var recordStart: Date?+ private var recordedFrames: AVAudioFramePosition = 0/// When a block counts as speech (pauses, language detection, the silence that ends a meeting).func setRoomGate(_ on: Bool) {@@ -130,6 +133,8 @@ final class AudioRouter: @unchecked Sendable {queue.sync {recorder = nil // closes the previous filerecordURL = url+ recordStart = url == nil ? nil : Date()+ recordedFrames = 0}}@@ -139,7 +144,32 @@ final class AudioRouter: @unchecked Sendable {recorder = AudioFileWriter.open(AudioFileWriter.partial(url), format: buffer.format)if recorder == nil { recordURL = nil; return }}+ // A process tap sends nothing while the Mac is silent: the gap goes in as silence, or every+ // later line's time would point past its words in the recording.+ if let recordStart {+ let rate = buffer.format.sampleRate+ let due = (Date().timeIntervalSince(recordStart) * rate).rounded() - Double(buffer.frameLength)+ let behind = due - Double(recordedFrames)+ if behind > rate / 4 { writeSilence(AVAudioFramePosition(behind), format: buffer.format) }+ }try? recorder?.write(from: buffer)+ recordedFrames += AVAudioFramePosition(buffer.frameLength)+ }++ private func writeSilence(_ frames: AVAudioFramePosition, format: AVAudioFormat) {+ let chunk = AVAudioFrameCount(format.sampleRate)+ guard let zeros = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: chunk) else { return }+ zeros.frameLength = chunk // sizes the buffers to the whole capacity before they are cleared+ for b in UnsafeMutableAudioBufferListPointer(zeros.mutableAudioBufferList) {+ if let data = b.mData { memset(data, 0, Int(b.mDataByteSize)) }+ }+ var left = frames+ while left > 0 {+ zeros.frameLength = AVAudioFrameCount(min(left, AVAudioFramePosition(chunk)))+ guard (try? recorder?.write(from: zeros)) != nil else { return }+ recordedFrames += AVAudioFramePosition(zeros.frameLength)+ left -= AVAudioFramePosition(zeros.frameLength)+ }}/// Seconds of audio given to the current analyzer, replay included: the analyzer's clock. Adiff --git a/Sources/Cicada/ImportViews.swift b/Sources/Cicada/ImportViews.swiftindex 2bf32b0..67dbd7c 100644--- a/Sources/Cicada/ImportViews.swift+++ b/Sources/Cicada/ImportViews.swift@@ -1,29 +1,39 @@import AVFoundationimport SwiftUI-/// Plays an imported record's original file, for the player bar and a click on a line's time.+/// Plays a record's audio, for the player bar and a click on a line's time: an imported record's+/// original file, or a meeting's own system.m4a.@MainActorfinal class RecordingPlayer: ObservableObject {@Published private(set) var sessionID: String?@Published private(set) var playing = false@Published private(set) var time = 0.0@Published private(set) var length = 0.0- /// The file was moved or deleted since it was imported.+ /// The file was moved or deleted since it was imported (or since the meeting was recorded).@Published private(set) var missing = false+ /// The meeting's own recording rather than an imported file: 找不到录音, not 找不到原文件.+ @Published private(set) var own = false@Published private(set) var rate: Float = 1private var player: AVPlayer?private var observer: Any?var ready: Bool { player != nil }- func load(_ s: Session?) {- guard s?.id != sessionID else { return }+ /// `recording`: the meeting's system.m4a, for a record that has no original file.+ func load(_ s: Session?, recording: URL? = nil) {+ // The same record again only while its recording was still being rewrapped.+ if let s, s.id == sessionID, player != nil || missing { return }unload()- guard let s, let path = s.sourcePath else { return }+ guard let s, let url = s.sourcePath.map({ URL(fileURLWithPath: $0) }) ?? recording else { return }sessionID = s.id+ own = s.sourcePath == nillength = s.duration- guard FileManager.default.fileExists(atPath: path) else { missing = true; return }- let p = AVPlayer(url: URL(fileURLWithPath: path))+ guard FileManager.default.fileExists(atPath: url.path) else {+ // Right after a meeting only the partial file is there until the rewrap ends: not missing yet.+ missing = !(own && FileManager.default.fileExists(atPath: AudioFileWriter.partial(url).path))+ return+ }+ let p = AVPlayer(url: url)player = pobserver = p.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 4), queue: .main) { [weak self] t inMainActor.assumeIsolated {@@ -35,6 +45,12 @@ final class RecordingPlayer: ObservableObject {}}+ /// The line the playhead is in, once playing has begun.+ func lineID(in s: Session) -> String? {+ guard s.id == sessionID, ready, playing || time > 0 else { return nil }+ return s.lines.last(where: { $0.t <= time + 0.2 })?.id+ }+func unload() {if let observer { player?.removeTimeObserver(observer) }player?.pause()@@ -43,6 +59,7 @@ final class RecordingPlayer: ObservableObject {sessionID = nilplaying = falsemissing = false+ own = falsetime = 0}@@ -211,7 +228,7 @@ struct RecordingPlayerBar: View {var body: some View {if player.missing {- Text("找不到原文件,没法播放").font(.system(size: 12)).foregroundStyle(Palette.secondary)+ Text(player.own ? L("找不到录音,没法播放") : L("找不到原文件,没法播放")).font(.system(size: 12)).foregroundStyle(Palette.secondary)} else if player.ready {HStack(spacing: 12) {Button { player.toggle() } label: {@@ -236,6 +253,8 @@ struct RecordingPlayerBar: View {}.buttonStyle(.plain).help(L("播放速度"))}+ .padding(.leading, 8).padding(.trailing, 12).padding(.vertical, 8)+ .background(RoundedRectangle(cornerRadius: 12).fill(Palette.raised))}}}diff --git a/Sources/Cicada/SessionStore.swift b/Sources/Cicada/SessionStore.swiftindex b35d5f3..4f4b9c2 100644--- a/Sources/Cicada/SessionStore.swift+++ b/Sources/Cicada/SessionStore.swift@@ -82,6 +82,8 @@ struct Session: Codable, Identifiable, Equatable {final class SessionStore: ObservableObject {@Published private(set) var sessions: [Session] = []@Published private(set) var liveID: String?+ /// The last meeting whose recording became a playable .m4a (the rewrap runs after the meeting).+ @Published private(set) var audioFinished: String?let root: URL/// Per meeting: a file being imported saves alongside the live meeting without delaying it.@@ -169,7 +171,14 @@ final class SessionStore: ObservableObject {/// Turns the meeting's recordings into .m4a files (call after the recorders are closed).func finishAudio(_ id: String, until: Double? = nil) {let urls = [systemAudioURL(id), micAudioURL(id)]- Task.detached(priority: .utility) { for u in urls { await AudioFileWriter.finish(u, until: until) } }+ Task.detached(priority: .utility) {+ for u in urls { await AudioFileWriter.finish(u, until: until) }+ await self.markAudioFinished(id)+ }+ }++ private func markAudioFinished(_ id: String) {+ audioFinished = id}var liveStart: Date? { liveID.flatMap { index($0) }.map { sessions[$0].startedAt } }diff --git a/Sources/Cicada/Views.swift b/Sources/Cicada/Views.swiftindex bb8b901..dd72186 100644--- a/Sources/Cicada/Views.swift+++ b/Sources/Cicada/Views.swift@@ -812,6 +812,12 @@ struct MainWindowView: View {private var current: Session? { store.session(selection ?? store.sessions.first?.id) }+ /// The shown record's audio: an imported file, or the meeting's own recording once it has ended.+ private func loadPlayer() {+ guard let s = current, s.id != store.liveID else { player.load(nil); return }+ player.load(s, recording: s.hasAudio ? store.systemAudioURL(s.id) : nil)+ }+var body: some View {// One white sheet; the list sits on a faint tint instead of behind a rule. The listening// pill lives in the window's toolbar (`MainToolbar`). With no meetings yet, only the@@ -837,7 +843,13 @@ struct MainWindowView: View {return true} isTargeted: { dropping = $0 }.overlay { if dropping { ImportDropOverlay() } }- .onChange(of: current?.id, initial: true) { _, _ in player.load(current) }+ .onChange(of: current?.id, initial: true) { _, _ in loadPlayer() }+ // A meeting that ends while it is shown, and its recording once it is rewrapped into an .m4a.+ .onChange(of: store.liveID) { _, _ in loadPlayer() }+ .onChange(of: store.audioFinished) { _, id in if id == current?.id { loadPlayer() } }+ .onReceive(NotificationCenter.default.publisher(for: .debugPlay)) { n in+ if let t = n.object as? Double { player.play(from: t) }+ }.onChange(of: model.mainShow) { _, show inguard let parts = show?.split(separator: ",").map(String.init), let id = parts.first else { return }selection = id@@ -1205,6 +1217,19 @@ struct MainWindowView: View {if player.sessionID == s.id { RecordingPlayerBar(player: player) }}.padding(.top, 16)+ } else if live {+ if settings.recordAudio {+ Text("会议结束后可以回放录音").font(.system(size: 12)).foregroundStyle(Palette.tertiary).padding(.top, 10)+ }+ } else if player.sessionID == s.id {+ RecordingPlayerBar(player: player).padding(.top, 16)+ } else if !s.hasAudio, !s.lines.isEmpty {+ HStack(spacing: 4) {+ Text("这场会议没存录音 ·").foregroundStyle(Palette.tertiary)+ Button(L("保存会议录音")) { model.openSettings(.records) }+ .buttonStyle(.plain).foregroundStyle(Palette.link)+ }+ .font(.system(size: 12)).padding(.top, 10)}tabsRow(s).padding(.top, 24)}@@ -1296,8 +1321,10 @@ struct MainWindowView: View {// In a meeting that heard the room and the Mac, a change of place starts a new run too.let starts = SpeakerLabels.runStarts(s.lines, speakers).union(both ? RecordList.placeStarts(s.lines) : [])let voices = SpeakerLabels.voiceNumbers(s.lines)+ let playingLine = player.lineID(in: s)ForEach(s.lines) { l in- lineRow(l, speaker: speakers[l.id], label: speakers.isEmpty || starts.contains(l.id), voices: !speakers.isEmpty, place: both, in: s)+ lineRow(l, speaker: speakers[l.id], label: speakers.isEmpty || starts.contains(l.id), voices: !speakers.isEmpty, place: both, in: s,+ current: l.id == playingLine).contextMenu { if !speakers.isEmpty, l.speaker == "them" { assignMenu(s, l, voices) } }.id(l.id)}@@ -1318,6 +1345,10 @@ struct MainWindowView: View {withAnimation { proxy.scrollTo(last.id, anchor: .bottom) }}}+ // The transcript follows the recording while it plays.+ .onChange(of: player.lineID(in: s)) { _, id in+ if player.playing, let id { withAnimation { proxy.scrollTo(id, anchor: .center) } }+ }.onAppear {if let t = jumpTo, let l = s.lines.first(where: { $0.t >= t - 1 }) { proxy.scrollTo(l.id, anchor: .top) }jumpTo = nil@@ -1325,14 +1356,15 @@ struct MainWindowView: View {}}- private func lineRow(_ l: TranscriptLine, speaker: Int? = nil, label: Bool = true, voices: Bool = false, place: Bool = false, in shownSession: Session? = nil) -> some View {+ private func lineRow(_ l: TranscriptLine, speaker: Int? = nil, label: Bool = true, voices: Bool = false, place: Bool = false, in shownSession: Session? = nil, current: Bool = false) -> some View {let me = l.speaker == "me"return HStack(alignment: .top, spacing: 16) {if let shownSession, player.sessionID == shownSession.id, player.ready {- // An imported file plays from this line.+ // The recording plays from this line.Button { player.play(from: l.t) } label: {Text(TranscriptExport.clock(l.t))- .font(.system(size: 12).monospacedDigit()).foregroundStyle(Palette.link)+ .font(.system(size: 12, weight: current ? .semibold : .regular).monospacedDigit())+ .foregroundStyle(current ? Palette.accent : Palette.link).frame(width: 52, alignment: .leading).padding(.top, 1).contentShape(Rectangle())}.buttonStyle(.plain).help(L("从这里播放"))@@ -1376,6 +1408,8 @@ struct MainWindowView: View {Spacer(minLength: 0)}.padding(.vertical, 12)+ // The line the recording is playing.+ .background(RoundedRectangle(cornerRadius: 10).fill(current ? Palette.accentPale : .clear).padding(.horizontal, -10))}}@@ -1652,3 +1686,8 @@ struct LanguageNotice: View {}}}++extension Notification.Name {+ /// Debug `play:<seconds>`: the shown record plays from there.+ static let debugPlay = Notification.Name("cicada.debugPlay")+}