知了 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: subtitles no longer show a lone "Translate" when Ling translates its own instruction instead of the line
wquguru0984b750fab6
diff --git a/Sources/Cicada/Translator.swift b/Sources/Cicada/Translator.swiftindex 175f192..cc12ca1 100644--- a/Sources/Cicada/Translator.swift+++ b/Sources/Cicada/Translator.swift@@ -209,6 +209,12 @@ final class TranslationService {return (o, t)}+ /// "Translate." in each target language, letters only and lowercased.+ nonisolated static let instructionEchoes: Set<String> = [+ "翻译", "翻譯", "translate", "翻訳", "翻訳して", "翻訳する", "翻訳してください", "번역", "번역해", "번역하세요", "번역해주세요",+ "traducir", "traduce", "traduzca", "traduire", "traduisez", "traduis", "übersetzen", "übersetze", "traduzir", "traduza",+ ]+/// Ling sometimes comments on a garbled subtitle ("The subtitle appears to be… Here is the/// best-effort translation:") instead of translating it, and that would land in the subtitles and/// the record. Remark lines are dropped, a "Translation:" label is stripped, and what is left must@@ -248,6 +254,10 @@ final class TranslationService {}out = out.trimmingCharacters(in: .whitespaces)guard !out.isEmpty else { return nil }+ // Ling translated the fixed "Translate." instruction instead of the subtitle ("翻译。" for an+ // empty subtitle, or for "Translate this into Chinese please."). A subtitle that really is+ // just "翻译一下" loses Ling's answer too, and the next provider translates it.+ if Self.instructionEchoes.contains(String(out.lowercased().unicodeScalars.filter { $0.properties.isAlphabetic })) { return nil }let letters = out.unicodeScalars.filter { $0.properties.isAlphabetic }let cjk = letters.filter { (0x3040...0x9FFF).contains($0.value) || (0xAC00...0xD7AF).contains($0.value) }.countlet wantsCJK = ["zh", "ja", "ko"].contains(where: { target.hasPrefix($0) })diff --git a/Tests/CicadaTests/TranslatorTests.swift b/Tests/CicadaTests/TranslatorTests.swiftindex a32d1e0..fd3e3b9 100644--- a/Tests/CicadaTests/TranslatorTests.swift+++ b/Tests/CicadaTests/TranslatorTests.swift@@ -16,6 +16,16 @@ import Testing#expect(TranslationService.cleanTranslation("“我们周五发布。”", target: "zh-CN") == "我们周五发布。")}+ @Test func translatedInstructionIsDropped() {+ // Ling answered "Translate this into Chinese please." and an empty subtitle with "翻译。":+ // the fixed "Translate." instruction, translated.+ #expect(TranslationService.cleanTranslation("翻译。", target: "zh-CN") == nil)+ #expect(TranslationService.cleanTranslation("Translate.", target: "en-US") == nil)+ #expect(TranslationService.cleanTranslation("翻訳してください。", target: "ja") == nil)+ #expect(TranslationService.cleanTranslation("好的,翻译。", target: "zh-CN") == "好的,翻译。")+ #expect(TranslationService.cleanTranslation("请翻译以下幻灯片。", target: "zh-CN") == "请翻译以下幻灯片。")+ }+@Test func ordinaryTranslationsAreKept() {#expect(TranslationService.cleanTranslation("The text is due on Friday.", target: "en-US") == "The text is due on Friday.")#expect(TranslationService.cleanTranslation("There are three points:", target: "en-US") == "There are three points:")