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(android): hold music, ringback tones and typing no longer show up as lines of filler words

wquguru7f07ee838ba8
diff --git a/android/cli/src/main/kotlin/cicada/cli/Tests.kt b/android/cli/src/main/kotlin/cicada/cli/Tests.kt
index 067d191..db41b0e 100644
--- a/android/cli/src/main/kotlin/cicada/cli/Tests.kt
+++ b/android/cli/src/main/kotlin/cicada/cli/Tests.kt
@@ -34,6 +34,7 @@ object Tests {
"namesAVoiceLikeTheMac" to ::namesAVoiceLikeTheMac,
"displayTitle" to ::displayTitle,
"parsesMingReplies" to ::parsesMingReplies,
+ "dropsNoise" to ::dropsNoise,
"speaksOnlyTranslations" to ::speaksOnlyTranslations,
"hangUpEndsAfterTheGrace" to ::hangUpEndsAfterTheGrace,
"rejoiningWithinTheGraceKeepsGoing" to ::rejoiningWithinTheGraceKeepsGoing,
@@ -343,6 +344,23 @@ object Tests {
equal("ja", Translator.parseHeard("lang: ja-JP\noriginal: はい\ntranslation: 是", "zh-CN", null)!!.lang, "labels in any case")
}
+ // Same cases as the Windows and Linux ports' noise tests.
+ fun dropsNoise() {
+ for (o in listOf("嗯。", "Mm.", "uh, um", "呃呃呃呃呃", "嗯,嗯,嗯,嗯,嗯,嗯,嗯,嗯,嗯,嗯,嗯,嗯。", "滴答".repeat(50),
+ "hmmmm", "うーん", "음…", "喂?", "No no no no no no",
+ "(无语音内容)", "[Music]", "♪♪", "这段音频是一段旋律,没有说话声。", "There is no speech in this audio."))
+ check(Translator.isNoise(o), "noise: $o")
+ for (o in listOf("嗯,好的。", "OK.", "Oh no, it crashed.", "对", "对对对", "谢谢谢谢", "喂喂,能听到吗?", "No, no, no.",
+ "えーと、来週の件ですが", "あの人です", "Okay, let's move on to the quarterly numbers.", "(笑)好的"))
+ check(!Translator.isNoise(o), "kept: $o")
+ val long = "我们今天讨论一下这个季度的数字和下个季度的计划安排"
+ check(Translator.isNoise(long, 1.0), "more than anyone says in a second")
+ check(!Translator.isNoise(long, 4.0), "said in four seconds")
+ equal(null, Translator.parseHeard("LANG: zh-CN\nORIGINAL: 嗯,嗯,嗯,嗯,嗯,嗯。\nTRANSLATION: 嗯,嗯,嗯,嗯,嗯,嗯。", "zh-CN", null), "hold music")
+ equal(800, Translator.hearTokens(0.0), "unknown length"); equal(380, Translator.hearTokens(8.0), "a full segment")
+ equal(800, Translator.hearTokens(30.0), "capped")
+ }
+
fun normalizesLanguages() {
equal("zh-CN", Languages.normalize("zh-Hans", "en"), "zh-Hans")
equal("zh-TW", Languages.normalize("zh-TW", "en"), "zh-TW")
diff --git a/android/core/src/main/kotlin/cicada/ListenEngine.kt b/android/core/src/main/kotlin/cicada/ListenEngine.kt
index dd49930..0c6b971 100644
--- a/android/core/src/main/kotlin/cicada/ListenEngine.kt
+++ b/android/core/src/main/kotlin/cicada/ListenEngine.kt
@@ -218,7 +218,7 @@ class ListenEngine(
val their = theirLanguage
val me = target
try {
- val heard = translator.hear(encode(pcm), their, me)
+ val heard = translator.hear(encode(pcm), their, me, pcm.size / Segmenter.RATE.toDouble())
if (heard == null) { sayProblem = Strings.L("没听清,再说一次"); return }
var dst = heard.translation
if (dst == null && !Languages.same(heard.lang, their)) dst = translator.translate(heard.original, heard.lang, their, Translator.Kind.Sentence)
@@ -272,7 +272,7 @@ class ListenEngine(
// Into what the meeting's language translates to; a segment that turns out to be
// in my own language under "follow system" is translated again (record).
val asked = settings.targetFor(lang)
- heard = translator.hear(clip, asked, lang)?.let { h ->
+ heard = translator.hear(clip, asked, lang, seg.seconds)?.let { h ->
if (settings.targetFor(h.lang) == asked) h else h.copy(translation = null)
}
problem = null
diff --git a/android/core/src/main/kotlin/cicada/Translator.kt b/android/core/src/main/kotlin/cicada/Translator.kt
index 1f23f9c..5c0c7f6 100644
--- a/android/core/src/main/kotlin/cicada/Translator.kt
+++ b/android/core/src/main/kotlin/cicada/Translator.kt
@@ -19,11 +19,12 @@ class Translator(private val ling: LingClient, private val transport: Transport
/// One stretch of speech (16 kHz mono, WAV or compressed) heard and interpreted. `hint` is the language the
/// meeting has been in, which keeps Ming from flipping on a short or accented stretch. Null
/// when there was no speech or the reply wasn't in the three-line form; never a guess.
- fun hear(clip: Clip, target: String, hint: String?): Heard? {
+ /// `seconds` is the clip's length (0: unknown): it caps the reply and catches a runaway one.
+ fun hear(clip: Clip, target: String, hint: String?, seconds: Double = 0.0): Heard? {
val reply = ling.chat(hearPrompt(target, hint, glossary()), hearInstruction(target), Priority.Translate,
- maxTokens = 800, timeout = 12.0, model = LingClient.AUDIO_MODEL,
+ maxTokens = hearTokens(seconds), timeout = 12.0, model = LingClient.AUDIO_MODEL,
audio = clip.bytes, audioType = clip.type)
- return parseHeard(reply, target, hint)
+ return parseHeard(reply, target, hint, seconds)
}
// MARK: Text
@@ -83,7 +84,7 @@ class Translator(private val ling: LingClient, private val transport: Transport
/// `LANG: … / ORIGINAL: … / TRANSLATION: …`. Drops replies without an original, "NONE" (music,
/// silence), and translations not in the target's script; a dropped translation leaves the
/// original for the text translator to try.
- fun parseHeard(reply: String, target: String, hint: String?): Heard? {
+ fun parseHeard(reply: String, target: String, hint: String?, seconds: Double = 0.0): Heard? {
var lang: String? = null; var original: String? = null; var translation: String? = null
for (raw in reply.split('\n')) {
val line = raw.trim()
@@ -93,6 +94,7 @@ class Translator(private val ling: LingClient, private val transport: Transport
val o = original
if (o.isNullOrBlank() || o.trim('.', '。', ' ').equals("NONE", ignoreCase = true)) return null
if (o.none { it.isLetterOrDigit() }) return null
+ if (isNoise(o, seconds)) { Log.d("hear: noise dropped"); return null }
val code = Languages.normalize(lang, hint ?: "en")
var t = translation
if (code == target) t = o
@@ -103,6 +105,61 @@ class Translator(private val ling: LingClient, private val transport: Transport
return Heard(code, o, t)
}
+ /// Room for a reply to `seconds` of audio: a fast talker's original and translation fit; a
+ /// reply that runs on repeating itself ("滴答" ×800 from typing) stops early. 0: unknown.
+ fun hearTokens(seconds: Double) = if (seconds <= 0) 800 else minOf(800, (60 + 40 * seconds).toInt())
+
+ /// Ming writes something for every stretch it is sent, speech or not (it can't be asked for
+ /// NONE, see hearInstruction): hold music, a ringback tone, a fan or typing came back as "嗯。",
+ /// "嗯,嗯,嗯…" or "滴答" ×800. That is noise: fillers only, one short sound six or more times
+ /// over, or more than anyone says in `seconds` (0: unknown). A short real answer ("对",
+ /// "好的", "喂,能听到吗") stays. Same rules and lists as the Windows and Linux ports.
+ fun isNoise(original: String, seconds: Double = 0.0): Boolean {
+ val text = original.lowercase().replace(ANNOTATION, " ")
+ if (NO_SPEECH.any { text.contains(it) }) return true
+ val words = mutableListOf<String>()
+ val word = StringBuilder()
+ for (c in text) {
+ if (c.isLetterOrDigit()) word.append(c) else if (word.isNotEmpty()) { words.add(word.toString()); word.clear() }
+ }
+ if (word.isNotEmpty()) words.add(word.toString())
+ if (words.isEmpty()) return true
+ if (words.all(::isFillerWord)) return true
+ // Each CJK character is a unit, as a word is elsewhere.
+ val units = words.flatMap { w -> if (w.any(::isCjk)) w.map { it.toString() } else listOf(w) }
+ val n = units.size
+ for (p in 1..4) if (n >= 6 * p && (p until n).all { units[it] == units[it - p] }) return true
+ return seconds > 0 && n > maxOf(12.0, 12 * seconds)
+ }
+
+ /// Ming describing the audio instead of transcribing it: "(无语音内容)", "[Music]", "这段音频是一段
+ /// 旋律,没有说话声。". A bracketed note beside real words ("(笑)好的") keeps the words.
+ private val ANNOTATION = Regex("[((\\[【][^))\\]】]*[))\\]】]|♪")
+ private val NO_SPEECH = listOf(
+ "没有说话", "无语音", "没有语音", "没有人声", "无人声", "没有人说话", "无人说话",
+ "no speech", "no spoken", "no one is speaking", "nobody is speaking", "no audible speech", "no dialogue",
+ "音声がありません", "発話がありません", "話し声はありません", "음성이 없습니다", "말소리가 없습니다",
+ )
+
+ private val FILLERS = listOf(
+ "嗯", "啊", "呃", "额", "哦", "噢", "喔", "唔", "哈", "诶", "欸", "哎", "喂", "嘿", "哼",
+ "uh", "uhm", "um", "umm", "hmm", "hm", "mm", "mhm", "ah", "oh", "eh", "er", "erm", "huh",
+ "え", "えー", "あ", "あー", "う", "うー", "うん", "うーん", "ん", "えっと", "ええと", "あの",
+ "음", "어", "아", "응", "흠", "으",
+ )
+
+ /// Made of fillers only, a held sound shortened first: "嗯嗯嗯", "hmmmm", "えーと" is not.
+ private fun isFillerWord(raw: String): Boolean {
+ val w = StringBuilder()
+ for (c in raw) if (w.length < 2 || w[w.length - 1] != c || w[w.length - 2] != c) w.append(c)
+ val ok = BooleanArray(w.length + 1); ok[0] = true
+ for (i in 1..w.length) ok[i] = FILLERS.any { f -> f.length <= i && ok[i - f.length] && w.regionMatches(i - f.length, f, 0, f.length) }
+ return ok[w.length]
+ }
+
+ private fun isCjk(c: Char) = c.code in 0x3040..0x30FF || c.code in 0x3400..0x4DBF || c.code in 0x4E00..0x9FFF ||
+ c.code in 0xF900..0xFAFF || c.code in 0xAC00..0xD7AF
+
private fun take(line: String, label: String) =
if (line.startsWith(label, ignoreCase = true)) line.substring(label.length).trim() else null
diff --git a/site/changelog.json b/site/changelog.json
index 1cdb43a..c5ebfbf 100644
--- a/site/changelog.json
+++ b/site/changelog.json
@@ -6,6 +6,11 @@
"summary": "实时纪要窗口重新排版,纪要落后时说清楚还差多少;说话人的名字在实时纪要里就能改。",
"image": null,
"items": [
+ {
+ "kind": "fixed",
+ "title": "Android、Windows、Linux 上,电话等待音乐、回铃音、键盘声不再变成一串“嗯”“喂”字幕。",
+ "text": "只有语气词、同一个音反复出现,或者是在描述音频而不是转写的句子不再显示,也不会让会议一直不自动结束;真正说的话照常显示。"
+ },
{
"kind": "new",
"title": "Linux 版有新版本时会提示,点一下就更新并重新打开。",