Nicla Voice Audio Recording

Question/Issue: Needing explanation on how to record audio from the nicla voice’s microphone.

Hi. For a project I’m trying to retrieve audio data from a nicla voice’s microphone. The default format is PDM uint8_t when audio data are retrieve if I understand the NDP library correctly, but it isn’t a listenable format.

I didn’t manage to use the “collect data” tools with the nicla voice despite flashing the required firmwares on it (I get the error

[WS ] Incoming sampling request {
path: ‘/api/training/data’,
label: ‘roomNoise’,
length: 5000,
interval: 0.0625,
hmacKey: ‘3a848d47e13cda26050a042913dcc897’,
sensor: ‘Microphone’
[WS ] Failed to sample data Timeout when waiting for > (timeout: 2000) AT+SAMPLESETTINGS=roomNoise,0.0625,5000,3a848d47e13cda26050a042913dcc897")


Even if I manage to get it working, I would like to know if it’s possible to have a detailed process on how to convert the raw data of the microphone into listenable data (without Edge Impulse), to collect long audio sequences… How did you manage to do it in Edge Impulse if your convertion work?.

Thanks in advance.

PS: don’t hesitate to tell me if my request isn’t clear enough

Hi @mbmn974,

I’ve had to do this, but I cannot find my code any longer :frowning: If I come across it, I will post it.

I recommend first writing a simple program in Arduino that captures data for some time (e.g. 1 second) and then print all of the values to the Serial terminal in a comma-separated list (e.g. “0, 0, 23, 53, 129, 255, 255, 3, 324” and so on). Try a recording and copy that list from the Serial terminal.

Next, write a quick Python program that converts the list/array to a wav file (using — SciPy v1.11.1 Manual). For example (warning: untested code):

import numpy as np
from import write

# Should match sample rate from Arduino program
samplerate = 16000

# Paste your comma-separated values audio list here
sample = np.array([...])

# Convert to .wav file
write("sample.wav", samplerate, sample.astype(np.uint8))

Then, try opening sample.wav in some program (e.g. Audacity). With some luck, you should hear your recording.

Hi @shawn_edgeimpulse,
thanks for your reply.

I tried your solution : printing the microphone raw value to serial, separated by commas, and converting them using scipy.

The .wav file isn’t audible (its loud noise, and doesn’t match the 20 seconds recorded (it is only 4s long, even if I picked the same sample rate on arduino and on python (16000))).

I think it comes from the fact that the raw data of the microphone are PDM data but not PCM.
With another arduino that convert automaticaly PDM data to PCM I can use your process to listen to audio (even if its low quality), but I have no idea how to work from the PDM data of the Nicla Voice.

That would be great if you come across your code.


I’ll post below the python code to retrieve the serial data of the arduino if anyone is interested :

import serial
import time
import struct
import pandas as pd
serialPort = ‘COM3’
serialBaud = 115200

bytesBuffer = []

print(‘Trying to connect to ’ + str(serialPort) +
’ at ’ + str(serialBaud) + ’ BAUD.’)

msg = “”

s = serial.Serial()
s.baudrate = serialBaud
s.port = serialPort


print("Failed to connect with " + str(serialPort) +
’ at ’ + str(serialBaud) + ’ BAUD.')


b =

with open(“”, “wb”) as binary_file:
for data in bytesBuffer :

import numpy as np
import as wav

f = open(“”,“rb”)
lines = f.readlines()
signal = str(lines[0]).split(“,”)[1:len(signal)-1]


signalNp = np.asarray(signal)
wav.write(“testNicla.wav”, 16000, signalNp.astype(np.uint8))

1 Like