audio — Audio Module¶
The audio module is used to record audio samples from a microphone on the Arduino Portenta or the Arduino Nicla.
Functions¶
- audio.init(channels: int = 2, frequency: int = 16000, gain_db: float = 24, highpass: float = 0.9883, samples: int = -1) None¶
Initializes the audio module. Must be called first before using the audio module.
channelsspecifies the number of audio channels. May be 1 or 2. Audio samples are interleaved for two audio channels. Using more than one channel is only possible on boards with more than one mic.frequencyis the sample frequency to run at. Running at a higher sample frequency results in a higher noise floor which means less effective bits per sample.gain_dbis the microphone gain to apply.highpassis the high pass filter cut-off given the target sample frequency. This parameter is applicable for the Arduino Portenta H7 only.samplesis the number of samples to accumulate per callback. This is typically caluclated based on the decimation factor and number of channels. If set to -1, the number of samples will be calculated automatically based on the decimation factor and number of channels.
- audio.start_streaming(callback) None¶
Calls the
callbackthat takes one argumentpcmbufautomatically forever when enough PCM samples have accumulated based on theaudiomodule settings. You can cast thepcmbufinto anndarrayfor processing the audio samples in numpy and then pass thendarrayto aml.Modelobject for inference.pcmbufis a signed 16-bit array of audio samples who’s sized based on the decimation factor and number of channels, or the number of samples specified in theaudio.init()function.In single channel mode audio samples will be 16-bits each filling up the 16-bit array.
In dual channel mode audio samples will be 16-bits each in pairs filling up the 16-bit array.