From ffd7e965a46da144b8b767c168c352e2add78440 Mon Sep 17 00:00:00 2001 From: Kris Gesling Date: Wed, 26 May 2021 11:30:30 +0930 Subject: [PATCH] Provide 0.3s buffer for silence trimming We want to trim the silence from recordings but risk cutting off the first and last syllables, particularly if they are softer sounds. This adds a reasonable length buffer for data collection. During post-processing the sounds can be further trimmed if desired. --- backend/app/audio.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/app/audio.py b/backend/app/audio.py index 89b13b3..1475573 100644 --- a/backend/app/audio.py +++ b/backend/app/audio.py @@ -13,7 +13,10 @@ class Audio: while sound[trim_ms:trim_ms + Audio.chunk_size].dBFS \ < Audio.silence_threshold and trim_ms < len(sound): trim_ms += Audio.chunk_size - + trim_buffer = 300 # buffer to prevent first sound getting cut + trim_ms -= trim_buffer + if trim_ms < 0: + trim_ms = 0 return trim_ms @staticmethod