知了 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
fix(language): start auto in the Mac language, not English
clementchen926069280f49
diff --git a/Sources/Cicada/Languages.swift b/Sources/Cicada/Languages.swiftindex eda95da..36865d8 100644--- a/Sources/Cicada/Languages.swift+++ b/Sources/Cicada/Languages.swift@@ -78,6 +78,20 @@ func likelySourceLanguages(last: String?, systemLanguages prefs: [String]) -> [Lreturn out}+/// The model auto starts with: the room's own language, else the last meeting's, else the+/// Mac's language before the remaining installed models. `candidates` is in `sourceLanguages`+/// order (English first), so taking `candidates.first` would start every fresh Mac in English.+func initialSourceLanguage(candidates: [Lang], last: String?, systemLanguages prefs: [String],+ mine: Lang? = nil) -> Lang {+ if let mine { return mine }+ if let last, let lang = candidates.first(where: { $0.locale == last }) { return lang }+ let likely = likelySourceLanguages(last: last, systemLanguages: prefs)+ return likely.first(where: { candidates.contains($0) })+ ?? likely.first+ ?? candidates.first+ ?? sourceLanguages[0]+}+/// The speech locale to listen for when I speak my language (English when it isn't one we recognize).func speakLocale(forLanguage code: String) -> String {if code.hasPrefix("zh") { return "zh-CN" }diff --git a/Sources/Cicada/ListenEngine.swift b/Sources/Cicada/ListenEngine.swiftindex de6bdc4..ad7eb45 100644--- a/Sources/Cicada/ListenEngine.swift+++ b/Sources/Cicada/ListenEngine.swift@@ -405,11 +405,11 @@ final class ListenEngine {initial = langcase .auto:let last = UserDefaults.standard.string(forKey: "lastDetected")- let likely = likelySourceLanguages(last: last, systemLanguages: systemLanguages)- // No model at all: start with the likeliest; the second follows in the background.// The people at the table most likely speak yours (同声传译's 我说), not the last online meeting's.- let mine = role == .room || settings.listensToRoom ? candidates.first(where: { $0.locale == settings.speakFromLang.locale }) : nil- initial = mine ?? candidates.first(where: { $0.locale == last }) ?? candidates.first ?? likely.first ?? sourceLanguages[0]+ let mine = role == .room || settings.listensToRoom+ ? candidates.first(where: { $0.locale == settings.speakFromLang.locale }) : nil+ initial = initialSourceLanguage(candidates: candidates, last: last,+ systemLanguages: systemLanguages, mine: mine)}// 会议室 the first time: nothing is heard until macOS's microphone question is answered.setStatus(audioTap == nil ? L("等你允许使用麦克风") : L("正在听"))diff --git a/Tests/CicadaTests/LanguageTests.swift b/Tests/CicadaTests/LanguageTests.swiftindex c957a33..7f18c8b 100644--- a/Tests/CicadaTests/LanguageTests.swift+++ b/Tests/CicadaTests/LanguageTests.swift@@ -94,4 +94,19 @@ import Testing// Languages with no speech model are skipped; English is always there.#expect(locales(likelySourceLanguages(last: "xx", systemLanguages: ["it-IT"])) == ["en-US"])}++ @Test func autoStartsInTheMacLanguageNotEnglish() {+ let en = sourceLanguages.first { $0.code == "en" }!+ let zh = sourceLanguages.first { $0.code == "zh-CN" }!+ // `candidates` comes in sourceLanguages order, English first. A fresh Chinese Mac must+ // still start in Chinese; otherwise the English model transcribes Chinese as English.+ #expect(initialSourceLanguage(candidates: [en, zh], last: nil,+ systemLanguages: ["zh-Hans-CN"]) == zh)+ // A last meeting in English still wins, as before.+ #expect(initialSourceLanguage(candidates: [en, zh], last: "en-US",+ systemLanguages: ["zh-Hans-CN"]) == en)+ // Only English installed: English is the only thing it can start.+ #expect(initialSourceLanguage(candidates: [en], last: nil,+ systemLanguages: ["zh-Hans-CN"]) == en)+ }}