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(ios): records, search, live subtitles and the lock screen show misheard words as fixed, dotted like on the Mac

wquguru9ba88a6ad0ac
diff --git a/ios/Sources/Cicada/CicadaApp.swift b/ios/Sources/Cicada/CicadaApp.swift
index 4a4585b..a36e025 100644
--- a/ios/Sources/Cicada/CicadaApp.swift
+++ b/ios/Sources/Cicada/CicadaApp.swift
@@ -68,7 +68,7 @@ final class AppModel: ObservableObject {
lazy var room: RoomListen = {
let r = RoomListen(store: store, translator: translator, notes: notes)
r.onStateChange = { [weak self] in self?.listeningChanged() }
- r.onLine = { [weak self] line in self?.liveActivity.update(line: line) }
+ r.onLine = { [weak self] line in self?.showOnLockScreen(line) }
return r
}()
let liveActivity = LiveActivityController()
@@ -123,6 +123,13 @@ final class AppModel: ObservableObject {
func stopListening() { room.stop() }
+ /// The Live Activity shows the line as fixed (改正听错的词), like the 字幕 page.
+ private func showOnLockScreen(_ line: RoomListen.Line) {
+ var shown = line
+ if let rec = store.session(room.sessionID)?.lines.first(where: { $0.id == line.id }) { shown.src = rec.shown }
+ liveActivity.update(line: shown)
+ }
+
private func listeningChanged() {
objectWillChange.send()
if room.isRunning, let start = room.startedAt {
diff --git a/ios/Sources/Cicada/FixViews.swift b/ios/Sources/Cicada/FixViews.swift
new file mode 100644
index 0000000..6fd00b0
--- /dev/null
+++ b/ios/Sources/Cicada/FixViews.swift
@@ -0,0 +1,19 @@
+import SwiftUI
+
+/// 改正听错的词 on iPhone and iPad: a line as shown, its fixed words with the Mac's dotted underline.
+enum FixedText {
+ /// The line with its applied fixes; each fixed word dotted, a word still waiting (这样改对吗?)
+ /// on a pale wash as heard. The Mac's `TranscriptParagraphs.joinFixed` for one line.
+ static func attributed(_ l: TranscriptLine) -> AttributedString {
+ let (text, marks) = Correction.apply(l.fixes ?? [], to: l.src)
+ var a = AttributedString(text)
+ for m in marks {
+ guard let lo = AttributedString.Index(m.lowerBound, within: a), let hi = AttributedString.Index(m.upperBound, within: a) else { continue }
+ a[lo..<hi].underlineStyle = Text.LineStyle(pattern: .dot, color: Ink.tertiary)
+ }
+ for f in l.fixes ?? [] where f.ask == true {
+ if let r = a.range(of: f.from) { a[r].backgroundColor = Ink.accentWash }
+ }
+ return a
+ }
+}
diff --git a/ios/Sources/Cicada/LiveViews.swift b/ios/Sources/Cicada/LiveViews.swift
index 6467ba2..22a573e 100644
--- a/ios/Sources/Cicada/LiveViews.swift
+++ b/ios/Sources/Cicada/LiveViews.swift
@@ -207,11 +207,14 @@ struct LiveLines: View {
.frame(maxWidth: .infinity).padding(.top, 40)
}
ForEach(room.lines) { l in
- card(who: numbers[l.id].map { SpeakerLabels.label($0, names) }, time: l.t, src: l.src, dst: l.dst, live: false)
+ // The record's line, so its fixed words show (改正听错的词); `room.lines` keeps what was heard.
+ let rec = session?.lines.first { $0.id == l.id }
+ card(who: numbers[l.id].map { SpeakerLabels.label($0, names) }, time: l.t,
+ src: rec.map(FixedText.attributed) ?? AttributedString(l.src), dst: l.dst, live: false)
.id(l.id)
}
if !room.draft.isEmpty {
- card(who: nil, time: nil, src: room.draft, dst: room.draftTranslation.isEmpty ? nil : room.draftTranslation, live: true)
+ card(who: nil, time: nil, src: AttributedString(room.draft), dst: room.draftTranslation.isEmpty ? nil : room.draftTranslation, live: true)
.id("draft")
}
Color.clear.frame(height: 40).id("end")
@@ -223,7 +226,7 @@ struct LiveLines: View {
}
}
- private func card(who: String?, time: Double?, src: String, dst: String?, live: Bool) -> some View {
+ private func card(who: String?, time: Double?, src: AttributedString, dst: String?, live: Bool) -> some View {
VStack(alignment: .leading, spacing: 6) {
Text(live ? L("正在说") : [who, time.map(TranscriptExport.clock)].compactMap { $0 }.joined(separator: " · "))
.font(.caption.weight(.semibold)).foregroundStyle(live ? Ink.accentText : Ink.ink)
diff --git a/ios/Sources/Cicada/RecordView.swift b/ios/Sources/Cicada/RecordView.swift
index 6b802d8..f4704a9 100644
--- a/ios/Sources/Cicada/RecordView.swift
+++ b/ios/Sources/Cicada/RecordView.swift
@@ -290,8 +290,8 @@ struct TranscriptList: View {
.foregroundStyle(l.speaker == "me" ? Ink.accentText : (focus == nil || mine ? Ink.ink : Ink.tertiary))
}
}
- Text(l.src).font(.system(size: srcSize)).foregroundStyle(Ink.secondary).lineSpacing(2)
- if let d = l.dst, d != l.src {
+ Text(FixedText.attributed(l)).font(.system(size: srcSize)).foregroundStyle(Ink.secondary).lineSpacing(2)
+ if let d = l.dst, d != l.src, d != l.shown {
Text(d).font(.system(size: dstSize)).foregroundStyle(Ink.ink).lineSpacing(4)
}
}
diff --git a/ios/Sources/Cicada/RecordsView.swift b/ios/Sources/Cicada/RecordsView.swift
index 7860795..9a2ee0f 100644
--- a/ios/Sources/Cicada/RecordsView.swift
+++ b/ios/Sources/Cicada/RecordsView.swift
@@ -285,7 +285,7 @@ struct SearchView: View {
guard !q.isEmpty else { return sessions }
return sessions.filter { s in
s.displayTitle.localizedCaseInsensitiveContains(q)
- || s.lines.contains { $0.src.localizedCaseInsensitiveContains(q) || ($0.dst?.localizedCaseInsensitiveContains(q) ?? false) }
+ || s.lines.contains { $0.shown.localizedCaseInsensitiveContains(q) || ($0.dst?.localizedCaseInsensitiveContains(q) ?? false) }
}
}