Raspberry Pi 4 audio not working with edge-impulse-linux

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 :slight_smile:

(Also, the topic title is horrible, but I couldn’t come with anything better)

Hello @jcwren,

What do you mean by:

telling edge-impulse-linux to use the same microphone results in no usable audio.

I am not familiar with this microphone.
Anyway, could you check if you can record usable audio straight from sox commands?

Best,

Louis

Invoking sox -t alsa hw:0,0 -r 16000 -c 1 -e signed-integer -b 16 -t raw output.raw results in the same data as I showed in the dump above. Saving in wav format and playing it back results in dead silence (which, looking at the values in the file, only makes sense).

As I said, this works fine with arecord and aplay, which use alsa directly. I don’t know why using sox should result in no useful audio.