Go Down

Topic: Arduino voice recorder (Read 852 times) previous topic - next topic

ardunewbie

As part of a school project I have to make a voice recorder in order to record the discussion of two people sitting on a table and save the wav files on an SD card.

Being quite new in arduino circuits and programming, I followed precisely the instructions found here: http://www.instructables.com/id/Make-Your-Own-Spy-Bug-Arduino-Voice-Recorder/.

Compared to this tutorial, my approach differs on that I'm using an Arduino Uno and a sparkfun electret microphone breakout. Also, I haven't incorporated the batteries yet, but the system is powered by my laptop.

I managed to get a .wav  in the SD card but with a continuous noise in the background. You can hear what I get in the attached file.

Any ideas why this may happen?

el_supremo

Post your code - in code tags using the </> icon.

The WAV file is corrupt - something wrong with the header. Goldwave says that it is 8-bit sampled at 16kHz.
But the audio is obviously totally screwed. The audio of your voice only occurs as negative samples interspersed with regular clicks. My guess is that the clicks are caused when the data are written to the SD card. Perhaps the card can't keep up with the sampling rate of 16kB/sec. But you need to post your code.

Pete
Don't send me technical questions via Private Message.

ardunewbie

Thanks for the quick reply. Here's the code

Code: [Select]

#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10

TMRpcm audio;
int audiofile = 0;
unsigned long i = 0;
bool recmode = 0;

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(6, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(0, button, LOW);
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;

}

void loop() {
}

void button() {
  while (i < 300000) {
    i++;
  }
  i = 0;
  Serial.println(recmode);
  if (recmode == 0) {
    recmode = 1;
    Serial.println(recmode);
    audiofile++;
    Serial.println(audiofile);
    digitalWrite(9, HIGH);
    switch (audiofile) {
      case 1: audio.startRecording("1.wav", 16000, A0); break;
      case 2: audio.startRecording("2.wav", 16000, A0); break;
      case 3: audio.startRecording("3.wav", 16000, A0); break;
      case 4: audio.startRecording("4.wav", 16000, A0); break;
      case 5: audio.startRecording("5.wav", 16000, A0); break;
      case 6: audio.startRecording("6.wav", 16000, A0); break;
      case 7: audio.startRecording("7.wav", 16000, A0); break;
      case 8: audio.startRecording("8.wav", 16000, A0); break;
      case 9: audio.startRecording("9.wav", 16000, A0); break;
      case 10: audio.startRecording("10.wav", 16000, A0); break;
    }
  }
  else {
    recmode = 0;
    digitalWrite(9, LOW);
   switch (audiofile) {
      case 1: audio.stopRecording("1.wav"); break;
      case 2: audio.stopRecording("2.wav"); break;
      case 3: audio.stopRecording("3.wav"); break;
      case 4: audio.stopRecording("4.wav"); break;
      case 5: audio.stopRecording("5.wav"); break;
      case 6: audio.stopRecording("6.wav"); break;
      case 7: audio.stopRecording("7.wav"); break;
      case 8: audio.stopRecording("8.wav"); break;
      case 9: audio.stopRecording("9.wav"); break;
      case 10: audio.stopRecording("10.wav"); break;
    }
  }
}

el_supremo

#3
May 27, 2018, 06:27 pm Last Edit: May 27, 2018, 06:28 pm by el_supremo
There are several things wrong with your code but the major one is that you can't do all the recording in the button function. That is an interrupt service routine which must deal with an event quickly and then return.
The button function should only set a flag (ideally an unsigned character which must also be declared volatile). The loop function then continuously tests this flag and when it is on it then executes the code that you currently have in the button function AND it also turns the flag off again.

If this code is meant to delay it definitely should not be in an interrupt routine but:
Code: [Select]
  while (i < 300000) {
    i++;
  }

it may not delay at all. The compiler is probably smart enough to figure out that the result of that loop is to set i to 300000 and will replace the loop with i = 300000;
Even if the compiler leaves it as it is, how long is this delay supposed to last? You'd be better off using delay or millis.

There are obviously other problems too but fix these up first.

Pete
Don't send me technical questions via Private Message.

Grumpy_Mike

#4
May 27, 2018, 09:54 pm Last Edit: May 27, 2018, 09:54 pm by Grumpy_Mike
Always remember that instructables are by and large crap written by people who have a vastly inflated idea of their own skill level.


ardunewbie

Thank you both for your replies. Based on them, I decided to start fresh and build the project from scratch by removing the button and the LED and keeping only the microphone and the SD card.

I thought that by using the following code

Code: [Select]

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

#define SD_ChipSelectPin 10 

TMRpcm audio;   

void setup() {
 
   Serial.begin(115200);
 
  if (!SD.begin(SD_ChipSelectPin)) { 
    return;
  }else{
    Serial.println("SD OK");
  }
 
  audio.CSPin = SD_ChipSelectPin;
}


void loop() {
 
    if(Serial.available()){                       
      switch(Serial.read()){
        case 'r': audio.startRecording("testTMR.wav", 16000, A0); break;   
        case 's': audio.stopRecording("testTMR.wav"); break;             
      }
    }
}



I would be able to record one wav file of acceptable quality. Unfortunately, that wasn't the case. What I got is attached.

Any ideas what I'm doing wrong this time? Could it be a problem of the library (TMRpcm)?

ardunewbie

Sorry, I forgot the attachment :)

zoomx

#7
Jun 04, 2018, 01:43 pm Last Edit: Jun 04, 2018, 01:50 pm by zoomx
Have you done what's written here?
https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features#recording-audio

Maybe there is a difference in the microphone. I don't know how the library works but the  microphone used on inscrutables uses a MAX9814, it means that you have a full wave recording and that the zero is not at 0 but at 512. Other simple microphone doesn't work in this way.

ardunewbie

Thanks for you reply zoomx.
I had already done what it was written in the link you submitted, but you were right about the microphone. I used a MAX 9814 and the result is better (see attachment 1.zip), even though there is still a background noise.
I also used the MAX 9814 with a new code that I downloaded from here: (http://www.apcmag.com/arduino.htm/, Project 18) and I got a similar result (see attachment 2.zip).




zoomx

#9
Jun 06, 2018, 06:18 pm Last Edit: Jun 09, 2018, 06:16 pm by zoomx
Ok, I believe that you first used this microphone

that is not a real microphone until you scream on it. I am not sure but this microphone works only on half of the wave, it means that in silence it gives 0 and loud sound give 1023 on ADC. It is more like a sound sensor that can listen a hand clap, nothing more.

The remaining noise is due to the connections and Arduino itself but I was surprised about the quality of this simple recorder, I have a MAX 9814 microphone too.
Thanks for sharing your results!


Update: I made the same project and got the noise. I am using the laptop to power the Arduino and the laptop is connected to the mains. The noise came from the mains and the laptop.

Go Up