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.
channels
specifies 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.frequency
is 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_db
is the microphone gain to apply.highpass
is the high pass filter cut-off given the target sample frequency. This parameter is applicable for the Arduino Portenta H7 only.samples
is the number of samples to accumulate per callback. This is typically calculated 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
callback
that takes one argumentpcmbuf
automatically forever when enough PCM samples have accumulated based on theaudio
module settings. You can cast thepcmbuf
into anndarray
for processing the audio samples in numpy and then pass thendarray
to aml.Model
object for inference.pcmbuf
is 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.