XIAO BLE Sense Audio Data Forwarder

Hi Guys,
I want to send audio data captured by XIAO BLE Sense mic to Studio using Data Forwarder. Do you have an Arduino Sketch example that I can use? For accelerometer data, I adapted the Nano BLE Sense example, but I did not find one for audio data.

For audio, I am using the code below (the same I used for the microphone test), but the studio does not recognize it as audio (what I understand). Should I convert it to .wav?

#include <PDM.h>
short sampleBuffer[2048];
volatile int samplesRead;

void setup() {
  Serial.begin(115200);
  while (!Serial);

  PDM.onReceive(onPDMdata);
  PDM.setBufferSize(4096);
  PDM.setGain(127);

  if (!PDM.begin(1, 16000)) {
    Serial.println("Failed to start PDM!");
    while (1);
  }
}

void loop() {
  if (samplesRead) {

    for (int i = 0; i < samplesRead; i++) {
      Serial.println(sampleBuffer[i]);
    }
    samplesRead = 0;
  }
}

void onPDMdata() {
  int bytesAvailable = PDM.available();
  PDM.read(sampleBuffer, bytesAvailable);
  samplesRead = bytesAvailable / 2;
}

thanks.
Marcelo

Yes Marcelo, it would be interesting to see the Data Forwarding Arduino code for both sound and also for vision since how to do it using the accelerometer is shown in the DOCs. With the client installed on a device it just works.

I am curious how they get the vision data sent so fast, as my upload speeds do not seem very good (Nano33 seems to peak at 51 Hz) .

@Rocksetta My project went to the end and did some classification, but the Studio considered the data from a generic sensor (that I changed to “microphone” during inference) and as “Sample Frequency around 4K Hz”, which is the content of the audio Buffer. The XIAO is, in fact capturing audio with the Mic PCM set up to 16KHz). So I also changed it on the deploy code (PDM.begin(1, 16000)). Doing those changes, the project worked. But I am not happy, the captured data is not a clear sound (when I analyzed it using Librosa.

1 Like

Hi @rovai,

I don’t think we’ll see the data forwarder working with audio data, as it’s too slow: Audio data using Data forwarder