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.

feat: while a recording plays back, the whole line being played lights up and a click anywhere on a line plays from there

wquguru4e0aa4f7685e
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings
index 499b2de..5d0bfec 100644
--- a/Resources/en.lproj/Localizable.strings
+++ b/Resources/en.lproj/Localizable.strings
@@ -1113,6 +1113,7 @@
"全部 %lld 句" = "All %lld lines";
"翻译中…" = "Translating…";
"从这里播放" = "Play from here";
+"回到正在播放" = "Back to playing";
"正在整理纪要…" = "Writing notes…";
"纪要会在会议进行中自动生成" = "Notes are written during the meeting";
"用 %@ 整理出总结、议题、结论和人名,约半分钟。" = "Uses %@ to organize summary, topics, conclusions, and names in ~30s.";
diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.strings
index 367857f..ae32f0f 100644
--- a/Resources/ja.lproj/Localizable.strings
+++ b/Resources/ja.lproj/Localizable.strings
@@ -1113,6 +1113,7 @@
"全部 %lld 句" = "全%lld文";
"翻译中…" = "翻訳中…";
"从这里播放" = "ここから再生";
+"回到正在播放" = "再生中の位置へ";
"正在整理纪要…" = "議事メモを作成中…";
"纪要会在会议进行中自动生成" = "議事メモは会議中に自動で作成されます";
"用 %@ 整理出总结、议题、结论和人名,约半分钟。" = "%@ で要約・議題・結論・人名を30秒ほどで整理します。";
diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.strings
index d5f40f2..f7aec82 100644
--- a/Resources/ko.lproj/Localizable.strings
+++ b/Resources/ko.lproj/Localizable.strings
@@ -1113,6 +1113,7 @@
"全部 %lld 句" = "전체 %lld문장";
"翻译中…" = "번역 중…";
"从这里播放" = "여기서부터 재생";
+"回到正在播放" = "재생 위치로";
"正在整理纪要…" = "회의록 작성 중…";
"纪要会在会议进行中自动生成" = "회의록은 회의 중에 자동으로 작성됩니다";
"用 %@ 整理出总结、议题、结论和人名,约半分钟。" = "%@(으)로 요약, 안건, 결론, 인명을 약 30초 만에 정리합니다.";
diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.strings
index c3c0549..b22f64e 100644
--- a/Resources/zh-Hans.lproj/Localizable.strings
+++ b/Resources/zh-Hans.lproj/Localizable.strings
@@ -1113,6 +1113,7 @@
"全部 %lld 句" = "全部 %lld 句";
"翻译中…" = "翻译中…";
"从这里播放" = "从这里播放";
+"回到正在播放" = "回到正在播放";
"正在整理纪要…" = "正在整理纪要…";
"纪要会在会议进行中自动生成" = "纪要会在会议进行中自动生成";
"用 %@ 整理出总结、议题、结论和人名,约半分钟。" = "用 %@ 整理出总结、议题、结论和人名,约半分钟。";
diff --git a/Sources/Cicada/Compat.swift b/Sources/Cicada/Compat.swift
index 823a22b..86a5694 100644
--- a/Sources/Cicada/Compat.swift
+++ b/Sources/Cicada/Compat.swift
@@ -25,6 +25,23 @@ extension View {
}
}
+ /// The user scrolled by hand: a trackpad, a wheel or the scroller, not our own `scrollTo` (macOS 15
+ /// and later; 14 never reports it, so a playing transcript just keeps following). A mouse wheel
+ /// animates like `scrollTo` does, so an animation counts unless we started one just before.
+ @ViewBuilder func onUserScroll(ownSince: @escaping () -> Date, _ action: @escaping () -> Void) -> some View {
+ if #available(macOS 15, *) {
+ onScrollPhaseChange { _, phase in
+ switch phase {
+ case .tracking, .interacting, .decelerating: action()
+ case .animating where Date().timeIntervalSince(ownSince()) > 0.3: action()
+ default: break
+ }
+ }
+ } else {
+ self
+ }
+ }
+
/// The content scrolled (macOS 15 and later).
@ViewBuilder func onScrolled(_ action: @escaping () -> Void) -> some View {
if #available(macOS 15, *) {
diff --git a/Sources/Cicada/ImportViews.swift b/Sources/Cicada/ImportViews.swift
index 67dbd7c..3dce42f 100644
--- a/Sources/Cicada/ImportViews.swift
+++ b/Sources/Cicada/ImportViews.swift
@@ -14,6 +14,11 @@ final class RecordingPlayer: ObservableObject {
/// The meeting's own recording rather than an imported file: 找不到录音, not 找不到原文件.
@Published private(set) var own = false
@Published private(set) var rate: Float = 1
+ /// The transcript keeps the playing line in view. Scrolling it by hand stops that until a line is
+ /// picked, the bar is dragged or 回到正在播放 is pressed: following would yank the page away.
+ @Published private(set) var following = true
+ /// When the transcript last scrolled itself to follow, so that scroll isn't taken for the user's.
+ var ownScroll = Date.distantPast
private var player: AVPlayer?
private var observer: Any?
@@ -60,9 +65,17 @@ final class RecordingPlayer: ObservableObject {
playing = false
missing = false
own = false
+ following = true
time = 0
}
+ /// The transcript was scrolled by hand while it plays.
+ func userScrolled() {
+ if following, playing { following = false }
+ }
+
+ func follow() { following = true }
+
func toggle() {
guard let player else { return }
if playing { player.pause() } else { player.playImmediately(atRate: rate) }
@@ -78,6 +91,7 @@ final class RecordingPlayer: ObservableObject {
func seek(_ t: Double) {
time = t
+ following = true
player?.seek(to: CMTime(seconds: t, preferredTimescale: 600), toleranceBefore: .zero, toleranceAfter: .zero)
}
@@ -273,3 +287,27 @@ struct ImportDropOverlay: View {
.allowsHitTesting(false)
}
}
+
+/// Three bars that bounce beside the line the recording is playing; nothing while paused.
+struct PlayingBars: View {
+ var on: Bool
+ @Environment(\.accessibilityReduceMotion) private var reduceMotion
+
+ var body: some View {
+ if on {
+ TimelineView(.animation(paused: reduceMotion)) { tl in
+ let t = tl.date.timeIntervalSinceReferenceDate
+ HStack(alignment: .bottom, spacing: 2) {
+ ForEach(0..<3, id: \.self) { i in
+ let h = reduceMotion ? 0.7 : 0.35 + 0.65 * abs(sin(t * 3.5 + Double(i) * 0.9))
+ Capsule().fill(Palette.accent).frame(width: 3, height: 12 * h)
+ }
+ }
+ .frame(height: 12, alignment: .bottom)
+ }
+ .accessibilityHidden(true)
+ } else {
+ Color.clear.frame(height: 12)
+ }
+ }
+}
diff --git a/Sources/Cicada/Views.swift b/Sources/Cicada/Views.swift
index d94a2bd..68f402e 100644
--- a/Sources/Cicada/Views.swift
+++ b/Sources/Cicada/Views.swift
@@ -1074,6 +1074,15 @@ struct MainWindowView: View {
transcript(s)
}
if s.id == store.liveID { liveNow }
+ // Under the page, not in its header: the controls stay while the transcript scrolls.
+ if player.sessionID == s.id, s.id != store.liveID, player.ready || player.missing {
+ RecordingPlayerBar(player: player)
+ .frame(maxWidth: 680, alignment: .leading)
+ .padding(.horizontal, 40).padding(.vertical, 10)
+ .frame(maxWidth: .infinity)
+ .background(Color.white)
+ .overlay(alignment: .top) { Rectangle().fill(Self.hairline).frame(height: 1) }
+ }
}
.onChange(of: s.id) { _, _ in pinned = false }
.onChange(of: tab) { _, _ in pinned = false }
@@ -1268,15 +1277,12 @@ struct MainWindowView: View {
} else {
ImportStatusStrip(model: model, importer: importer, session: s)
}
- 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)
@@ -1400,15 +1406,46 @@ struct MainWindowView: View {
if pinned { pinnedBar(s) { withAnimation { proxy.scrollTo(PinnedHeader.top, anchor: .top) } } }
}
.animation(.easeOut(duration: 0.15), value: pinned)
+ .onUserScroll(ownSince: { player.ownScroll }) { if player.sessionID == s.id { player.userScrolled() } }
.overlay(alignment: .bottom) { FixToast(fixes: model.fixes).padding(.bottom, 18) }
+ .overlay(alignment: .bottom) {
+ // Scrolled away from what is playing: one way back.
+ if player.sessionID == s.id, !player.following, let id = player.lineID(in: s),
+ let l = s.lines.first(where: { $0.id == id }) {
+ Button { player.follow() } label: {
+ HStack(spacing: 6) {
+ Image(systemName: "waveform").font(.system(size: 11, weight: .semibold))
+ Text(L("回到正在播放") + " · " + TranscriptExport.clock(l.t))
+ .font(.system(size: 13, weight: .semibold))
+ }
+ .foregroundStyle(.white).padding(.horizontal, 16).frame(height: 34)
+ .background(Capsule().fill(Palette.ink))
+ .shadow(color: Palette.ink.opacity(0.18), radius: 10, y: 4)
+ .contentShape(Capsule())
+ }
+ .buttonStyle(.plain).linkPointer()
+ .padding(.bottom, 16)
+ .transition(.opacity.combined(with: .move(edge: .bottom)))
+ }
+ }
+ .animation(.easeOut(duration: 0.2), value: player.following)
.onChange(of: s.lines.count) { _, _ in
if s.id == store.liveID, let last = s.lines.last {
withAnimation { proxy.scrollTo(last.id, anchor: .bottom) }
}
}
- // The transcript follows the recording while it plays.
+ // The transcript follows the recording while it plays, until scrolled by hand.
.onChange(of: player.lineID(in: s)) { _, id in
- if player.playing, let id { withAnimation { proxy.scrollTo(id, anchor: .center) } }
+ if player.playing, player.following, let id {
+ player.ownScroll = Date()
+ withAnimation { proxy.scrollTo(id, anchor: .center) }
+ }
+ }
+ .onChange(of: player.following) { _, on in
+ if on, let id = player.lineID(in: s) {
+ player.ownScroll = Date()
+ 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) }
@@ -1419,14 +1456,19 @@ struct MainWindowView: 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"
+ let playable = shownSession.map { player.sessionID == $0.id && player.ready } ?? false
+ let hovered = playable && hoveredLine == l.id && editingLine != l.id
return HStack(alignment: .top, spacing: 16) {
- if let shownSession, player.sessionID == shownSession.id, player.ready {
- // The recording plays from this line.
+ if playable {
+ // The recording plays from this line (so does a click anywhere on it).
Button { player.play(from: l.t) } label: {
- Text(TranscriptExport.clock(l.t))
- .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())
+ HStack(spacing: 3) {
+ if hovered { Image(systemName: "play.fill").font(.system(size: 8)) }
+ Text(TranscriptExport.clock(l.t))
+ .font(.system(size: 12, weight: current || hovered ? .semibold : .regular).monospacedDigit())
+ }
+ .foregroundStyle(current || hovered ? Palette.accent : Palette.link)
+ .frame(width: 52, alignment: .leading).padding(.top, 1).contentShape(Rectangle())
}
.buttonStyle(.plain).help(L("从这里播放"))
} else {
@@ -1480,12 +1522,18 @@ struct MainWindowView: View {
}
}
Spacer(minLength: 0)
+ PlayingBars(on: current && player.playing).frame(width: 14).padding(.top, 4)
}
+ // The padding is part of the line, so there is no dead strip between two lines.
+ .padding(.vertical, 12)
.contentShape(Rectangle())
.onHover { inside in if inside { hoveredLine = l.id } else if hoveredLine == l.id { hoveredLine = nil } }
- .padding(.vertical, 12)
- // The line the recording is playing.
- .background(RoundedRectangle(cornerRadius: 10).fill(current ? Palette.accentPale : .clear).padding(.horizontal, -10))
+ // A click anywhere on the line plays from it; a drag selects text instead (a tap ends without moving).
+ .onTapGesture { if playable, editingLine != l.id { player.play(from: l.t) } }
+ // The line the recording is playing; a lighter fill under the pointer when a click would play it.
+ .background(RoundedRectangle(cornerRadius: 10).fill(current ? Palette.accentPale : hovered ? Palette.raised : .clear)
+ .padding(.horizontal, -10))
+ .animation(.easeOut(duration: 0.2), value: current)
}
}