Record audio with Arduino Nicla Vision

Hi everyone
(sorry for this 3rd post in so little time but it’s on another problem)

I have an Arduino Nicla Vision with and embedded microphone MP34DT05 and QSPI flash of 16Mbits (even if the component is an AT25QL128A-UUE-T of 128 Mbits !? according to the pinout).

I would like to record audio files on the arduino nicla to build a dataset for AI. No importance about the format : mp3, mp4, wav, flac… And I need to format sound datas for post-processing (other than a sound image).

Among the examples provided in openMV IDE, the FFT is perfectly working (NANO RP2040) and the micro-speech (portenta H7) don’t because of the error "micro-speech doesn’t exist. Other examples on internet use SD cards on SPI.

Does someone know a code for compress and turn the 256bits buffer to a sound file on the Arduino Nicla Vision ? I’ve really searched the internet but haven’t found any oil yet

Thank for any help provided :pray:, even if it’s limited to read my problem :grin:

We don’t really work on audio support.

@flob74 I’m trying to do the same, have you solved the problem? Could you help me please? First time approcing python and arduino.

To test I’ve tried also the code audio_fft.py of the examples (https://docs.arduino.cc/tutorials/nicla-vision/microphone-sensor) but it doesn’t work: AttributeError: ‘module’ object has no attribute ‘spectrogram’ and I can’t solve it anyway.

Then I’ve wrote this VSC in python to create a .wav file after using PDMSerialPlotter Example (https://docs.arduino.cc/tutorials/nicla-vision/microphone-sensor) and upload in the Nicla vision board:

#this create a .wav file but it seems not to be working properly and the integer trasformation/save file take very long time (4 min to save a 10s .wav)

#CODE: 

import serial
import wave
import struct
ser = serial.Serial('COM8', 9600)  # replace 'COM3' with the serial port connected 

sample_rate = 44100  # 44.1KHz
bits_per_sample = 16
channels = 1
samples_per_frame = 1
frames = []

while True:
    # Read audio data from serial
    data = ser.readline().strip()
    audio_data = int(data)
    #print(audio_data)
    frames.append(struct.pack('<h', audio_data))

    # If we have enough audio data (10sec), save to .wav file
    if len(frames) == sample_rate*10:
        with wave.open('audio.wav', 'wb') as wavFile:
            wavFile.setnchannels(channels)
            wavFile.setsampwidth(bits_per_sample // 8)
            wavFile.setframerate(sample_rate)
            wavFile.writeframes(b''.join(frames))
            print('Saved audio to audio.wav')
          

        frames = []

AttributeError: ‘module’ object has no attribute ‘spectrogram’ and I can’t solve it anyway.

This has been fixed, see the updated example on github.

help me. why when i record audio this nicla vision with openmv and play it in audacity import through raw data. the output sound as like speed up, can you help to fix it the audio,pleasee. anyway my format audio who import to audacity through raw data is PCM data
audio pdm to pcm.py (1.9 KB)

I’ve same issues, I think the audio is not speed up but there are some missing data, so queued data are less, queue is shorter and it seems like speed up.

Have you solved the problem?

I’ve used different approach saving microphone data directly from serial to .txt file (CoolTerm app) and then creating .wav file from txt in a second moment. Then I’ve tried to send data on mqtt server Rabbitmq but with VSCode is not faster enough (1000 msg/s) and with OpenMV I can’t create the queue on Rabbit and save data in it. I’ve check the publish and subscribe example, but I can only connect to rabbit and see a temporary publish but not the queue. Someone could help in this?

Then there is Edge impulse who seems to save audio data (max 130s) on the boards and then after the acquisition reading from it. Please, someone know how does it work?

The stm32 audio module uses double buffers only and expects callbacks to finish in time before the next buffer. The audio modules for rp2 and nrf both use double buffers for DMA/PDM and a queue with configurable length for PCM buffers, so it’s much easier to overflow the stm32 audio module than rp2 or nrf even though both are slower than stm32, and it also doesn’t detect overflows like the other modules. There’s room for improvements in the stm32 audio module, but it’s just not a top priority right now.