知了 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
build(ios): wire AI services, save to folder, notes editing, people and hands-free into the app and settings
wqugurua1ece1652f39
diff --git a/ios/Sources/Cicada/CicadaApp.swift b/ios/Sources/Cicada/CicadaApp.swiftindex ec147d9..df0038e 100644--- a/ios/Sources/Cicada/CicadaApp.swift+++ b/ios/Sources/Cicada/CicadaApp.swift@@ -123,11 +123,20 @@ final class AppModel: ObservableObject {}()/// 导入录音或视频: the Mac's importer, with the iOS app's languages.let importPrefs = ImportPrefs()+ /// 存到文件夹 (FolderPage.swift): the Mac's exporter, writing into a folder picked in Files.+ let folderPrefs = FolderPrefs()+ lazy var folderExport = FolderExporter(store: store, settings: folderPrefs)+ @Published var showFolder = falselazy var importer: FileImporter = {- let i = FileImporter(store: store, settings: importPrefs, translator: translator, profiles: nil)+ // 记住的人 name the voices of imported files too.+ let i = FileImporter(store: store, settings: importPrefs, translator: translator, profiles: profiles)// As on the Mac: a file transcribed to the end gets its notes when there is a key.i.onFinished = { [weak self] id in- guard let self, self.ling.hasKey else { return }+ guard let self else { return }+ self.folderExport.ended(id)+ for ref in self.store.session(id)?.voiceProfiles?.values ?? [:].values { self.profiles.markSeen(id: ref.id) }+ self.speakerProfiles = self.profiles.all()+ guard self.ling.hasKey else { return }self.notes.generate(for: id)}ImportBackground.importer = i@@ -136,6 +145,17 @@ final class AppModel: ObservableObject {/// 面对面同声传译 (FaceView), over everything while it is open.lazy var face = FaceToFace(store: store, translator: translator, ling: ling)@Published var showFace = false+ /// 记住的人 (PeoplePage.swift): the Mac's voiceprint store, what it holds, and the last problem.+ let profiles = SpeakerProfileStore()+ @Published var speakerProfiles: [SpeakerProfile] = []+ @Published var speakerMemoryBusy = false+ @Published var speakerProblem: (String, String)?+ @Published var showPeople = false+ /// The notes piece open for editing (NotesEdit.swift), and the meeting whose notes were just copied.+ @Published var noteEdit: NoteEdit?+ @Published var copiedNotes: String?+ /// 设置 › AI 服务, pushed (a debug command opens it).+ @Published var showAIService = false/// 设置 › 念给对方的声音, pushed (a debug command opens it).@Published var showVoices = false/// 设置 › 快速开始, pushed (a debug command opens it).@@ -196,14 +216,18 @@ final class AppModel: ObservableObject {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 = {- // Ming speaks 面对面 with the same key: without the voice model, every turn fell back to the phone's voice.- AIConfig(provider: .ling, base: AIProvider.ling.base,- textModel: UserDefaults.standard.string(forKey: Pref.model) ?? LingClient.models[0],- voiceModel: AIProvider.ling.voiceModels.first?.id, voiceBase: AIProvider.ling.base)- }+ // 设置 › AI 服务 (AIServicePage.swift): the Mac's services and settings.+ ling.config = { AIPrefs.config }+ AIPrefs.applyVoices()wireNotes()+ // 存到文件夹, as the Mac's AppModel: a meeting is written once settled and rewritten when it changes.+ folderExport.settling = { [weak self] id in self?.notes.settling(id) ?? false }+ store.onSave = { [weak self] id in self?.folderExport.saved(id) }+ notes.finalDone = { [weak self] id in self?.folderExport.settled(id) }+ room.onEnded = { [weak self] id in self?.folderExport.ended(id) }+ room.profiles = profiles+ speakerProfiles = profiles.all()+ folderExport.retry()wireFixes()#if targetEnvironment(simulator)HostRecognizer.install()@@ -339,6 +363,7 @@ final class AppModel: ObservableObject {searchPath.removeAll { $0 == id }if speakerUndo?.session == id { speakerUndo = nil }store.delete(id)+ folderExport.deleted(id)debugLog("delete \(id) sessions=\(store.sessions.count)")}diff --git a/ios/Sources/Cicada/SettingsView.swift b/ios/Sources/Cicada/SettingsView.swiftindex 60ec8d4..c22f743 100644--- a/ios/Sources/Cicada/SettingsView.swift+++ b/ios/Sources/Cicada/SettingsView.swift@@ -26,22 +26,14 @@ struct SettingsView: View {}SectionLabel(text: L("AI 服务"))Card {- NavigationLink { KeyPage() } label: {- row(Text(verbatim: "Ling key")) {+ NavigationLink { AIServicePage() } label: {+ row(Text(verbatim: ling.provider.id == .custom ? L("自定义服务") : ling.provider.name)) {KeyStatus(state: ling.keyState)Chevron()}}.buttonStyle(RowPress())Hairline()- row(Text("模型")) {- Picker(selection: $aiModel) {- ForEach(LingClient.models, id: \.self) { Text(verbatim: $0).tag($0) }- } label: { Text("模型") }- .pickerStyle(.menu)- .tint(Ink.secondary)- }- Hairline()NavigationLink { WordListPage(vocabulary: model.vocabulary) } label: {row(Text("词表")) {if !model.vocabulary.terms.isEmpty {@@ -69,6 +61,16 @@ struct SettingsView: View {.tint(Ink.ok)}Hairline()+ NavigationLink { PeoplePage() } label: {+ row(Text("人员库")) {+ if !model.speakerProfiles.isEmpty {+ Text(verbatim: "\(model.speakerProfiles.count)").foregroundStyle(Ink.secondary).monospacedDigit()+ }+ Chevron()+ }+ }+ .buttonStyle(RowPress())+ Hairline()helped(row(Text("保存会议录音")) {Toggle(isOn: $recordAudio) { Text("保存会议录音") }.labelsHidden()@@ -138,6 +140,17 @@ struct SettingsView: View {}.buttonStyle(RowPress())}+ SectionLabel(text: L("会后存一份"))+ Card {+ NavigationLink { FolderPage(exporter: model.folderExport) } label: {+ row(Text("存到文件夹")) {+ Text(verbatim: model.folderExport.on ? model.folderExport.folder.map(FolderExporter.shortPath) ?? "" : L("关闭"))+ .foregroundStyle(Ink.secondary).lineLimit(1)+ Chevron()+ }+ }+ .buttonStyle(RowPress())+ }SectionLabel(text: L("快速开始"))Card {NavigationLink { QuickStartPage() } label: {@@ -160,6 +173,9 @@ struct SettingsView: View {.navigationDestination(isPresented: $model.showWordList) { WordListPage(vocabulary: model.vocabulary) }.navigationDestination(isPresented: $model.showQuickStart) { QuickStartPage() }.navigationDestination(isPresented: $model.showVoices) { VoicesPage(face: model.face) }+ .navigationDestination(isPresented: $model.showAIService) { AIServicePage() }+ .navigationDestination(isPresented: $model.showFolder) { FolderPage(exporter: model.folderExport) }+ .navigationDestination(isPresented: $model.showPeople) { PeoplePage() }.toolbar(sheet ? .visible : .hidden, for: .navigationBar).navigationTitle(sheet ? Text("设置") : Text("")).navigationBarTitleDisplayMode(.inline)@@ -186,7 +202,7 @@ struct SettingsView: View {/// 念给对方的声音 at a glance: the voice the other person hears.private var voiceSummary: String {let lang = model.face.theirs.code- let id = SpeakVoices.chosenID(for: lang, hasKey: ling.hasKey)+ let id = SpeakVoices.chosenID(for: lang, hasKey: ling.hasKey, clones: ling.clones)if id == VoiceCatalog.cloneOption.id { return L("我自己的声音") }return VoiceCatalog.options(for: lang).first { $0.id == id }?.name ?? L("手机自带")}@@ -284,12 +300,16 @@ struct KeyPage: View {}}.padding(.top, 16)- Text("在 Ling 开放平台点“创建令牌”,复制以 sk- 开头的那串。")- .font(.footnote).foregroundStyle(Ink.secondary)- .padding(.horizontal, 4).padding(.top, 12)- Link("打开 Ling 开放平台 ↗", destination: URL(string: "https://chat.ant-ling.com/platform/api")!)- .font(.footnote.weight(.semibold))- .padding(.horizontal, 4).padding(.top, 8)+ if ling.provider.id == .ling {+ Text("在 Ling 开放平台点“创建令牌”,复制以 sk- 开头的那串。")+ .font(.footnote).foregroundStyle(Ink.secondary)+ .padding(.horizontal, 4).padding(.top, 12)+ }+ if let site = ling.provider.site {+ Link(ling.provider.id == .ling ? L("打开 Ling 开放平台 ↗") : L("获取 \(ling.provider.name) key ↗"), destination: site)+ .font(.footnote.weight(.semibold))+ .padding(.horizontal, 4).padding(.top, 8)+ }}if ling.key != nil && !editing {HStack {@@ -306,14 +326,14 @@ struct KeyPage: View {.frame(maxWidth: .infinity)}.background(Ink.ground)- .navigationTitle(Text(verbatim: "Ling key"))+ .navigationTitle(Text(verbatim: ling.provider.id == .custom ? "Key" : "\(ling.provider.name) key")).navigationBarTitleDisplayMode(.inline)}private var detail: String? {switch ling.keyState {- case .ok(let s): L("\(aiModel) · 响应约 \(String(format: "%.1f", s)) 秒")- case .invalid: L("Ling 提示此令牌无效,请检查是否复制完整,或重新创建一个")+ case .ok(let s): L("\(ling.config().textModel) · 响应约 \(String(format: "%.1f", s)) 秒")+ case .invalid: ling.provider.id == .ling ? L("Ling 提示此令牌无效,请检查是否复制完整,或重新创建一个") : L("这个 key 用不了")case .unreachable(let why): whycase .none: L("不填 key 时,字幕和翻译仍可正常使用")default: nildiff --git a/ios/shared-sources.txt b/ios/shared-sources.txtindex e54854e..0410509 100644--- a/ios/shared-sources.txt+++ b/ios/shared-sources.txt@@ -26,3 +26,8 @@ Sources/Cicada/SpeakerProfiles.swiftSources/Cicada/FileImport.swiftSources/Cicada/ShareProjection.swiftSources/Cicada/ShareClient.swift+Sources/Cicada/FolderExport.swift+Sources/Cicada/RichCopy.swift+Sources/Cicada/NotesEditing.swift+Sources/Cicada/SpeakerEnrollment.swift+Sources/Cicada/HandsFree.swift