aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-04-23 20:00:12 -0700
committerPinapelz <yukais@pinapelz.com>2026-04-23 20:00:12 -0700
commita74fa05013bd62f960d5cb59615447b78d73a1d0 (patch)
treebd60c3cb12080eee0d083073384c185bfda204bd /server.py
parent054b742d3f2a23a09209f392380f6af0f3e31dce (diff)
add root-mean-square check to skip processing silence
Diffstat (limited to 'server.py')
-rw-r--r--server.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/server.py b/server.py
index 65a4567..17bfb39 100644
--- a/server.py
+++ b/server.py
@@ -192,6 +192,13 @@ def audio_callback(indata, frames, time_info, status):
audio_buffer = audio_buffer[-MAX_SAMPLES:]
+def is_silent(audio_16k):
+ if audio_16k is None or len(audio_16k) == 0:
+ return False
+ rms = float(np.sqrt(np.mean(np.square(audio_16k)))) # root mean square
+ return rms < 0.003
+
+
def processing_loop():
while True:
time.sleep(PROCESS_INTERVAL_SECONDS)
@@ -201,6 +208,8 @@ def processing_loop():
audio_copy = audio_buffer.copy()
capture_rate = CAPTURE_SAMPLE_RATE
audio_16k = resample_audio(audio_copy, capture_rate, TARGET_SAMPLE_RATE)
+ if is_silent(audio_16k):
+ continue
run_whisper(audio_16k)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage