Arduino+MAX9814制作簡(jiǎn)易錄音機(jī)

MAX9814

這個(gè)示例是用MAX9814進(jìn)行錄音,并生成一個(gè)wav文件保存到SD上。如果用ESP8266可以不使用SD卡模塊直接將文件存到云。

BOM

  • MAX9814 模塊
  • MicroSDCard 模塊
  • Arduino Uno

線路圖

電路圖

代碼

這里我使用了一個(gè)叫TMRpcm的庫(kù),這個(gè)庫(kù)在Arduino上非常好用,它本來(lái)是做軟DAC用的,可以用來(lái)擴(kuò)展Arduino進(jìn)行直接的聲音解碼播放。另外TMRpcm里面還有一個(gè)用于錄音的方法,源碼中是被注釋掉的,在安裝該庫(kù)之后需要打開(kāi)源碼庫(kù)中的pcmConfig.h文件將以下的行取消注釋,否則會(huì)編譯不通過(guò):

#define buffSize 128. May need to increase.
#define ENABLE_RECORDING 
#define BLOCK_COUNT 10000UL

以下是 Arduino 代碼:


#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>

#define SD_ChipSelectPin 10  //using digital pin 4 on arduino nano 328, can use other pins

TMRpcm audio;   // create an object for use in this sketch 
void setup() {
  
  audio.speakerPin = 4; 

  Serial.begin(115200);
  
  if (!SD.begin(SD_ChipSelectPin)) {  
    Serial.println("SD Fail");
    return;
  }else{
    Serial.println("SD OK"); 
  }
  // The audio library needs to know which CS pin to use for recording
  audio.CSPin = SD_ChipSelectPin;
}


void loop() {
  
    if(Serial.available()){                          //Send commands over serial to play
      char c = Serial.read();
      Serial.println(c);
      switch(c){
        case 'r': audio.startRecording("test.wav",16000,A0); break;    //Record at 16khz sample rate on pin A0
        case 'R': audio.startRecording("test.wav",16000,A0,1); break;  //Record, but with passthrough to speaker.
        case 't': audio.startRecording("test.wav",16000,A0,2); break;  //Do not record. Output direct to speaker
                                           //Note: If samples are dropped before writing, it
                                           //      will not be heard in passthrough mode
        case 's': audio.stopRecording("test.wav"); break;              //Stop recording
        case 'p': audio.play("test.wav"); break;                       //Play the recording 
        case '=': audio.volume(1); break;                              //Increase volume by 1. Does not affect recording
        case '-': audio.volume(0); break;                              //Decrease volume by 1. Does not affect recording
        case 'S': audio.stopPlayback(); break;                         //Stop all playback
        
      }
    }
}

參考

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容