Merge pull request #2445 from openmv/ml_gain

libraries/ml/ml/apps: Allow passing gain to audio init.
This commit is contained in:
Ibrahim Abdelkader 2024-10-09 20:43:00 +03:00 committed by GitHub
commit 1f22d4fce7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,7 +46,7 @@ class MicroSpeech:
_CATEGORY_COUNT = const(4) _CATEGORY_COUNT = const(4)
_AVERAGE_WINDOW_SAMPLES = const(1020 // _SLICE_TIME_MS) _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 self.preprocessor = preprocessor
if preprocessor is None: if preprocessor is None:
self.preprocessor = Model("audio_preprocessor") self.preprocessor = Model("audio_preprocessor")
@ -59,7 +59,7 @@ class MicroSpeech:
self.spectrogram = np.zeros((1, _SLICE_COUNT * _SLICE_SIZE), dtype=np.int8) 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.pred_history = np.zeros((_AVERAGE_WINDOW_SAMPLES, _CATEGORY_COUNT), dtype=np.float)
self.audio_started = False 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): def audio_callback(self, buf):
# Roll the audio buffer to the left, and add the new samples. # Roll the audio buffer to the left, and add the new samples.