Collect audio data by sony spresence digital microphone

Hi everyone,
I am trying to collect the data from the Sony Spresence digital microphone. It works well when I collect data using the ‘recording’ example. However, I can not record anything in the Live classification stage.
Is that due to edge impulse use of the analog microphone to record only?

Any suggestions will be appreciated!
Kind regards

Hello @dengkewangkaust,

I am not certain about which ‘recording’ example you are referring to.
Could you please provide more info?

Best,

Louis

Thanks!
Here it is:
#include <SDHCI.h>
#include <Audio.h>

#include <arch/board/board.h>

#define RECORD_FILE_NAME “SoundtestGmin.wav”

SDClass theSD;
*AudioClass theAudio;

File myFile;

bool ErrEnd = false;

/**

    • @brief Audio attention callback*

    • When audio internal error occurs, this function will be called back.*
  • /

*static void audio_attention_cb(const ErrorAttentionParam atprm)
{

  • puts(“Attention!”);*
  • if (atprm->error_code >= AS_ATTENTION_CODE_WARNING)*
  • {*
  •  ErrEnd = true;*
    
  • }*
    }

/**

    • @brief Setup recording of wav stream to file*

    • Select input device as microphone
      *
    • Initialize filetype to stereo wav with 48 Kb/s sampling rate
      *
    • Open RECORD_FILE_NAME file in write mode*
  • /

/ Sampling rate*

    • Set 16000 or 48000*
  • /

static const uint32_t recoding_sampling_rate = 48000;

/ Number of input channels*

    • Set either 1, 2, or 4.*
  • /

static const uint8_t recoding_cannel_number = 8;

/ Audio bit depth*

    • Set 16 or 24*
  • /

static const uint8_t recoding_bit_length = 16;

/ Recording time[second] /

static const uint32_t recoding_time = 10;

/ Bytes per second /

*static const int32_t recoding_byte_per_second = recoding_sampling_rate **

  •                                            recoding_cannel_number **
    
  •                                            recoding_bit_length / 8;*
    

/ Total recording size /

static const int32_t recoding_size = recoding_byte_per_second * recoding_time;

void setup()
{

  • Serial.begin(115200);*

  • /* Initialize SD /

  • while (!theSD.begin())*

  • {*

  •  /* wait until SD card is mounted. */*
    
  •  Serial.println("Insert SD card.");*
    
  • }*

  • theAudio = AudioClass::getInstance();*

  • theAudio->begin(audio_attention_cb);*

  • puts(“initialization Audio Library”);*

  • /* Select input device as microphone /

  • theAudio->setRecorderMode(AS_SETRECDR_STS_INPUTDEVICE_MIC,0,1024864,true);

  • /* Search for WAVDEC codec in “/mnt/sd0/BIN” directory /

  • theAudio->initRecorder(AS_CODECTYPE_WAV,*

  •                     "/mnt/sd0/BIN",*
    
  •                     recoding_sampling_rate,*
    
  •                     recoding_bit_length,*
    
  •                     recoding_cannel_number);*
    
  • puts(“Init Recorder!”);*

  • /* Open file for data write on SD card /

  • if (theSD.exists(RECORD_FILE_NAME))*

  • {*

  •  printf("Remove existing file [%s].\n", RECORD_FILE_NAME);*
    
  •  theSD.remove(RECORD_FILE_NAME);*
    
  • }*

  • myFile = theSD.open(RECORD_FILE_NAME, FILE_WRITE);*

  • /* Verify file open /

  • if (!myFile)*

  • {*

  •  printf("File open error\n");*
    
  •  exit(1);*
    
  • }*

  • printf(“Open! [%s]\n”, RECORD_FILE_NAME);*

  • theAudio->writeWavHeader(myFile);*

  • puts(“Write Header!”);*

  • theAudio->startRecorder();*

  • puts(“Recording Start!”);*

}

*void loop() *
{

  • err_t err;*

  • /* recording end condition /

  • if (theAudio->getRecordingSize() > recoding_size)*

  • {*

  •  theAudio->stopRecorder();*
    
  •  sleep(1);*
    
  •  err = theAudio->readFrames(myFile);*
    
  •  goto exitRecording;*
    
  • }*

  • /* Read frames to record in file /

  • err = theAudio->readFrames(myFile);*

  • if (err != AUDIOLIB_ECODE_OK)*

  • {*

  •  printf("File End! =%d\n",err);*
    
  •  theAudio->stopRecorder();*
    
  •  goto exitRecording;*
    
  • }*

  • if (ErrEnd)*

  • {*

  •  printf("Error End\n");*
    
  •  theAudio->stopRecorder();*
    
  •  goto exitRecording;*
    
  • }*

  • return;*

exitRecording:

  • theAudio->closeOutputFile(myFile);*

  • myFile.close();*

  • theAudio->setReadyMode();*

  • theAudio->end();*

  • puts(“End Recording”);*

  • //exit(1);*

  • delay(100);*

  • Serial.println(“>>> Start USB Mass Storage Operation”);*

  • // Start USB Mass Storage*

  • if (theSD.beginUsbMsc()) {*

  • Serial.println(“UsbMsc connect error”);*

  • }*

  • Serial.println(“Finish USB MSC? (y/n)”);*

  • while (true) {*

  • while (!Serial.available());*

  • if(Serial.read() == ‘y’){*

  •  while (Serial.available()) {*
    
  •    Serial.read(); // dummy read to empty input buffer*
    
  •  }*
    
  •  break;*
    
  • }*

  • }*

  • // Finish USB Mass Storage*

  • if (theSD.endUsbMsc()) {*

  • Serial.println(“UsbMsc disconnect error”);*

  • }*

  • Serial.println(“<<< Finish USB Mass Storage Operation”);*

  • delay(100);*

  • exit(1);*
    }

I also added one line to record in edge-impulse example, like this:
static bool microphone_inference_record(void) {
uint32_t length;
err_t err;
/*
RingBuff* ringbuf_fft[m_channel];
int16_t *samples = ringbuf_fft[1];
*/
int16_t *samples = (int16_t *)s_buffer;

inference.buf_ready = 0;

do {
err = theAudio->readFrames(s_buffer, buffer_size, &length);
if ((err != AUDIOLIB_ECODE_OK) && (err != AUDIOLIB_ECODE_INSUFFICIENT_BUFFER_AREA)) {
return false;
}
size_t bytesWritten = myFile.write((const byte *)s_buffer, length);

The recording can be done correctly, but the data doesn’t seem recognized.

Thanks again!
Dengke