From b7bf719e96fc26e9c2759212e1e5897fddc2aa69 Mon Sep 17 00:00:00 2001 From: Muqiu Han Date: Wed, 26 Jun 2024 10:42:10 +0800 Subject: [PATCH] [services]: optimize voice recorder strategy --- autumnbot/services/voice_recorder/voice_recorder_config.py | 2 +- autumnbot/services/voice_recorder/voice_recorder_thread.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/autumnbot/services/voice_recorder/voice_recorder_config.py b/autumnbot/services/voice_recorder/voice_recorder_config.py index 17eaf44..fbec776 100644 --- a/autumnbot/services/voice_recorder/voice_recorder_config.py +++ b/autumnbot/services/voice_recorder/voice_recorder_config.py @@ -32,5 +32,5 @@ CHANNELS: int = 1 RATE: int = 44100 FRAMES_PER_BUFFER: int = 1024 -AUDIO_MIN_RMS: int = 5000 +AUDIO_MIN_RMS: int = 200 MAX_LOW_AUDIO_FLAG: int = 100 diff --git a/autumnbot/services/voice_recorder/voice_recorder_thread.py b/autumnbot/services/voice_recorder/voice_recorder_thread.py index b63684e..3c054aa 100644 --- a/autumnbot/services/voice_recorder/voice_recorder_thread.py +++ b/autumnbot/services/voice_recorder/voice_recorder_thread.py @@ -72,8 +72,9 @@ def run(self) -> None: if low_audio_flag > config.MAX_LOW_AUDIO_FLAG: if len(self.__frames) <= ( - int(config.RATE / config.FRAMES_PER_BUFFER * 2) + 50 + int(config.RATE / config.FRAMES_PER_BUFFER * 2) + 100 ): + self.__frames.clear() low_audio_flag = 0 continue path = "{}.wav".format(int(time.time()))