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(linux): a fan, hum or hiss no longer turns into a made-up English sentence

wqugurua432905a90e8
diff --git a/linux/cicada/core/segmenter.py b/linux/cicada/core/segmenter.py
index 386f57d..81d32af 100644
--- a/linux/cicada/core/segmenter.py
+++ b/linux/cicada/core/segmenter.py
@@ -34,6 +34,7 @@ class Segmenter:
pause = 0.6
max_length = 8.0
min_speech = 0.25
+ steady = 2.0 # loud frames' 90th / 10th percentile below this: not speech
def __init__(self):
self.pending = array("h")
@@ -94,6 +95,17 @@ class Segmenter:
cut = i
self._close(cut * FRAME)
+ @classmethod
+ def _steady(cls, levels) -> bool:
+ """Steady sound just over the gate (a fan, hum, hiss) isn't speech: its loud frames barely vary
+ (90th / 10th percentile about 1.1; speech, even over such a floor, 3 and up). Given one, Ming
+ writes a stock sentence in the hint's language ("I'm going to show you a couple of things").
+ Speech buried under steady noise goes too; system audio rarely carries it."""
+ loud = sorted(l for l in levels if l >= cls.threshold)
+ if len(loud) < 2:
+ return False
+ return loud[int(0.9 * (len(loud) - 1))] < cls.steady * loud[int(0.1 * (len(loud) - 1))]
+
def _close(self, end_at: int) -> None:
"""Emits current[:end] and keeps what follows as the start of the next segment."""
end = max(0, min(end_at, len(self.current)))
@@ -101,7 +113,7 @@ class Segmenter:
rest = self.current[end:]
rest_levels = self.levels[min(len(self.levels), end // FRAME):]
start = self.current_start
- speech = self.loud * FRAME >= self.min_speech * RATE
+ speech = self.loud * FRAME >= self.min_speech * RATE and not self._steady(self.levels[:end // FRAME])
self.current = array("h")
self.levels = []
self.quiet = self.loud = 0
diff --git a/linux/tests/test_core.py b/linux/tests/test_core.py
index d2cfdc1..368ca89 100644
--- a/linux/tests/test_core.py
+++ b/linux/tests/test_core.py
@@ -103,8 +103,10 @@ MAC = """{
}"""
-def tone(seconds, amp=0.3):
- return array("h", (int(math.sin(2 * math.pi * 300 * i / 16000) * amp * 32767) for i in range(int(seconds * 16000))))
+def tone(seconds, amp=0.3, syllables=True):
+ """A 300 Hz tone that swells and fades four times a second like syllables; steady when not."""
+ env = (lambda i: 0.55 + 0.45 * math.sin(2 * math.pi * 4 * i / 16000)) if syllables else (lambda i: 1.0)
+ return array("h", (int(math.sin(2 * math.pi * 300 * i / 16000) * env(i) * amp * 32767) for i in range(int(seconds * 16000))))
def silence(seconds):
@@ -411,6 +413,9 @@ class Segmenting(Base):
def test_ignores_clicks(self):
self.assertEqual(0, len(cut(silence(1.0), tone(0.1), silence(1.0))))
self.assertEqual(0, len(cut(tone(3.0, 0.002))))
+ # A steady hum over the gate isn't speech: Ming would make up a sentence for it.
+ self.assertEqual(0, len(cut(tone(3.0, 0.02, syllables=False), silence(1.0))))
+ self.assertEqual(1, len(cut(tone(3.0), silence(1.0))))
def test_wav_round_trip(self):
pcm = tone(0.5)