知了 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): a very quiet voice in a meeting is no longer mistaken for a fan or hum and left without subtitles
wqugurue732b4e2a048
diff --git a/android/cli/src/main/kotlin/cicada/cli/Tests.kt b/android/cli/src/main/kotlin/cicada/cli/Tests.ktindex 740f28d..4b27d0e 100644--- a/android/cli/src/main/kotlin/cicada/cli/Tests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/Tests.kt@@ -403,9 +403,11 @@ object Tests {// MARK: Segmenter- /// A 300 Hz tone that swells and fades four times a second like syllables; steady when not.- private fun tone(seconds: Double, amp: Double = 0.3, syllables: Boolean = true) = ShortArray((seconds * 16000).toInt()) {- (sin(2 * PI * 300 * it / 16000) * (if (syllables) 0.55 + 0.45 * sin(2 * PI * 4 * it / 16000) else 1.0) * amp * 32767).toInt().toShort()+ /// A 300 Hz tone that swells and fades four times a second like syllables; steady when not, or+ /// rising and falling by `wobble` twice a second like a fan.+ private fun tone(seconds: Double, amp: Double = 0.3, syllables: Boolean = true, wobble: Double = 0.0) = ShortArray((seconds * 16000).toInt()) {+ val env = if (syllables) 0.55 + 0.45 * sin(2 * PI * 4 * it / 16000) else 1.0 + wobble * sin(2 * PI * 0.5 * it / 16000)+ (sin(2 * PI * 300 * it / 16000) * env * amp * 32767).toInt().toShort()}private fun silence(seconds: Double) = ShortArray((seconds * 16000).toInt())private fun concat(vararg parts: ShortArray): ShortArray = parts.fold(ShortArray(0)) { a, b -> a + b }@@ -442,6 +444,8 @@ object Tests {equal(0, cut(tone(3.0, 0.02, syllables = false), silence(1.0)).size, "a steady hum over the gate is not speech")equal(1, cut(tone(3.0), silence(1.0)).size, "speech, which rises and falls, is")equal(1, cut(tone(3.0, 0.03), silence(1.0)).size, "quiet speech, whose dips fall below the gate, is too")+ equal(1, cut(tone(3.0, 0.022), silence(1.0)).size, "a voice whose loudest frames barely clear the gate dips far between syllables")+ equal(0, cut(tone(4.0, 0.016, syllables = false, wobble = 0.3), silence(1.0)).size, "a hum at the gate that slowly rises and falls doesn't")}fun wavRoundTrip() {diff --git a/android/core/src/main/kotlin/cicada/Segmenter.kt b/android/core/src/main/kotlin/cicada/Segmenter.ktindex 455769c..fb10021 100644--- a/android/core/src/main/kotlin/cicada/Segmenter.kt+++ b/android/core/src/main/kotlin/cicada/Segmenter.kt@@ -20,7 +20,8 @@ class Segmenter {@Volatile var pause = 0.6@Volatile var maxLength = 8.0@Volatile var minSpeech = 0.25- @Volatile var steady = 2.0 // frames' 90th / 10th percentile below this: not speech+ @Volatile var steady = 2.0 // frames' 90th / 10th percentile below this: not speech…+ @Volatile var dips = 2.5 // …unless the median is this far over the 10th, quiet ones held at gate / 8private const val PRE_ROLL = 0.15private const val TAIL = 0.15private const val CUT_WINDOW = 2.0@@ -90,12 +91,22 @@ class Segmenter {/// Speech buried under steady noise goes too; system audio rarely carries it. Every frame from/// the first loud one to the last counts, the quiet ones held at the gate: counting only the/// loud ones dropped quiet speech (under about -30 dBFS), whose dips fall below the gate.+ /// A voice so quiet that its loudest frames barely clear the gate (about -38 dBFS: 6 of 6 lines+ /// lost in testing) still pauses between syllables, its quietest tenth of frames far under its+ /// median (8 dB and more); noise near the gate stays within about 6 dB of its median. So a flat+ /// top is steady only when it has no such dips, measured with quiet frames held at gate / 8.+ /// Very low rumble (brown noise with almost nothing over 20 Hz) can look like that and gets+ /// through more often than before (about 1 in 3 segments, was 1 in 5); what Ming makes of it+ /// still meets the hear filter (Translator.isNoise).internal fun isSteady(frameLevels: List<Double>): Boolean {val first = frameLevels.indexOfFirst { it >= threshold }val last = frameLevels.indexOfLast { it >= threshold }if (first < 0 || last <= first) return false- val body = frameLevels.subList(first, last + 1).map { maxOf(it, threshold) }.sorted()- return body[(0.9 * (body.size - 1)).toInt()] < steady * body[(0.1 * (body.size - 1)).toInt()]+ val body = frameLevels.subList(first, last + 1)+ val top = body.map { maxOf(it, threshold) }.sorted()+ if (top[(0.9 * (top.size - 1)).toInt()] >= steady * top[(0.1 * (top.size - 1)).toInt()]) return false+ val low = body.map { maxOf(it, threshold / 8) }.sorted()+ return low[(0.5 * (low.size - 1)).toInt()] < dips * low[(0.1 * (low.size - 1)).toInt()]}/// Emits `current[0 until end]` and keeps what follows as the start of the next segment.