知了 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(android): holding the talk button without saying anything no longer says "Hmm." to the other person
wquguru828a2549899e
diff --git a/android/cli/src/main/kotlin/cicada/cli/Tests.kt b/android/cli/src/main/kotlin/cicada/cli/Tests.ktindex caef6b9..01cf421 100644--- a/android/cli/src/main/kotlin/cicada/cli/Tests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/Tests.kt@@ -31,6 +31,7 @@ object Tests {"theLiveMeetingCantBeDeleted" to ::theLiveMeetingCantBeDeleted,"followSystemLikeTheMac" to ::followSystemLikeTheMac,"anUntranslatedSentenceIsNeitherSentNorRecorded" to ::anUntranslatedSentenceIsNeitherSentNorRecorded,+ "aSilentHoldOrAFillerIsNotSaid" to ::aSilentHoldOrAFillerIsNotSaid,"anUnreachableServiceIsTriedOncePer15s" to ::anUnreachableServiceIsTriedOncePer15s,"storeSavesAndDropsEmptyMeetings" to ::storeSavesAndDropsEmptyMeetings,"closesInterruptedMeetings" to ::closesInterruptedMeetings,@@ -1051,6 +1052,40 @@ object Tests {} finally { LingClient.spacing = old }}+ fun aSilentHoldOrAFillerIsNotSaid() {+ var asked = 0+ val fake = Fake { body ->+ if (body.contains("Ming-3.0-audio-flash")) { asked++; reply("LANG: zh-CN\nORIGINAL: 嗯。\nTRANSLATION: Hmm.") }+ else Transport.Response(500, "")+ }+ val old = LingClient.spacing+ LingClient.spacing = 0.05+ try {+ val ling = client(fake)+ val store = SessionStore(loadNow = false)+ val engine = ListenEngine(ling, Translator(ling, fake), store, NotesEngine(ling, store), AppSettings(target = "zh-CN"))+ var spoken: String? = null+ engine.onSaid = { text, _ -> spoken = text }+ val src = ManualSource()+ engine.start(src, "mic")+ // Nobody spoke: the room's hush only, loud enough for the old check (rms 0.004).+ val hush = ShortArray(16000 * 2) { ((if (it % 2 == 0) 1 else -1) * 0.004 * 32767).toInt().toShort() }+ engine.hold(); src.push(hush); engine.release(); src.push(silence(0.3))+ Thread.sleep(600)+ equal(0, asked, "a silent hold isn't sent to the service")+ equal("没听到声音,靠近手机再说", engine.sayProblem, "and says why")+ // Ming hears only 嗯: nothing said.+ engine.hold(); src.push(tone(1.2)); engine.release(); src.push(silence(0.3))+ val until = System.currentTimeMillis() + 4000+ while (asked == 0 && System.currentTimeMillis() < until) Thread.sleep(20)+ Thread.sleep(300)+ equal(null, spoken, "a filler alone isn't said")+ check(store.get(engine.sessionId!!)!!.lines.none { it.speaker == "me" }, "nor recorded")+ engine.stop()+ } finally { LingClient.spacing = old }+ check(PressSpeech.filler("嗯嗯。") && PressSpeech.filler("Um, uh...") && !PressSpeech.filler("嗯,好的。") && !PressSpeech.filler("OK."), "fillers")+ }+// MARK: Meeting end (MeetingEndTests.swift, the same cases)private val zoom = mapOf("us.zoom.xos" to "Zoom")diff --git a/android/core/src/main/kotlin/cicada/ListenEngine.kt b/android/core/src/main/kotlin/cicada/ListenEngine.ktindex 95b4ccf..e5a028c 100644--- a/android/core/src/main/kotlin/cicada/ListenEngine.kt+++ b/android/core/src/main/kotlin/cicada/ListenEngine.kt@@ -209,7 +209,8 @@ class ListenEngine(for (b in mine) { b.copyInto(all, at); at += b.size }mine.clear(); all}- if (pcm.size < Segmenter.RATE / 2 || Wav.rms(pcm) < 0.003) {+ // Spoken, not just loud enough: a silent press came back from the service as "嗯" and was said as "Hmm." (the Mac's PressSpeech).+ if (pcm.size < Segmenter.RATE / 2 || !PressSpeech.spoken(pcm)) {sayProblem = if (pcm.size < Segmenter.RATE / 2) Strings.L("按住说完再松开") else Strings.L("没听到声音,靠近手机再说")changed(); return}@@ -226,6 +227,7 @@ class ListenEngine(try {val heard = translator.hear(encode(pcm), their, me, pcm.size / Segmenter.RATE.toDouble())if (heard == null) { sayProblem = Strings.L("没听清,再说一次"); return }+ if (PressSpeech.filler(heard.original)) { Log.d("listen: only a filler heard, not said"); return }var dst = heard.translationif (dst == null && !Languages.same(heard.lang, their)) dst = translator.translate(heard.original, heard.lang, their, Translator.Kind.Sentence)val sameLanguage = Languages.same(heard.lang, their)@@ -431,3 +433,35 @@ class ListenEngine(}}}++/** Whether anyone spoke during a hold (PressSpeech in the Mac's SpeakEngine.swift, same numbers):+ * 0.3 s of 30 ms frames over three times the hold's own quiet (its quietest tenth), between+ * -44 and -36 dBFS. A silent hold came back from Ming as "嗯。" and went out as "Hmm."; a result+ * that is only fillers isn't said either. */+object PressSpeech {+ private const val FRAME = 480+ private const val NEEDED = 0.3+ private val fillers = setOf("嗯", "啊", "呃", "哦", "唔", "额", "噢", "哎", "um", "uh", "hmm", "hm", "mm", "mhm", "ah", "oh", "er", "えー", "あの", "음", "어")++ fun spoken(pcm: ShortArray): Boolean {+ if (pcm.size < FRAME) return false+ val levels = ArrayList<Double>()+ var i = 0+ while (i + FRAME <= pcm.size) {+ var sum = 0.0+ for (k in i until i + FRAME) { val v = pcm[k] / 32768.0; sum += v * v }+ levels.add(Math.sqrt(sum / FRAME))+ i += FRAME+ }+ val floor = levels.sorted()[levels.size / 10]+ val line = minOf(0.016, maxOf(0.0063, floor * 3))+ return levels.count { it >= line } * FRAME / 16000.0 >= NEEDED+ }++ /** Nothing but fillers (嗯, 啊, um, hmm…), whatever the punctuation. */+ fun filler(text: String): Boolean {+ val words = text.lowercase().split(Regex("[^\\p{L}]+")).filter { it.isNotEmpty() }+ return words.isEmpty() || words.all { w -> w in fillers || (w.length > 1 && w.toSet().size == 1 && w.substring(0, 1) in fillers) }+ }+}+