I have an RPi4 with an I2S microphone connected. I can record and playback audio with no issues using arecord
and aplay
. However, telling edge-impulse-linux
to use the same microphone results in no usable audio. I believe this might be related to sample sizes, in that the I2S microphone is configured for S32_LE
, but edge-impulse-linux
is expecting S16_LE
.
The microphone is configured per this Adafruit web page.
Running edge-impulse-linux
with the --verbose
flag, we get this output:
me@rpi4:~ $ edge-impulse-linux --disable-camera --verbose
Edge Impulse Linux client v1.4.2
[SER] Using microphone hw:0,0
[WS ] Connecting to wss://remote-mgmt.edgeimpulse.com
[WS ] Connected to wss://remote-mgmt.edgeimpulse.com
[WS ] Device "rpi4" is now connected to project "[hidden]"
[WS ] Go to https://studio.edgeimpulse.com/studio/[hidden]/acquisition/training to build your machine learning model!
[WS ] Incoming sampling request {
path: '/api/training/data',
label: 'Test',
length: 30000,
interval: 0.0625,
hmacKey: '[hidden]',
sensor: 'Microphone'
}
[SER] Waiting 2 seconds
Recording via: sox [
'-t', 'alsa',
'hw:0,0', '-q',
'-r', '16000',
'-c', '1',
'-e', 'signed-integer',
'-b', '16',
'-t', 'raw',
'-'
] {}
Recording 1 channels with sample rate 16000...
Recording 4096 bytes <Buffer 00 00 00 00 ff ff 00 00 00 00 00 00 ff ff 00 00 ff ff 00 00 00 00 01 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 ... 4046 more bytes>
Recording 4096 bytes <Buffer 01 00 ff ff 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 4046 more bytes>
Recording 4096 bytes <Buffer 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 ff ff 00 00 00 00 01 00 00 00 ff ff 00 00 00 00 ff ff 00 00 00 00 00 00 ff ff 00 00 00 00 01 00 00 00 ... 4046 more bytes>
[repeats for sample duration]
This command is what I use for recording audio at 16KHz:
arecord -D dmic_sv -c2 -r 16000 -f S32_LE -t wav -V mono -v recording.wav
If I replace S32_LE
with S16_LE
, I get the following error:
arecord -D dmic_sv -c2 -r 8000 -f S16_LE -t wav -V mono -v recording.wav
Recording WAVE 'recording.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Stereo
arecord: set_params:1343: Sample format non available
Available formats:
- S32_LE
I also notice that edge-impulse-linux
is specifying 1 channel instead of 2, although I don’t know if that has any impact.
I’m not all that familiar with the Linux sound system, so I don’t know if the .asoundrc
file can be configured to convert the 32-bit samples to 16. I read through the asound webpage, but it was rather opaque.
Hopefully someone will have some insight into what’s going on here
(Also, the topic title is horrible, but I couldn’t come with anything better)