知了 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): start listening from the Action button, Control Center or Siri, and pause or end it from the lock screen
wquguru7541d08e1fc9
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.stringsindex c1b04e5..ae5481e 100644--- a/Resources/en.lproj/Localizable.strings+++ b/Resources/en.lproj/Localizable.strings@@ -1599,3 +1599,24 @@"按住下面的按钮说话" = "Hold the button below and speak";"松开就念给对方" = "Let go to read it out";"对方在说话" = "They're speaking";++/* iOS: quick start, Live Activity buttons, settings */+"用麦克风听会议室,出实时双语字幕和纪要" = "Listen to the room with the microphone for live bilingual subtitles and notes";+"结束并出纪要" = "End and Make Notes";+"结束正在听的会议,有 key 时整理纪要" = "Ends the meeting being listened to and writes its notes when there is a key";+"暂停或继续听" = "Pause or Resume Listening";+"快速开始" = "Quick Start";+"念给对方的声音" = "Voice for the Other Person";+"手机自带" = "Built-in";+"操作按钮、控制中心和 Siri" = "Action Button, Control Center and Siri";+"不用先打开 app 就开始听,再按一次结束" = "Start listening without opening the app; press again to end";+"都按上次的语言听" = "Each uses the last languages you listened in";+"操作按钮" = "Action Button";+"控制中心和锁屏" = "Control Center and Lock Screen";+"按一下开始听" = "Press Once to Listen";+"iPhone 设置 › 操作按钮 › 快捷指令 › %@“开始听”" = "iPhone Settings › Action Button › Shortcut › %@ “Start Listening”";+"打开 iPhone 设置" = "Open iPhone Settings";+"“开始听”按钮" = "“Start Listening” Button";+"下拉控制中心,点左上角的 + 添加" = "Pull down Control Center and tap + at the top left to add it";+"“嘿 Siri,用%@开始听”" = "“Hey Siri, start listening with %@”";+"“嘿 Siri,%@结束”" = "“Hey Siri, stop %@”";diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.stringsindex 7016e20..b8325d4 100644--- a/Resources/ja.lproj/Localizable.strings+++ b/Resources/ja.lproj/Localizable.strings@@ -1599,3 +1599,24 @@"按住下面的按钮说话" = "下のボタンを押したまま話してください";"松开就念给对方" = "離すと読み上げます";"对方在说话" = "相手が話しています";++/* iOS: quick start, Live Activity buttons, settings */+"用麦克风听会议室,出实时双语字幕和纪要" = "マイクで会議室を聞き、2か国語の字幕と議事メモをリアルタイムで";+"结束并出纪要" = "終了して議事メモ";+"结束正在听的会议,有 key 时整理纪要" = "聞いている会議を終了し、キーがあれば議事メモをまとめます";+"暂停或继续听" = "一時停止または再開";+"快速开始" = "クイックスタート";+"念给对方的声音" = "相手に読み上げる声";+"手机自带" = "端末の音声";+"操作按钮、控制中心和 Siri" = "アクションボタン、コントロールセンター、Siri";+"不用先打开 app 就开始听,再按一次结束" = "アプリを開かずに聞き始め、もう一度押すと終了";+"都按上次的语言听" = "どれも前回の言語で聞きます";+"操作按钮" = "アクションボタン";+"控制中心和锁屏" = "コントロールセンターとロック画面";+"按一下开始听" = "1回押して聞き始める";+"iPhone 设置 › 操作按钮 › 快捷指令 › %@“开始听”" = "iPhone の設定 › アクションボタン › ショートカット › %@「聞き始める」";+"打开 iPhone 设置" = "iPhone の設定を開く";+"“开始听”按钮" = "「聞き始める」ボタン";+"下拉控制中心,点左上角的 + 添加" = "コントロールセンターを下に引き、左上の + で追加";+"“嘿 Siri,用%@开始听”" = "「Hey Siri、%@ で聞き始めて」";+"“嘿 Siri,%@结束”" = "「Hey Siri、%@ を終了」";diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.stringsindex 0144e0a..85a1983 100644--- a/Resources/ko.lproj/Localizable.strings+++ b/Resources/ko.lproj/Localizable.strings@@ -1599,3 +1599,24 @@"按住下面的按钮说话" = "아래 버튼을 누른 채 말하세요";"松开就念给对方" = "떼면 읽어 줍니다";"对方在说话" = "상대가 말하는 중";++/* iOS: quick start, Live Activity buttons, settings */+"用麦克风听会议室,出实时双语字幕和纪要" = "마이크로 회의실을 듣고 실시간 이중 언어 자막과 회의록을 만듭니다";+"结束并出纪要" = "종료하고 회의록 만들기";+"结束正在听的会议,有 key 时整理纪要" = "듣고 있는 회의를 끝내고, 키가 있으면 회의록을 정리합니다";+"暂停或继续听" = "일시정지 또는 계속 듣기";+"快速开始" = "빠른 시작";+"念给对方的声音" = "상대에게 읽어 줄 목소리";+"手机自带" = "기본 음성";+"操作按钮、控制中心和 Siri" = "동작 버튼, 제어 센터, Siri";+"不用先打开 app 就开始听,再按一次结束" = "앱을 열지 않고 듣기 시작, 다시 누르면 종료";+"都按上次的语言听" = "모두 지난번 언어로 듣습니다";+"操作按钮" = "동작 버튼";+"控制中心和锁屏" = "제어 센터와 잠금 화면";+"按一下开始听" = "한 번 눌러 듣기 시작";+"iPhone 设置 › 操作按钮 › 快捷指令 › %@“开始听”" = "iPhone 설정 › 동작 버튼 › 단축어 › %@ ‘듣기 시작’";+"打开 iPhone 设置" = "iPhone 설정 열기";+"“开始听”按钮" = "‘듣기 시작’ 버튼";+"下拉控制中心,点左上角的 + 添加" = "제어 센터를 내리고 왼쪽 위 +를 눌러 추가";+"“嘿 Siri,用%@开始听”" = "“시리야, %@로 듣기 시작”";+"“嘿 Siri,%@结束”" = "“시리야, %@ 종료”";diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.stringsindex acaa986..c72547d 100644--- a/Resources/zh-Hans.lproj/Localizable.strings+++ b/Resources/zh-Hans.lproj/Localizable.strings@@ -1504,3 +1504,24 @@"按住下面的按钮说话" = "按住下面的按钮说话";"松开就念给对方" = "松开就念给对方";"对方在说话" = "对方在说话";++/* iOS: quick start, Live Activity buttons, settings */+"用麦克风听会议室,出实时双语字幕和纪要" = "用麦克风听会议室,出实时双语字幕和纪要";+"结束并出纪要" = "结束并出纪要";+"结束正在听的会议,有 key 时整理纪要" = "结束正在听的会议,有 key 时整理纪要";+"暂停或继续听" = "暂停或继续听";+"快速开始" = "快速开始";+"念给对方的声音" = "念给对方的声音";+"手机自带" = "手机自带";+"操作按钮、控制中心和 Siri" = "操作按钮、控制中心和 Siri";+"不用先打开 app 就开始听,再按一次结束" = "不用先打开 app 就开始听,再按一次结束";+"都按上次的语言听" = "都按上次的语言听";+"操作按钮" = "操作按钮";+"控制中心和锁屏" = "控制中心和锁屏";+"按一下开始听" = "按一下开始听";+"iPhone 设置 › 操作按钮 › 快捷指令 › %@“开始听”" = "iPhone 设置 › 操作按钮 › 快捷指令 › %@“开始听”";+"打开 iPhone 设置" = "打开 iPhone 设置";+"“开始听”按钮" = "“开始听”按钮";+"下拉控制中心,点左上角的 + 添加" = "下拉控制中心,点左上角的 + 添加";+"“嘿 Siri,用%@开始听”" = "“嘿 Siri,用%@开始听”";+"“嘿 Siri,%@结束”" = "“嘿 Siri,%@结束”";diff --git a/ios/LiveActivity/CicadaLive.swift b/ios/LiveActivity/CicadaLive.swiftindex 2c805e8..8685f8b 100644--- a/ios/LiveActivity/CicadaLive.swift+++ b/ios/LiveActivity/CicadaLive.swift@@ -3,11 +3,54 @@ import SwiftUIimport WidgetKit// The CicadaLive extension: draws ListenActivity (ios/Sources/Cicada/ListenActivity.swift) on the-// lock screen and in the Dynamic Island. Built by ios/scripts/build.sh into PlugIns/CicadaLive.appex.+// lock screen and in the Dynamic Island, and 开始听 in Control Center. Built by ios/scripts/build.sh+// into PlugIns/CicadaLive.appex. Its buttons are App Intents (ios/Sources/Cicada/Intents.swift),+// which run in the app.@mainstruct CicadaLiveBundle: WidgetBundle {- var body: some Widget { ListenLiveActivity() }+ var body: some Widget {+ ListenLiveActivity()+ StartListeningControl()+ }+}++/// 开始听 in Control Center and on the lock screen.+struct StartListeningControl: ControlWidget {+ var body: some ControlWidgetConfiguration {+ StaticControlConfiguration(kind: "com.wquguru.cicada.start") {+ ControlWidgetButton(action: StartListeningIntent()) {+ Label("开始听", systemImage: "mic.fill")+ }+ }+ .displayName("开始听")+ .description("用麦克风听会议室,出实时双语字幕和纪要")+ }+}++/// 暂停 / 继续 and 结束并出纪要, on the lock screen and in the expanded Dynamic Island.+private struct LiveButtons: View {+ let paused: Bool+ var dark = false++ var body: some View {+ HStack(spacing: 8) {+ Button(intent: PauseListeningIntent()) {+ Text(paused ? "继续" : "暂停").font(.subheadline.weight(.semibold))+ .foregroundStyle(dark ? .white : LiveInk.ink)+ .frame(maxWidth: .infinity, minHeight: 40)+ .background((dark ? Color.white : LiveInk.ink).opacity(dark ? 0.16 : 0.07), in: Capsule())+ }+ .buttonStyle(.plain)+ Button(intent: StopListeningIntent()) {+ Text("结束并出纪要").font(.subheadline.weight(.semibold))+ .foregroundStyle(dark ? LiveInk.ink : .white)+ .frame(maxWidth: .infinity, minHeight: 40)+ .background(dark ? Color.white : LiveInk.ink, in: Capsule())+ }+ .buttonStyle(.plain)+ }+ }}private enum LiveInk {@@ -48,9 +91,13 @@ struct ListenLiveActivity: Widget {LiveLogo(size: 34)VStack(alignment: .leading, spacing: 1) {HStack(spacing: 6) {- Circle().fill(LiveInk.accent).frame(width: 7, height: 7)- Text("正在听").font(.footnote.weight(.semibold)).foregroundStyle(LiveInk.accent)- Elapsed(since: context.attributes.startedAt).font(.footnote.weight(.semibold)).foregroundStyle(LiveInk.accent)+ Circle().fill(context.state.paused ? LiveInk.grey : LiveInk.accent).frame(width: 7, height: 7)+ if context.state.paused {+ Text("已暂停").font(.footnote.weight(.semibold)).foregroundStyle(LiveInk.grey)+ } else {+ Text("正在听").font(.footnote.weight(.semibold)).foregroundStyle(LiveInk.accent)+ Elapsed(since: context.attributes.startedAt).font(.footnote.weight(.semibold)).foregroundStyle(LiveInk.accent)+ }}Text(verbatim: "\(String(localized: "会议室")) · \(context.attributes.pair)").font(.subheadline.weight(.semibold)).foregroundStyle(LiveInk.ink)@@ -65,6 +112,7 @@ struct ListenLiveActivity: Widget {} else {Text("开始说话后,字幕会出现在这里").font(.callout).foregroundStyle(LiveInk.grey)}+ LiveButtons(paused: context.state.paused)}.padding(16).activityBackgroundTint(LiveInk.ground.opacity(0.92))@@ -88,6 +136,7 @@ struct ListenLiveActivity: Widget {.font(.callout).foregroundStyle(.white).lineLimit(2)Text(verbatim: "\(String(localized: "会议室")) · \(context.attributes.pair)").font(.caption2).foregroundStyle(.white.opacity(0.6))+ LiveButtons(paused: context.state.paused, dark: true).padding(.top, 6)}.frame(maxWidth: .infinity, alignment: .leading).padding(.horizontal, 4)diff --git a/ios/Sources/Cicada/CicadaApp.swift b/ios/Sources/Cicada/CicadaApp.swiftindex d33d5e3..bdb5a48 100644--- a/ios/Sources/Cicada/CicadaApp.swift+++ b/ios/Sources/Cicada/CicadaApp.swift@@ -113,6 +113,8 @@ 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+ /// 设置 › 快速开始, pushed (a debug command opens it).+ @Published var showQuickStart = false/// The meeting whose 导出 sheet is open.@Published var exporting: String?/// Why a picked file wasn't imported.@@ -172,6 +174,7 @@ final class AppModel: ObservableObject {HostRecognizer.install()#endifDebugChannel.listen(self)+ IntentHub.run = { [weak self] action in self?.intent(action) }debugLog("ios launch \(DevBuild.label ?? "release") sessions=\(store.sessions.count) key=\(ling.hasKey)")if ling.hasKey { Task { await ling.check() } }}@@ -210,8 +213,22 @@ final class AppModel: ObservableObject {liveActivity.update(line: shown)}+ /// 快速开始 and the Live Activity's buttons.+ func intent(_ action: IntentHub.Action) {+ debugLog("intent: \(action)")+ switch action {+ case .start:+ if showFace { closeFace() }+ showWelcome = false+ startListening()+ case .stop: stopListening()+ case .togglePause: room.setPaused(!room.paused)+ }+ }+private func listeningChanged() {objectWillChange.send()+ liveActivity.setPaused(room.paused)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))diff --git a/ios/Sources/Cicada/Debug.swift b/ios/Sources/Cicada/Debug.swiftindex e742163..73e2b4a 100644--- a/ios/Sources/Cicada/Debug.swift+++ b/ios/Sources/Cicada/Debug.swift@@ -82,6 +82,13 @@ extension AppModel {case "interrupt":// interrupt:began|ended, what the system sends for a call or Siriroom.debugInterrupt(arg != "ended")+ case "quickStart":+ tab = .settings+ showSettings = true+ showQuickStart = arg != "off"+ case "intent":+ // intent:start|stop|pause, as the Action button, Siri or the Live Activity's buttons+ IntentHub.send(arg == "stop" ? .stop : arg == "pause" ? .togglePause : .start)case "pip":pip.start()case "livePage":diff --git a/ios/Sources/Cicada/FaceView.swift b/ios/Sources/Cicada/FaceView.swiftindex 87fa362..ff7265b 100644--- a/ios/Sources/Cicada/FaceView.swift+++ b/ios/Sources/Cicada/FaceView.swift@@ -212,7 +212,7 @@ struct FaceButton: View {Button { model.openFace() } label: {VStack(spacing: 1) {Image(systemName: "bubble.left.and.text.bubble.right").font(.system(size: 19, weight: .medium))- Text("面对面").font(.system(size: 10, weight: .semibold))+ Text("面对面").font(.system(size: 10, weight: .semibold)).lineLimit(1).minimumScaleFactor(0.7).padding(.horizontal, 4)}.foregroundStyle(Ink.ink).frame(width: 58, height: 58)diff --git a/ios/Sources/Cicada/Intents.swift b/ios/Sources/Cicada/Intents.swiftnew file mode 100644index 0000000..42f9db4--- /dev/null+++ b/ios/Sources/Cicada/Intents.swift@@ -0,0 +1,75 @@+import AppIntents+import Foundation++// 快速开始: 开始听 for the Action button, Control Center and Siri, and the Live Activity's 暂停 and+// 结束并出纪要. Compiled into the app and into the CicadaLive extension (its Control Center button+// names the intent); every intent runs in the app, which hands it to AppModel through `IntentHub`.++@MainActor+enum IntentHub {+ /// Set by AppModel. An intent that comes before it (the app launched by the intent) is kept+ /// in `pending` and run once AppModel is there.+ static var run: ((Action) -> Void)? {+ didSet { if let run, let p = pending { pending = nil; run(p) } }+ }+ static var pending: Action?++ enum Action { case start, stop, togglePause }++ static func send(_ a: Action) {+ if let run { run(a) } else { pending = a }+ }+}++struct StartListeningIntent: AppIntent {+ static let title: LocalizedStringResource = "开始听"+ static let description = IntentDescription("用麦克风听会议室,出实时双语字幕和纪要")+ /// The microphone starts with the app in front: iOS won't start recording from the background.+ static let openAppWhenRun = true++ @MainActor+ func perform() async throws -> some IntentResult {+ IntentHub.send(.start)+ return .result()+ }+}++struct StopListeningIntent: LiveActivityIntent {+ static let title: LocalizedStringResource = "结束并出纪要"+ static let description = IntentDescription("结束正在听的会议,有 key 时整理纪要")++ @MainActor+ func perform() async throws -> some IntentResult {+ IntentHub.send(.stop)+ return .result()+ }+}++struct PauseListeningIntent: LiveActivityIntent {+ static let title: LocalizedStringResource = "暂停或继续听"+ static let isDiscoverable = false++ @MainActor+ func perform() async throws -> some IntentResult {+ IntentHub.send(.togglePause)+ return .result()+ }+}++#if !CICADA_LIVE+/// Siri and Spotlight (the app's only; the extension builds with CICADA_LIVE). Phrases in the languages people ask in; each must name the app.+struct CicadaShortcuts: AppShortcutsProvider {+ static var appShortcuts: [AppShortcut] {+ AppShortcut(intent: StartListeningIntent(), phrases: [+ "用\(.applicationName)开始听",+ "\(.applicationName)开始听",+ "Start listening with \(.applicationName)",+ "\(.applicationName) start listening",+ ], shortTitle: "开始听", systemImageName: "mic.fill")+ AppShortcut(intent: StopListeningIntent(), phrases: [+ "\(.applicationName)结束",+ "Stop \(.applicationName)",+ ], shortTitle: "结束并出纪要", systemImageName: "stop.fill")+ }+}+#endifdiff --git a/ios/Sources/Cicada/ListenActivity.swift b/ios/Sources/Cicada/ListenActivity.swiftindex 182bb66..068d90c 100644--- a/ios/Sources/Cicada/ListenActivity.swift+++ b/ios/Sources/Cicada/ListenActivity.swift@@ -10,6 +10,8 @@ struct ListenActivity: ActivityAttributes {var source: String/// Distinct voices so far.var people: Int+ /// 暂停 on the lock screen: the microphone is off until 继续.+ var paused = false}var startedAt: Datediff --git a/ios/Sources/Cicada/LiveActivityController.swift b/ios/Sources/Cicada/LiveActivityController.swiftindex e7846b7..71fb5ed 100644--- a/ios/Sources/Cicada/LiveActivityController.swift+++ b/ios/Sources/Cicada/LiveActivityController.swift@@ -9,6 +9,8 @@ final class LiveActivityController {private var lastSent = Date.distantPastprivate var pending: ListenActivity.ContentState?private var people = 0+ private var paused = false+ private var last = ListenActivity.ContentState(line: "", source: "", people: 0)func start(startedAt: Date, pair: String) {guard activity == nil else { return }@@ -17,6 +19,7 @@ final class LiveActivityController {return}people = 0+ paused = falselet state = ListenActivity.ContentState(line: "", source: "", people: 0)do {activity = try Activity.request(attributes: ListenActivity(startedAt: startedAt, pair: pair),@@ -30,7 +33,8 @@ final class LiveActivityController {func update(line: RoomListen.Line, people: Int? = nil) {guard let activity else { return }if let people { self.people = people }- let state = ListenActivity.ContentState(line: line.dst ?? "", source: line.src, people: self.people)+ let state = ListenActivity.ContentState(line: line.dst ?? "", source: line.src, people: self.people, paused: paused)+ last = statelet wait = 1.5 - Date().timeIntervalSince(lastSent)if wait > 0 {let first = pending == nil@@ -53,6 +57,17 @@ final class LiveActivityController {Task { await activity.update(.init(state: state, staleDate: nil)) }}+ /// 暂停 / 继续, shown at once (not held back by the line throttle).+ func setPaused(_ on: Bool) {+ guard let activity, paused != on else { return }+ paused = on+ last.paused = on+ pending = nil+ lastSent = Date()+ let state = last+ Task { await activity.update(.init(state: state, staleDate: nil)) }+ }+func end() {guard let activity else { return }self.activity = nildiff --git a/ios/Sources/Cicada/LiveViews.swift b/ios/Sources/Cicada/LiveViews.swiftindex dcc698a..50fc588 100644--- a/ios/Sources/Cicada/LiveViews.swift+++ b/ios/Sources/Cicada/LiveViews.swift@@ -79,7 +79,7 @@ struct ListenBar: View {private var idle: some View {Group {- Text("开始听").font(.headline).foregroundStyle(Ink.ink).padding(.leading, 18)+ Text("开始听").font(.headline).foregroundStyle(Ink.ink).lineLimit(1).fixedSize().padding(.leading, 18)Rectangle().fill(Ink.line).frame(width: 1, height: 20)Menu {Section {diff --git a/ios/Sources/Cicada/RoomListen.swift b/ios/Sources/Cicada/RoomListen.swiftindex 0597374..bd9d1a7 100644--- a/ios/Sources/Cicada/RoomListen.swift+++ b/ios/Sources/Cicada/RoomListen.swift@@ -29,8 +29,11 @@ final class RoomListen: ObservableObject {/// 手机外放: a video app plays aloud while we listen from the background, so its audio keeps/// playing beside ours and the subtitles go to the picture-in-picture window (PiPSubtitles).@Published private(set) var speakerMode = false- /// A call, Siri or another app took the audio: the microphone is off until it ends.+ /// A call, Siri or another app took the audio, or 暂停 on the lock screen: the microphone is+ /// off until it ends.@Published private(set) var paused = false+ /// The pause is the user's (暂停): an interruption ending doesn't end it.+ private var userPaused = false/// Every finished line, for the Live Activity.var onLine: ((Line) -> Void)?@@ -82,6 +85,7 @@ final class RoomListen: ObservableObject {guard !isRunning else { return }speakerMode = speakerpaused = false+ userPaused = falselang = sourceLanguages.first { $0.locale == source } ?? sourceLanguages[0]self.target = targetstatus = L("正在准备…")@@ -176,7 +180,7 @@ final class RoomListen: ObservableObject {debugLog("room: interrupted")return}- guard paused else { return }+ guard paused, !userPaused else { return }do {try audio.resume()paused = false@@ -194,6 +198,32 @@ final class RoomListen: ObservableObject {private var resumeWhenActive = false+ /// 暂停 / 继续 (the Live Activity's button): the microphone off and on, the meeting going on.+ func setPaused(_ on: Bool) {+ guard isRunning, sessionID != nil, on != userPaused else { return }+ userPaused = on+ if on {+ paused = true+ level = 0+ draft = ""+ draftTranslation = ""+ status = L("已暂停")+ if !Self.silent { audio.pause() }+ debugLog("room: paused by the user")+ } else {+ do {+ if !Self.silent { try audio.resume() }+ paused = false+ status = ""+ debugLog("room: resumed by the user")+ } catch {+ debugLog("room: resume failed: \(error)")+ userPaused = true+ }+ }+ onStateChange?()+ }+/// The app is in front again: a pause whose end came too early to take the microphone back.func appBecameActive() {guard resumeWhenActive, isRunning, paused else { return }@@ -224,6 +254,7 @@ final class RoomListen: ObservableObject {guard isRunning else { return }isRunning = falsepaused = false+ userPaused = falseresumeWhenActive = falseif !Self.silent { audio.stop() }let stream = self.stream, reader = self.reader@@ -392,6 +423,12 @@ final class RoomAudio: @unchecked Sendable {try engine.start()}+ /// 暂停: nothing is heard or recorded until `resume`.+ func pause() {+ held = true+ engine.pause()+ }+/// The microphone again after an interruption, in whatever format the route now has.func resume() throws {held = falsediff --git a/ios/Sources/Cicada/SettingsView.swift b/ios/Sources/Cicada/SettingsView.swiftindex 7b1a775..0bdb3dd 100644--- a/ios/Sources/Cicada/SettingsView.swift+++ b/ios/Sources/Cicada/SettingsView.swift@@ -1,8 +1,7 @@import SwiftUI-/// 设置, as the design's: grey section labels over white cards. Only what the app does today:-/// the Ling key and model (纪要), the language meetings are translated into, and 说话人识别.-/// 同声传译 and 快速开始 come with M3 and M4.+/// 设置, as the design's: grey section labels over white cards: the Ling key and model (纪要), the+/// language meetings are translated into, 说话人识别, 面对面's own language, and 快速开始.struct SettingsView: View {/// iPad shows it as a sheet, with 完成.var sheet = false@@ -78,6 +77,31 @@ struct SettingsView: View {.tint(Ink.secondary)}}+ SectionLabel(text: L("面对面"))+ Card {+ row(Text("我说")) {+ Picker(selection: Binding(get: { model.face.mine.locale }, set: { l in+ guard let m = FaceToFace.lang(l) else { return }+ model.face.setLanguages(mine: m, theirs: m == model.face.theirs ? model.face.mine : model.face.theirs)+ model.objectWillChange.send()+ })) {+ ForEach(sourceLanguages, id: \.locale) { Text(verbatim: $0.name).tag($0.locale) }+ } label: { Text("我说") }+ .pickerStyle(.menu)+ .tint(Ink.secondary)+ }+ Hairline()+ row(Text("念给对方的声音")) {+ Text(verbatim: ling.hasKey ? "Ming" : L("手机自带")).foregroundStyle(Ink.secondary)+ }+ }+ SectionLabel(text: L("快速开始"))+ Card {+ NavigationLink { QuickStartPage() } label: {+ row(Text("操作按钮、控制中心和 Siri")) { Chevron() }+ }+ .buttonStyle(RowPress())+ }Text(L("版本 \(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "")")).font(.footnote).foregroundStyle(Ink.tertiary).frame(maxWidth: .infinity)@@ -91,6 +115,7 @@ struct SettingsView: View {}.background(Ink.ground).navigationDestination(isPresented: $model.showWordList) { WordListPage(vocabulary: model.vocabulary) }+ .navigationDestination(isPresented: $model.showQuickStart) { QuickStartPage() }.toolbar(sheet ? .visible : .hidden, for: .navigationBar).navigationTitle(sheet ? Text("设置") : Text("")).navigationBarTitleDisplayMode(.inline)@@ -241,3 +266,70 @@ struct KeyPage: View {Task { await ling.setKey(k) }}}++/// 设置 › 快速开始: where 开始听 can be put. iOS lets only the user choose them, in the system's own+/// settings; this page says where.+struct QuickStartPage: View {+ /// What Siri and the Action button list the app as.+ private let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ?? appDisplayName++ var body: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 0) {+ Text("不用先打开 app 就开始听,再按一次结束").font(.subheadline).foregroundStyle(Ink.secondary)+ .padding(.horizontal, 16).padding(.top, 12)+ SectionLabel(text: L("操作按钮"))+ Card {+ HStack(spacing: 16) {+ RoundedRectangle(cornerRadius: 14, style: .continuous).stroke(Ink.ink, lineWidth: 2)+ .frame(width: 56, height: 86)+ .overlay(alignment: .topLeading) {+ Capsule().fill(Ink.accent).frame(width: 4, height: 16).offset(x: -6, y: 16)+ }+ .accessibilityHidden(true)+ VStack(alignment: .leading, spacing: 6) {+ Text("按一下开始听").font(.headline).foregroundStyle(Ink.ink)+ Text(L("iPhone 设置 › 操作按钮 › 快捷指令 › \(name)“开始听”")).font(.footnote).foregroundStyle(Ink.secondary)+ Button("打开 iPhone 设置") {+ if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) }+ }+ .font(.subheadline.weight(.semibold)).tint(Ink.accentText)+ .frame(minHeight: 32)+ }+ }+ .padding(16)+ }+ SectionLabel(text: L("控制中心和锁屏"))+ Card {+ HStack(spacing: 16) {+ RoundedRectangle(cornerRadius: 18, style: .continuous).fill(Color(hex: 0x2A2D35))+ .frame(width: 60, height: 60)+ .overlay { Image(systemName: "mic.fill").foregroundStyle(.white).frame(width: 34, height: 34).background(Ink.accent, in: Circle()) }+ .accessibilityHidden(true)+ VStack(alignment: .leading, spacing: 6) {+ Text("“开始听”按钮").font(.headline).foregroundStyle(Ink.ink)+ Text("下拉控制中心,点左上角的 + 添加").font(.footnote).foregroundStyle(Ink.secondary)+ }+ Spacer(minLength: 0)+ }+ .padding(16)+ }+ SectionLabel(text: "Siri")+ Card {+ Text(L("“嘿 Siri,用\(name)开始听”")).padding(.horizontal, 16).frame(minHeight: 50)+ Hairline()+ Text(L("“嘿 Siri,\(name)结束”")).padding(.horizontal, 16).frame(minHeight: 50)+ }+ Text("都按上次的语言听").font(.footnote).foregroundStyle(Ink.tertiary)+ .padding(.horizontal, 16).padding(.top, 10)+ }+ .padding(.horizontal, 16)+ .padding(.bottom, 40)+ .frame(maxWidth: 640)+ .frame(maxWidth: .infinity)+ }+ .background(Ink.ground)+ .navigationTitle(Text("快速开始"))+ .navigationBarTitleDisplayMode(.inline)+ }+}diff --git a/ios/scripts/build.sh b/ios/scripts/build.shindex fed3976..23cca17 100755--- a/ios/scripts/build.sh+++ b/ios/scripts/build.sh@@ -15,12 +15,34 @@ files=()while IFS= read -r line; do [[ -z $line || $line == \#* ]] || files+=("$line"); done < ios/shared-sources.txtwhile IFS= read -r f; do files+=("$f"); done < <(find ios/Sources -name '*.swift' | sort)+SDKPATH=$(xcrun --show-sdk-path --sdk "$SDK")+# App Intents (Intents.swift) need the metadata Xcode extracts from the compiler's constant values:+# without Metadata.appintents in the bundle, Siri, Shortcuts, Control Center and the Live+# Activity's buttons don't know the intents. Each module is compiled whole (-wmo) to one+# .swiftconstvalues file, then appintentsmetadataprocessor writes the metadata into its bundle.+WORK=$(mktemp -d)+trap 'rm -rf "$WORK"' EXIT+printf '%s' '["AppIntent","AppEntity","TransientAppEntity","AppEnum","EntityQuery","AppShortcutsProvider","AppShortcutProviding","DynamicOptionsProvider","LiveActivityIntent","ControlConfigurationIntent","WidgetConfigurationIntent","_IntentValueRepresentable","AppIntentsPackage"]' > "$WORK/protocols.json"+CONST=(-wmo -Xfrontend -const-gather-protocols-file -Xfrontend "$WORK/protocols.json")+intents_metadata() { # <module> <bundle dir> <binary> <sources...>+ local module=$1 out=$2 binary=$3; shift 3+ printf '%s\n' "$@" > "$WORK/$module.sources"+ printf '%s\n' "$WORK/$module.swiftconstvalues" > "$WORK/$module.constvals"+ xcrun appintentsmetadataprocessor --toolchain-dir "$(dirname "$(dirname "$(dirname "$(xcrun -f swiftc)")")")" \+ --module-name "$module" --sdk-root "$SDKPATH" --xcode-version "$(xcodebuild -version | awk '/Build version/{print $3}')" \+ --platform-family iOS --deployment-target 26.0 --target-triple "$TARGET" --output "$out" \+ --source-file-list "$WORK/$module.sources" --swift-const-vals-list "$WORK/$module.constvals" \+ --binary-file "$binary" --deployment-aware-processing --no-app-shortcuts-localization --force --quiet-warnings >/dev/null 2>&1+ [[ -d "$out/Metadata.appintents" ]] || { echo "no App Intents metadata for $module"; exit 1; }+}+# STRINGS_OUT=<dir>: also write the UI text keys there (scripts/strings.py).extra=()[[ -n "${STRINGS_OUT:-}" ]] && extra=(-emit-localized-strings -emit-localized-strings-path "$STRINGS_OUT")xcrun --sdk "$SDK" swiftc -O -swift-version 5 -parse-as-library -module-name Cicada \- -target "$TARGET" -sdk "$(xcrun --show-sdk-path --sdk "$SDK")" -D CICADA_IOS \+ -target "$TARGET" -sdk "$SDKPATH" -D CICADA_IOS "${CONST[@]}" -emit-const-values-path "$WORK/Cicada.swiftconstvalues" \"${extra[@]+"${extra[@]}"}" "${files[@]}" -o "$APP/Cicada"+intents_metadata Cicada "$APP" "$APP/Cicada" "${files[@]}"cp ios/Resources/Info.plist "$APP/Info.plist"# UI text is the Mac's: the Chinese source is the key, the other languages translate it.@@ -47,10 +69,12 @@ rm -rf "$ICONS"# queue (the plain Swift entry point dies in libdispatch before the bundle loads).APPEX="$APP/PlugIns/CicadaLive.appex"mkdir -p "$APPEX"+LIVE=(ios/LiveActivity/*.swift ios/Sources/Cicada/ListenActivity.swift ios/Sources/Cicada/Intents.swift)xcrun --sdk "$SDK" swiftc -O -swift-version 5 -parse-as-library -application-extension -module-name CicadaLive \- -target "$TARGET" -sdk "$(xcrun --show-sdk-path --sdk "$SDK")" \+ -target "$TARGET" -sdk "$SDKPATH" -D CICADA_LIVE "${CONST[@]}" -emit-const-values-path "$WORK/CicadaLive.swiftconstvalues" \-Xlinker -e -Xlinker _NSExtensionMain \- ios/LiveActivity/*.swift ios/Sources/Cicada/ListenActivity.swift -o "$APPEX/CicadaLive"+ "${LIVE[@]}" -o "$APPEX/CicadaLive"+intents_metadata CicadaLive "$APPEX" "$APPEX/CicadaLive" "${LIVE[@]}"cp ios/LiveActivity/Info.plist "$APPEX/Info.plist"cp "$APP/logo.png" "$APPEX/"for d in "$APP"/*.lproj; do cp -R "$d" "$APPEX/"; done