From 6671d9df50392ee2854127c51a37b3172e9d60b1 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 9 Oct 2024 19:40:49 +0200 Subject: [PATCH] libraries/ml/ml/apps: Allow passing gain to audio init. --- scripts/libraries/ml/ml/apps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/libraries/ml/ml/apps.py b/scripts/libraries/ml/ml/apps.py index 488eb0488..469c3bd01 100644 --- a/scripts/libraries/ml/ml/apps.py +++ b/scripts/libraries/ml/ml/apps.py @@ -46,7 +46,7 @@ class MicroSpeech: _CATEGORY_COUNT = const(4) _AVERAGE_WINDOW_SAMPLES = const(1020 // _SLICE_TIME_MS) - def __init__(self, preprocessor=None, micro_speech=None, labels=None): + def __init__(self, preprocessor=None, micro_speech=None, labels=None, gain_db=24): self.preprocessor = preprocessor if preprocessor is None: self.preprocessor = Model("audio_preprocessor") @@ -59,7 +59,7 @@ class MicroSpeech: self.spectrogram = np.zeros((1, _SLICE_COUNT * _SLICE_SIZE), dtype=np.int8) self.pred_history = np.zeros((_AVERAGE_WINDOW_SAMPLES, _CATEGORY_COUNT), dtype=np.float) self.audio_started = False - audio.init(channels=1, frequency=_AUDIO_FREQUENCY, gain_db=24, samples=_SAMPLES_PER_STEP * 2) + audio.init(channels=1, frequency=_AUDIO_FREQUENCY, gain_db=gain_db, samples=_SAMPLES_PER_STEP * 2) def audio_callback(self, buf): # Roll the audio buffer to the left, and add the new samples.