# ESP32 audio recording files to Computer using WAV file

#### Brettjohnson7191

Joined Apr 28, 2022
23
C-like:
Simple code is as follows.
const int soundPin = 35;
int sound = 0;
void setup() {
Serial.begin(9600);
delay(1000);
}
void loop() {
Serial.println(sound);
delay(3);
}
Hello all, I hope this is the correct place for this thread.
I am using an ESP32 with an adafruit max4466 microphone. I am testing the quality of audio files picked up using simple ADC read before switching to different techniques. It would be easy to save the files to an external SD card connected right to the ESP32, but I do not have that at hand currently. So, my question is how can I save my data to a wav file on my laptop to listen to the audio? I do not believe Arduino IDE has the library's to do this so a python script will be needed. So if someone could point me in the right direction that would be greatly appreciated.

And yes I know that reading the values strictly from the ADC will not be a clean nor high quality audio this is just where I am starting this project.

serial plotter shows recognizable sound patterns and confirms its functionality.

Last edited by a moderator:

#### Ya’akov

Joined Jan 27, 2019
7,026
Welcome to AAC.

The simplest way, since you are just prototyping, would probably be a simple serial connection. This doesn’t involve the Arduino IDE, just the computer. You could write a small script to accept the data and convert it to a valid file format. But the gist is, write the file out on serial.

If you want to make it a bit fancy, you can provide a very simple command interface where you can choose to initiate the download by a command from the computer (script), or, you can do something as hackish as putting a button on the ESP32 that starts the transfer. FIrst cat /dev/tty-XXX > sound.dat, then press the button, then ^C, then process the. (For Windows you should be able to do something similar but it‘s been a very long time since I cared about how that would work so I can’t suggest the exact method).

Anyway, other methods such as network transfer seem very heavyweight for what amounts, I expect, to a temporary workaround. Also, consider moving to a board with native USB that can do Mass Storage, then you could write a filesystem to flash and just plug the thing in like a USB drive to read (and write) files.

#### Brettjohnson7191

Joined Apr 28, 2022
23
Okay So I have successfully read the microphone data in through ADC7 and stored this data into a .txt file on a sd card connected to the ESP32. Now I am not sure how to convert this data to a .wav file. I can not find anything about it online either. Any help is appreciated

#### Ya’akov

Joined Jan 27, 2019
7,026
If you use Python, you could try this: PCM2Wav

Raw sampled audio is PCM data and WAV is just containerized PCM.

#### KeithWalker

Joined Jul 10, 2017
2,714
To store your data in .WAV format, you need to add a header to the file which contains information about the stored data. It looks a bit complicated but it is really quite straight forward. Here is the spec for the header:
https://docs.fileformat.com/audio/wav/