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(windows): a very quiet voice in a meeting is no longer mistaken for a fan or hum and left without subtitles

wquguru0a454cb77063
diff --git a/windows/src/Cicada.Core/Segmenter.cs b/windows/src/Cicada.Core/Segmenter.cs
index f8a7b9f..bbf4b6d 100644
--- a/windows/src/Cicada.Core/Segmenter.cs
+++ b/windows/src/Cicada.Core/Segmenter.cs
@@ -17,7 +17,8 @@ public sealed class Segmenter
const int Frame = 480; // 30 ms
public static double Threshold = 0.01; // the Mac AudioRouter's gate (about -40 dBFS)
public static double Pause = 0.6, MaxLength = 8.0, MinSpeech = 0.25;
- public static double Steady = 2.0; // frames' 90th / 10th percentile below this: not speech
+ public static double Steady = 2.0; // frames' 90th / 10th percentile below this: not speech…
+ public static double Dips = 2.5; // …unless the median is this far over the 10th, quiet ones held at gate / 8
const double PreRoll = 0.15, Tail = 0.15, CutWindow = 2.0;
readonly List<short> pending = []; // samples not yet a whole frame
@@ -112,14 +113,24 @@ public sealed 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 static bool IsSteady(IEnumerable<double> frameLevels, double? gate = null)
{
var all = frameLevels.ToList();
var threshold = gate ?? Threshold;
int first = all.FindIndex(l => l >= threshold), last = all.FindLastIndex(l => l >= threshold);
if (first < 0 || last <= first) return false;
- var body = all.GetRange(first, last - first + 1).Select(l => Math.Max(l, threshold)).Order().ToList();
- return body[(int)(0.9 * (body.Count - 1))] < Steady * body[(int)(0.1 * (body.Count - 1))];
+ var body = all.GetRange(first, last - first + 1);
+ var top = body.Select(l => Math.Max(l, threshold)).Order().ToList();
+ if (top[(int)(0.9 * (top.Count - 1))] >= Steady * top[(int)(0.1 * (top.Count - 1))]) return false;
+ var low = body.Select(l => Math.Max(l, threshold / 8)).Order().ToList();
+ return low[(int)(0.5 * (low.Count - 1))] < Dips * low[(int)(0.1 * (low.Count - 1))];
}
/// Emits `current[..end]` and keeps what follows as the start of the next segment.
diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.cs
index 7b8a73b..c564f97 100644
--- a/windows/tests/Cicada.Tests/Program.cs
+++ b/windows/tests/Cicada.Tests/Program.cs
@@ -461,10 +461,12 @@ static class Tests
// MARK: Segmenter
- /// A 300 Hz tone that swells and fades four times a second like syllables; steady when not.
- static short[] Tone(double seconds, double amp = 0.3, bool syllables = true) =>
+ /// 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.
+ static short[] Tone(double seconds, double amp = 0.3, bool syllables = true, double wobble = 0) =>
Enumerable.Range(0, (int)(seconds * 16000)).Select(i => (short)(Math.Sin(2 * Math.PI * 300 * i / 16000)
- * (syllables ? 0.55 + 0.45 * Math.Sin(2 * Math.PI * 4 * i / 16000) : 1) * amp * 32767)).ToArray();
+ * (syllables ? 0.55 + 0.45 * Math.Sin(2 * Math.PI * 4 * i / 16000) : 1 + wobble * Math.Sin(2 * Math.PI * 0.5 * i / 16000))
+ * amp * 32767)).ToArray();
static short[] Silence(double seconds) => new short[(int)(seconds * 16000)];
static List<Segment> Cut(params short[][] parts)
@@ -503,6 +505,8 @@ static class Tests
Equal(0, Cut(Tone(3, 0.02, syllables: false), Silence(1)).Count, "a steady hum over the gate is not speech");
Equal(1, Cut(Tone(3), Silence(1)).Count, "speech, which rises and falls, is");
Equal(1, Cut(Tone(3, 0.03), Silence(1)).Count, "quiet speech, whose dips fall below the gate, is too");
+ Equal(1, Cut(Tone(3, 0.022), Silence(1)).Count, "a voice whose loudest frames barely clear the gate dips far between syllables");
+ Equal(0, Cut(Tone(4, 0.016, syllables: false, wobble: 0.3), Silence(1)).Count, "a hum at the gate that slowly rises and falls doesn't");
}
public static void WavRoundTrip()