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.

fix(ios): when listening can't start, a card under Start listening says why (no network, storage full, microphone not allowed) with the fix, and a speech model download shows how long it has waited

wquguru9afe36fc2d9c
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings
index 9a9f12c..e029cce 100644
--- a/Resources/en.lproj/Localizable.strings
+++ b/Resources/en.lproj/Localizable.strings
@@ -1172,6 +1172,9 @@
"网络连不上,连上后会自动继续" = "No internet. It carries on once you're back online";
"这台 Mac 的磁盘空间不够了" = "This Mac is low on disk space";
"这台 Mac 上的语音模型已满 5 种" = "This Mac already holds the most speech models it allows (5)";
+"这台手机的存储空间不够了" = "This phone is low on storage";
+"这台手机上的语音模型已满 5 种" = "This phone already holds the most speech models it allows (5)";
+"没能开始听,再试一次" = "Couldn't start listening. Try again";
"打开存储空间" = "Open Storage";
"打开听写设置" = "Open Dictation Settings";
"先用已装的:" = "Use one already here:";
diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.strings
index 9b35139..17797a1 100644
--- a/Resources/ja.lproj/Localizable.strings
+++ b/Resources/ja.lproj/Localizable.strings
@@ -1172,6 +1172,9 @@
"网络连不上,连上后会自动继续" = "ネットワークに接続できません。つながると自動で続けます";
"这台 Mac 的磁盘空间不够了" = "この Mac のディスク容量が足りません";
"这台 Mac 上的语音模型已满 5 种" = "この Mac の音声モデルが上限の 5 つに達しています";
+"这台手机的存储空间不够了" = "この iPhone のストレージが足りません";
+"这台手机上的语音模型已满 5 种" = "この iPhone の音声モデルが上限の 5 つに達しています";
+"没能开始听,再试一次" = "聞き取りを開始できませんでした。もう一度お試しください";
"打开存储空间" = "ストレージを開く";
"打开听写设置" = "音声入力の設定を開く";
"先用已装的:" = "入っている言語で続ける:";
diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.strings
index eb866ed..0b95e4a 100644
--- a/Resources/ko.lproj/Localizable.strings
+++ b/Resources/ko.lproj/Localizable.strings
@@ -1172,6 +1172,9 @@
"网络连不上,连上后会自动继续" = "네트워크에 연결할 수 없어요. 연결되면 자동으로 계속해요";
"这台 Mac 的磁盘空间不够了" = "이 Mac의 디스크 공간이 부족해요";
"这台 Mac 上的语音模型已满 5 种" = "이 Mac의 음성 모델이 최대 5개에 도달했어요";
+"这台手机的存储空间不够了" = "이 휴대폰의 저장 공간이 부족해요";
+"这台手机上的语音模型已满 5 种" = "이 휴대폰의 음성 모델이 최대 5개에 도달했어요";
+"没能开始听,再试一次" = "듣기를 시작하지 못했어요. 다시 시도해 주세요";
"打开存储空间" = "저장 공간 열기";
"打开听写设置" = "받아쓰기 설정 열기";
"先用已装的:" = "설치된 언어로 계속:";
diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.strings
index ad79c83..16b278b 100644
--- a/Resources/zh-Hans.lproj/Localizable.strings
+++ b/Resources/zh-Hans.lproj/Localizable.strings
@@ -1154,6 +1154,9 @@
"网络连不上,连上后会自动继续" = "网络连不上,连上后会自动继续";
"这台 Mac 的磁盘空间不够了" = "这台 Mac 的磁盘空间不够了";
"这台 Mac 上的语音模型已满 5 种" = "这台 Mac 上的语音模型已满 5 种";
+"这台手机的存储空间不够了" = "这台手机的存储空间不够了";
+"这台手机上的语音模型已满 5 种" = "这台手机上的语音模型已满 5 种";
+"没能开始听,再试一次" = "没能开始听,再试一次";
"打开存储空间" = "打开存储空间";
"打开听写设置" = "打开听写设置";
"先用已装的:" = "先用已装的:";
diff --git a/ios/Sources/Cicada/Debug.swift b/ios/Sources/Cicada/Debug.swift
index 08e158c..049728d 100644
--- a/ios/Sources/Cicada/Debug.swift
+++ b/ios/Sources/Cicada/Debug.swift
@@ -182,6 +182,12 @@ extension AppModel {
// A meeting without the microphone or the recognizer, fed lines by `heard:`.
RoomListen.silent = arg != "off"
case "heard": room.debugHeard(arg)
+ case "modelFail":
+ // modelFail:<offline|disk|limit|other>: the next speech model download fails that way, as on the Mac.
+ RoomListen.simulatedModelFailure = arg.isEmpty ? nil : arg
+ case "startRetry":
+ // 再试一次 on the card under 开始听.
+ room.retry()
case "aiCustomOnly":
// aiCustomOnly:on|off, 语音和文字只发给你的服务, as on the Mac.
UserDefaults.standard.set(arg == "on", forKey: AIPrefs.customOnly)
@@ -403,6 +409,7 @@ extension AppModel {
debugLog("import busy=\(importer.busy) phase=\(importer.phase) progress=\(String(format: "%.2f", importer.progress)) queue=\(importer.queue.count) current=\(importer.current?.id ?? "-")")
case "state":
debugLog("memory \(DeviceLoad.line)")
+ debugLog("room problem=\(room.problem.map { "\($0)" } ?? "-") downloading=\(room.downloading?.name ?? "-")")
debugLog("room running=\(room.isRunning) lines=\(room.lines.count) draft=\(room.draft.count) level=\(room.level) status=\(room.status) speaker=\(room.speakerMode) paused=\(room.paused) pip=\(pip.isActive) session=\(room.sessionID ?? "-")")
debugLog("state tab=\(tab.rawValue) selection=\(selection ?? "-") page=\(recordPage) sessions=\(store.sessions.count) query=\(query) notesLang=\(notesLanguageCode(selection ?? store.sessions.first?.id ?? "")) undo=\(speakerUndo?.text ?? "-")")
default:
diff --git a/ios/Sources/Cicada/LiveViews.swift b/ios/Sources/Cicada/LiveViews.swift
index f440b78..43f5f6a 100644
--- a/ios/Sources/Cicada/LiveViews.swift
+++ b/ios/Sources/Cicada/LiveViews.swift
@@ -181,6 +181,7 @@ struct LivePhone: View {
ListenBar()
PillSwitch(selection: $model.livePage, options: [(.notes, notesTitle), (.subtitles, "字幕")])
EndingStrip()
+ ModelWaitCard()
TranslateDownCard()
if let id = room.sessionID { FixAskCard(fixes: model.fixes, session: id) }
}
@@ -344,6 +345,7 @@ struct LivePad: View {
var body: some View {
VStack(spacing: 0) {
EndingStrip().frame(maxWidth: 560).padding(.horizontal, 20).padding(.top, 18)
+ ModelWaitCard().frame(maxWidth: 560).padding(.horizontal, 20).padding(.top, 18)
TranslateDownCard().frame(maxWidth: 560).padding(.horizontal, 20).padding(.top, 18)
if let id = room.sessionID {
FixAskCard(fixes: model.fixes, session: id).frame(maxWidth: 560).padding(.horizontal, 20).padding(.top, 18)
@@ -392,3 +394,96 @@ struct LivePad: View {
.frame(maxWidth: .infinity, alignment: .leading)
}
}
+
+/// A speech model on its way: the system says only "not yet" or "done", so a moving bar and the time
+/// waited show it is still coming (the Mac's download card).
+struct ModelWaitCard: View {
+ @EnvironmentObject var room: RoomListen
+
+ var body: some View {
+ if let d = room.downloading {
+ VStack(alignment: .leading, spacing: 6) {
+ HStack(spacing: 10) {
+ ProgressView().tint(Ink.tertiary)
+ Text(L("正在下载 \(d.name) 语音模型")).font(.subheadline.weight(.semibold)).foregroundStyle(Ink.ink)
+ }
+ TimelineView(.periodic(from: .now, by: 1)) { context in
+ let s = max(0, Int(context.date.timeIntervalSince(d.since)))
+ Text(L("约 140 MB · 已等 \(String(format: "%d:%02d", s / 60, s % 60))"))
+ .font(.footnote).foregroundStyle(Ink.secondary).monospacedDigit()
+ }
+ }
+ .padding(14)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(Color.white, in: RoundedRectangle(cornerRadius: 18, style: .continuous))
+ }
+ }
+}
+
+/// Under 开始听 when it didn't start: why, and the one thing that helps (the Mac's 听不出 card for a
+/// speech model; the microphone permission; anything else, 再试一次).
+struct StartProblemCard: View {
+ @EnvironmentObject var room: RoomListen
+
+ var body: some View {
+ if !room.isRunning, let p = room.problem {
+ VStack(alignment: .leading, spacing: 10) {
+ HStack(alignment: .top, spacing: 10) {
+ Image(systemName: "exclamationmark.triangle.fill").foregroundStyle(Ink.accent).padding(.top, 2)
+ VStack(alignment: .leading, spacing: 3) {
+ Text(title(p)).font(.subheadline.weight(.semibold)).foregroundStyle(Ink.ink)
+ if let r = reason(p) {
+ Text(r).font(.footnote).foregroundStyle(Ink.secondary).fixedSize(horizontal: false, vertical: true)
+ }
+ }
+ Spacer(minLength: 0)
+ Button { room.dismissProblem() } label: {
+ Image(systemName: "xmark").font(.footnote.weight(.semibold)).foregroundStyle(Ink.tertiary)
+ .frame(width: 32, height: 32)
+ }
+ .buttonStyle(.plain).accessibilityLabel(Text("关闭"))
+ }
+ if let (label, act) = action(p) {
+ Button(action: act) {
+ Text(label).font(.subheadline.weight(.semibold)).foregroundStyle(.white)
+ .padding(.horizontal, 16).frame(minHeight: 36)
+ .background(Ink.ink, in: Capsule())
+ }
+ .buttonStyle(.plain).padding(.leading, 28)
+ }
+ }
+ .padding(14)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(Color.white, in: RoundedRectangle(cornerRadius: 18, style: .continuous))
+ }
+ }
+
+ private func title(_ p: RoomListen.StartProblem) -> String {
+ switch p {
+ case .microphone: L("请在设置里允许知了使用麦克风")
+ case .model(let m): L("没能下载 \(m.lang.name) 语音模型")
+ case .other(let message): message
+ }
+ }
+
+ private func reason(_ p: RoomListen.StartProblem) -> String? {
+ guard case .model(let m) = p else { return nil }
+ switch m.cause {
+ case .offline: return L("网络连不上,连上后会自动继续")
+ case .disk: return L("这台手机的存储空间不够了")
+ case .limit: return L("这台手机上的语音模型已满 5 种")
+ case .dictation(let message), .other(let message?): return message
+ case .other(nil): return nil
+ }
+ }
+
+ private func action(_ p: RoomListen.StartProblem) -> (String, () -> Void)? {
+ let settings = { if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) } }
+ switch p {
+ case .microphone: return (L("打开 iPhone 设置"), settings)
+ case .model(let m) where m.cause == .disk: return (L("打开 iPhone 设置"), settings)
+ case .model(let m) where m.cause == .offline: return nil
+ default: return (L("再试一次"), { room.retry() })
+ }
+ }
+}
diff --git a/ios/Sources/Cicada/RecordsView.swift b/ios/Sources/Cicada/RecordsView.swift
index c2744b1..a35dcc3 100644
--- a/ios/Sources/Cicada/RecordsView.swift
+++ b/ios/Sources/Cicada/RecordsView.swift
@@ -26,6 +26,7 @@ struct RecordsSplit: View {
.padding(.top, 6)
VStack(spacing: 10) {
ListenBar()
+ StartProblemCard()
if !room.isRunning { FaceRow(face: model.face) }
}
.padding(.top, 16)
@@ -108,6 +109,7 @@ struct PadRoot: View {
.padding(.horizontal, 4)
VStack(spacing: 8) {
ListenBar(onGlass: true)
+ StartProblemCard()
if !room.isRunning { FaceRow(face: model.face, onGlass: true) }
}
.padding(.top, 14).padding(.bottom, 12)
diff --git a/ios/Sources/Cicada/RoomListen.swift b/ios/Sources/Cicada/RoomListen.swift
index f8226a3..6ce1ae6 100644
--- a/ios/Sources/Cicada/RoomListen.swift
+++ b/ios/Sources/Cicada/RoomListen.swift
@@ -1,5 +1,6 @@
import AVFoundation
import Foundation
+import Network
/// 听会议室 on iPhone and iPad: the microphone → the shared recognizer (`Recognition`) → the shared
/// translation chain → the meeting record, with live notes from the shared `NotesEngine`. The Mac's
@@ -36,6 +37,24 @@ final class RoomListen: ObservableObject {
/// The pause is the user's (暂停): an interruption ending doesn't end it.
private var userPaused = false
+ /// Why 开始听 didn't start, shown under it: listening has stopped, so the live screen (where
+ /// `status` goes) is gone and a bare status would never be seen.
+ enum StartProblem: Equatable {
+ case microphone
+ /// A speech model that couldn't be had (the Mac's `ModelProblem`, its causes and words).
+ case model(ModelProblem)
+ case other(String)
+ }
+ @Published private(set) var problem: StartProblem?
+ /// A speech model on its way since then (约 140 MB · 已等 …).
+ @Published private(set) var downloading: (name: String, since: Date)?
+ /// Debug (`modelFail:<offline|disk|limit|other>`): the next model download fails that way.
+ static var simulatedModelFailure: String?
+ /// How the last 开始听 was asked, for 再试一次 and the network coming back.
+ private var lastStart: (source: String, target: String, voices: Bool, speaker: Bool)?
+ private let path = NWPathMonitor()
+ private var online = true
+
/// Every finished line, for the Live Activity.
var onLine: ((Line) -> Void)?
/// A line was written or its words changed (a joined sentence): the word list's known
@@ -101,8 +120,29 @@ final class RoomListen: ObservableObject {
if let i = self.lines.firstIndex(where: { $0.id == lineID }) { self.lines[i].voice = voice }
debugLog("voice profiles: heard \(match.profile.name) (\(String(format: "%.2f", match.similarity)))")
}
+ // A download that failed for want of a network starts again once there is one (as on the Mac).
+ path.pathUpdateHandler = { [weak self] p in
+ let up = p.status == .satisfied
+ DispatchQueue.main.async {
+ MainActor.assumeIsolated {
+ guard let self, up != self.online else { return }
+ self.online = up
+ if up, case .model(let m)? = self.problem, m.cause == .offline { self.retry() }
+ }
+ }
+ }
+ path.start(queue: .global(qos: .utility))
+ }
+
+ /// 再试一次: 开始听 again as it was asked.
+ func retry() {
+ guard !isRunning, let s = lastStart else { return }
+ debugLog("room: start again after \(String(describing: problem))")
+ start(source: s.source, target: s.target, voices: s.voices, speaker: s.speaker)
}
+ func dismissProblem() { problem = nil }
+
/// 记住的人 (PeoplePage.swift): voices remembered by voiceprint, matched while listening.
var profiles: SpeakerProfileStore? { didSet { speakers.profiles = profiles } }
@@ -117,6 +157,8 @@ final class RoomListen: ObservableObject {
func start(source: String, target: String, voices: Bool, speaker: Bool = false) {
guard !isRunning else { return }
+ lastStart = (source, target, voices, speaker)
+ problem = nil
speakerMode = speaker
paused = false
userPaused = false
@@ -154,6 +196,7 @@ final class RoomListen: ObservableObject {
return
}
guard await AVAudioApplication.requestRecordPermission() else {
+ problem = .microphone
fail(L("请在设置里允许知了使用麦克风"))
return
}
@@ -171,8 +214,7 @@ final class RoomListen: ObservableObject {
debugLog("room: auto candidates=\(candidates.map(\.locale)) start=\(lang.locale)")
}
if await Recognition.status(lang.locale) != .installed {
- status = L("正在下载 \(lang.name) 语音模型…")
- try await Recognition.install(lang.locale)
+ try await fetch(lang)
}
let stream = try await Recognition.start(lang.locale, drafts: true, confidence: true)
guard isRunning else { await stream.cancel(); return }
@@ -207,9 +249,14 @@ final class RoomListen: ObservableObject {
if !settled { watchLanguage() }
debugLog("room: listening locale=\(lang.locale) target=\(target) speaker=\(speakerMode) format=\(stream.format) session=\(s.id)")
onStateChange?()
+ } catch let failure as ModelFailure {
+ problem = .model(failure.problem)
+ fail(L("没能下载 \(lang.name) 语音模型"))
} catch {
debugLog("room: start failed: \(error)")
- fail(Recognition.needsUser(error) ? error.localizedDescription : L("没能下载 \(lang.name) 语音模型"))
+ let message = Recognition.needsUser(error) ? error.localizedDescription : L("没能开始听,再试一次")
+ problem = .other(message)
+ fail(message)
}
}
@@ -241,8 +288,7 @@ final class RoomListen: ObservableObject {
var out: [Lang] = []
for lang in likely {
if await Recognition.status(lang.locale) != .installed {
- status = L("正在下载 \(lang.name) 语音模型…")
- do { try await Recognition.install(lang.locale) } catch {
+ do { try await fetch(lang) } catch {
debugLog("room: auto can't fetch \(lang.locale): \(error)")
continue
}
@@ -402,6 +448,50 @@ final class RoomListen: ObservableObject {
/// Debug (`interrupt:began|ended`): what the system sends for a call or Siri.
func debugInterrupt(_ began: Bool) { audio.debugInterrupt(began) }
+ /// A speech model that couldn't be had, as the start's error: the card under 开始听 says why.
+ struct ModelFailure: Error { let problem: ModelProblem }
+
+ /// Downloads `lang`'s speech model. At the five-model limit one this app isn't using (and isn't a
+ /// likely language) is given back and the download tried once more, as on the Mac.
+ private func fetch(_ lang: Lang) async throws {
+ status = L("正在下载 \(lang.name) 语音模型…")
+ downloading = (lang.name, Date())
+ defer { downloading = nil }
+ var freed = false
+ while true {
+ let simulated = Self.simulatedModelFailure
+ do {
+ if let simulated {
+ Self.simulatedModelFailure = nil
+ try await Task.sleep(nanoseconds: 1_500_000_000)
+ throw ModelProblem.simulated(simulated)
+ }
+ try await Recognition.install(lang.locale)
+ return
+ } catch {
+ let cause = ModelProblem.cause(of: error, online: online, freeBytes: ModelProblem.freeBytes())
+ debugLog("room: model problem \(lang.locale): \(cause)")
+ if cause == .limit, simulated == nil, !freed, await freeModelSlot(for: lang) {
+ freed = true
+ continue
+ }
+ throw ModelFailure(problem: ModelProblem(lang: lang, cause: cause, picked: true))
+ }
+ }
+ }
+
+ private func freeModelSlot(for wanted: Lang) async -> Bool {
+ let keep = Set(likelySourceLanguages(last: UserDefaults.standard.string(forKey: Pref.lastDetected),
+ systemLanguages: Locale.preferredLanguages).map(\.locale) + [wanted.locale, lang.locale])
+ for locale in await Recognition.reservedLocales() where !keep.contains(locale) {
+ if await Recognition.release(locale) {
+ debugLog("room: model limit, gave back \(locale) for \(wanted.locale)")
+ return true
+ }
+ }
+ return false
+ }
+
private func fail(_ message: String) {
status = message
isRunning = false
diff --git a/ios/shared-sources.txt b/ios/shared-sources.txt
index 617df4b..1a17ccc 100644
--- a/ios/shared-sources.txt
+++ b/ios/shared-sources.txt
@@ -33,3 +33,4 @@ Sources/Cicada/NotesEditing.swift
Sources/Cicada/SpeakerEnrollment.swift
Sources/Cicada/HandsFree.swift
Sources/Cicada/TranscriptSearch.swift
+Sources/Cicada/ModelProblem.swift