ESP32 | INMP441 | Tutorial - [Part.4] Capturing audio from i2s mic to save WAV file (I2S interface)
Вставка
- Опубліковано 25 вер 2024
- The WAV media format is still a popular file, making it easy to access. In this video, it's showing you how to capture audio from i2s mic to save the WAV file in the SPIFFS.
[INMP441 Omnidirectional Microphone]
amzn.to/3Ma8C47
[I2S ADC DAC EXAMPLE]
github.com/esp...
[All SPIFFS Example]
github.com/Bod...
[WAVE PCM soundfile format]
soundfile.sapp....
[Arduino core for the ESP32]
github.com/esp...
[Steve Jobs iPhone Launch Keynote 2007]
time.com/46285...
[Project Github Link]
github.com/001...
Music:
Music provided by NoCopyRightSounds from UA-cam.
#ESP32 #WAV #Arduino #MIC #I2S #microphone #audio #recorder #SPIFFS
Subscribe - ua-cam.com/users/ThatProject
Thanks for the great tutorial! I followed it strictly, but sometimes the SPIFFS record speed wasn't fast enough, and the audios showed up missing parts. I suggest you using LITTLEFS memory, it's much faster and works pretty well. Also it's very easy to implement, just add the LITTLEFS library and switch SPIFFS for LITTLEFS.
Agree with you. I'll use LITTLEFS for the next projects. Thanks.
are you sure it is just add the library and switch spiffs for littlefs? I got Corrupted dir pair at {0x0, 0x1}. I try it and it does not work. If you did it, please let me know.
@@josefarias8299 did u finally make it work?
I'm seriously blown away by your skills! thank you for this tutorial!
Thanks 🙏
can i use pdm microphone insted i2s
Just to let you know, I changed the following lines in the wav header and got it working really nicely at 44.1khz (see lines with comments)
header[24] = 0x44; // 80 ac44
header[25] = 0xAC; // 3e
header[26] = 0x00;
header[27] = 0x00;
header[28] = 0x88; //00
header[29] = 0x58; //7D 125 7d00 15888
header[30] = 0x01; //00
That's really great. When I was working on this project, I tried a lot to make it work at 44.1Khz, but I didn't succeed. Thank you very much.
Can you help me with how can i capture audio like on SDcard? I tried alot but i didn't got succes. the problem is that it only capture noise and sometimes it is silent. I tried with different mic and code but result is the same
Bro this single comment is going to help me very significantly
Awesome! Thanks to you and this video I got my first recordings with the inmp441 and learned about the fs browser.
I get an
exit status 1
'base64_encode' was not declared in this scope
error what should I do?
I'm not using base64 encoding in this project. Could there be an issue with another project build?
Thank you very much, this tutorial course helped me a lot. I still have a question. Do the captive pins work on esp32 CAM? it is based on the esp32_S but I try it and it does not work.
What are the captive pins???
heyy bradd,, can you send voice via websocket and directly stream on the web with javascript or others ? Thanks
Hi. It’s very similar project with one of my previous projects. The ESP32CAM sent the picture to the local JS server via websocket stream. I think you can do it based on the project. ua-cam.com/video/kE0idrJYPII/v-deo.html If you run into any trouble, let me know.
@@ThatProject , Thanks for your answer ..
I have seen the video before, but when I want to try to make a sound with the i2s sensor microphone on the web client, I get confused there ..
for the esp32 client side, I found this line of code to send to the websocket server: client.sendBinary((const char *) i2s_read_buff, i2s_read_len); , and on the web client side generates BLOB data, well, can it be made as a sound stream like a video stream?
Saepul Lukman I didn't know there was a new comment. Sorry. Yes, I think it's possible. I'll try it within a new project.
Hi did you find a solution? I am looking for the same solution ( streams audio to the browser or server on PC/Raspberry pi) Thx
Hi brother, Thanks for posting. I have a small issue
1. i run the code, after it completes it shows proper size of my recording.wav, like 160 kb for 5 seconds
2. i then run the Fs server code and it shows that my recording.wav is of 0 bytes. thus it doesn't show on my url
3. i formated my spiffs, and re ran the code , but the problem is still there.
Can you give some suggestions if possible.
As you said, the wav file of 160kb was created, but it seems that some problem caused this file to be removed. After recording for about 3 seconds, please check the existence of the file again.
"header[30] = 0x01;" should it be 0x00?
Yongzheng Wu Thanks for reporting. You're right! it should be header[30] = 0x00.
ByteRate == SampleRate * NumChannels * BitsPerSample/8
16000 * 1 * 16 / 8 = 32000 to hex 0x7D00
header[28] = 0x00;
header[29] = 0x7D;
header[30] = 0x00;
header[31] = 0x00;
I followed the video strictly and it got working but after 2-3 recordings it is not working as it starts recording but doesn't complete and then restart
Since data is stored in Flash, writing of the file will not be completed if the available capacity is exceeded. I think you should change the partition to increase the flash size as much as possible, and if that doesn't work, you should change it to save on the SD card.
is possible to only streaming and hear audio from a browser ?
Seems like the project you're looking for is this. ua-cam.com/video/qq2FRv0lCPw/v-deo.htmlsi=euTM9Tm0u_sdX78P
Excellent project.
I have a question. I tried it on esp32 CAM. it worked well .But at the beginning, the audio was recorded for only 2 seconds. Even if I put 20 seconds in the code.
After having tried it several times, the card restarts itself at the end of each recording. So I can't save it. the serial monitor display something like:
rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) ...
Please help me.
Unfortunately, using two I2S at the same time on the ESP32 causes problems. Please refer to this for more details. github.com/s60sc/ESP32-CAM_MJPEG2SD
Hello, great tutorial.
I try it on an ESP32 CAM. The recording works well but the audio is recorded for at most 2 seconds. Even if I change the time in the code. Afterwards, my card only starts up and can no longer run a program. Please help me
Unfortunately, using two I2S at the same time on the ESP32 causes problems. Please refer to this for more details. github.com/s60sc/ESP32-CAM_MJPEG2SD
Isn't possible to send the data directly to Matlab for real time streaming sound using the PC speakers??
It is possible to send and receive ESP32 data through serial communication in Matlab. Therefore, I think you can receive real-time byte data if it keeps sending the buffer of i2s to UART.
i wonder if we could also use this microphone for live audio classifications
This type is not good for live audio classifications as it requires the microphone to be placed fairly close together.
Haaallo sir, How can I connect to a Bluetooth headset
That would be more efficient. github.com/espressif/esp-idf/blob/master/examples/bluetooth/bluedroid/classic_bt/hfp_ag/README.md
Hey i followed all the steps as you mentioned it says /recording.wav 225904 bytes, but when i upload fsbrowser and check for file it finds nothing, kindly help
I'm pretty sure there it is if you didn't delete it mistakenly. Please check your code carefully.
Hi, excellent work, Im having a problem, I tested the code and send the file with FSBrowser, but in the page appears the message 'FileNotFound' and when I record something the Monitor indicates the file exists and have 327724 bytes on it. Im working with an ESP32 DevKit V1 and the INMP441
Hello, that's weird. Isn't that a typo issue? Please check the file name and path again.
@@ThatProject Thank you for your answer! but no, I checked every path and any possible typo, followed every step of your video, looks like the Arduino IDE is wiping everything on the ESP every time I upload the FSBrowser code on it, thats my guess, any other solution? And again thank you
@@ThatProject Hi, I fixed the problem, I had to tap the button BOOT on the board to not to erase everything (I was holding it the entire upload process before), but now I have another problem, the code actually recognizes the file but the size is 0B, and nothing comes out of the browser, it doesnt say FileNotFound but it doesnt do anything either
The file size is zero because it exceeds the flash memory available when writing the file. For testing, format SPIFFS and record it in a short time to confirm it has no problem.
did u manage to fix it?
I'm confused about your i2s_data_scale() function, why did you do:
(b1 & 0xF) | b0
if you want to get the actual ADC value, you have to do this:
(b1 & 0xFF) | b0
why did you chose 0xF not 0xFF?
im confused by the part "dac_value * 256 / 2048", esp-idf example says "dac_value * 256 / 4096". why 2048 not 4096?
shouldnt the 12-bit to 8-bit conversion use 256/4096? can anyone share some thoughts?
Thank you for the tutorial, but facing a issue, I generally record audio of short time like 3 sec (96kb) or 7 secs(256kb) but when I'm trying to encode it in BASE64 it shows the error at line 47 where SPIFFS initializes. rest works completely fine. All I can suspect is either esp doesn't have enough buffer to store the audio in buffer or encoding !
BASE64 encoding requires more memory than the target file. Perhaps out of memory has occurred.
I'm attempting to append files to an SD card instead of SPIFFS but doesn't seem to be writing properly, do you guys think its possibly because both the mic and SD card are using SPI even though they're all mounted to different pins and is causing it to clash?
Well, I don't think there is any problem writing the data coming from the I2S Microphone to the SD card of the SPI interface. Is it possible to read and write to the sd card in the current system without the MIC?
Dear I compiled the project when i record the voice and replay , it skips and recorded wav file is 6 seconds .. Can you answer why can it skip ? is there a problem , using the same github code from your repository
I'm pretty sure that it's a matter of timing between getting buffer data from i2s and writing files to SPIFFS. The longer the recording time, the more this problem occurs. If you need a long recording, you need to allow files to be saved on other devices.
Hi the FSbrowser takes me thru but it shows file not found when there is a recording saved onto the flash of the ESP32?
327724 bytes
is shown but still ends up showing file not found?
It is possible that it was not actually saved. Please test again after recording as short as possible.
@@ThatProject I've tested and for the esp32 DEV KIT V1 , the fsbrowser needs to be compiled onto the ESP32 (meaning i have to long press BOOT to upload) but from the coding itself it should not overwrite any of the addresses that is stored within the ESP32 no? Iam confused , does it mean that compiling the FS browser wipes out the saved file when compiling to ESP32? Iam not sure if it is stack overflow either as 20 second recording is fine and ive tested as small as 5 seconds and it is saved perfectly fine. When it comes to uploading the FS browser sketch is when the Serial Port states file size is 0B.
@@jetblack6243 It means that your file exceeds the capacity of the Flash memory that can be stored. As the length of the recording increases, the file size also increases. So consider saving to other media like SD card rather than Flash.
Hi, the technical documentation says that this microphone gives out 24-bit in one Sample, when I listen to the recording I get only noise. I changed the Wav file, also changed the DMA buffer size. Subsazhi please, what needs to be changed to get high quality sound?
header[16] = 0x10;
header[17] = 0x00;
header[18] = 0x00;
header[19] = 0x00;
header[20] = 0x01;
header[21] = 0x00;
header[22] = 0x01;
header[23] = 0x00;
header[24] = 0x80;
header[25] = 0x3E;
header[26] = 0x00;
header[27] = 0x00;
header[28] = 0x00;
header[29] = 0x7D;
header[30] = 0x00;
header[31] = 0x00;
header[32] = 0x03;
header[33] = 0x00;
header[34] = 0x18;
header[35] = 0x00;
Thanks a lot for your hard work!!!
I changed the 24-bit sampling of the microphone and tested it, but it didn't work properly. I think we should look for more details.
Hey
I am using your code, but i can't capture any audio. it is constantly 0 procent. what could be the issue
It is most likely your i2s connection is wrong. In this series, Part. 0, you can check the data coming from your mems microphone. Please check it out. ua-cam.com/video/m8LwPNXqK9o/v-deo.htmlsi=wTWXDlQAMggRAkmg
@@ThatProject I got succes to capture something but it is recording only up to 33% and then it stop a shows error and starting from 0 procent again.
I am using ESP32-Devkitc V4 and INMP441 microphone and using the following pin for i2s interface
WS GPIO25
SD GPIO33
SCK GPIO32
@@latiffaghiri1500 This problem seems to occur when the recording length is long and exceeds the internal flash size. Please try for about 5 seconds.
@@ThatProject Thanks alot :D
hi the listSPIFFS link in your description shows 404 where can i find it now?
Seems like it's gone. Try this, github.com/Bodmer/TJpg_Decoder/blob/master/examples/SPIFFS/All_SPIFFS/All_SPIFFS.ino
Hello, I use this code on my microphone sph0645lm4h but i I can't hear any sound.I change #define I2S_CHANNEL_NUM (1). Thanks for you answer
I didn't play this project with the sph0645lm4h so not sure what the problem is. Sorry.
Does this work for ESP8266??? I cant find SPIFF.h
Since SPIFFS has been deprecated, you need to use LittleFS. Unfortunately, I haven't been able to test it on the ESP8266.
The write speed of SPIFFS is not fast enough, which can cause the input sound to lose data.
If you want to improve the smoothness of recording sound, you can consider using PSRAM, while also using dual cores to transcribe PSRAM wav data to SD
Totally agree with you.
Hi, pls respond to me. I can't receive any sound. here only the blank audio file is generated what can i do
Hello. Mm, that's weird. First, please check if INMP441 works properly.
Thanks for the great project. I have a question. How can i save that recording file to my computer directly?
It's not possible the way I did it here. You need to modify the code and connect it directly to the PC to save the byte data coming from I2s to the PC. Connection with PC can be done through wired serial communication or wireless TCP/UDP.
Hello, can I somehow combine the 2 codes to download it right after the recording script? Or can I obtain the audio it in a different way?
I'm not sure what code you want to combine. Tell me more clearly.
@@ThatProject the one you made and the one that is from the examples (that downloads the audio file)
@@unsoaremaimic7545 Unfortunately, it isn't easy. To download a file, the file must be closed. The file cannot be closed while audio data is being saved. This project is probably close to what you want. ua-cam.com/video/qq2FRv0lCPw/v-deo.htmlsi=ecwchDeSrtF-sGt4
When i try to run the FSBrowser example it recognize the filename but says that the size is 0KB
FS File: /recording.wav, size: 0B
Jaime Galvis Hi. I think you need to check the incoming byte data from i2s. It seems to be a problem here for some reason.
file.write((const byte*) flash_write_buff, i2s_read_len);
i want to record an internet radio stream. i have found the code that does the i2s_write,which sends the radio stream to the DAC, is it simply a case or taking the variables that are sent to i2s_write, and writing the variables to a wav file using fwrite,
Because writing to a wave file is file I/O, a short length is fine, but it can be difficult to handle a large amount of data. Anyway, I hope you have a good result with that.
If I want to make it 44kHz how should I modify dma buffer count/len or I2S_READ_LEN. Thank you very much.
Please refer to this project. It has a 44.1kHz sampling rate. github.com/MhageGH/esp32_SoundRecorder
its possible recorder audio and upload it in the same sketch?
I didn't make it but it's possible. It would be good to upload to a specific server after the recording is finished. It seems that you need a server so that you can upload wav files using HTTP post request.
Hello friend, can you help me do this project on sdcard? i just tested your code and works ok, but i want to store the wav on sd card
I think you can do this by switching to using SD cards instead of SPIFFS. I'll try an upgraded project for this sooner or later.
@@ThatProject thanks , I'm having some issues with the pins assignments for mems microphone and micro sd
Hi, another help please. Is it possible to record more time? I mean like 2/5 minutes recording, upload to webserver, delete this file, then record more 2/5 minutes and so on?
I know that its memory is 4 or 8mb, but is it possible to save, send it automatically through wifi and start another file at the same moment? Because I need a longer recording time. Thank you so much for your help.
Giuliano Dias Well, it's possible, but it occurs a time gap between storing and sending files to the server. The idea seems to need further improvement. One of the projects I did was to save a recording file to a smartphone through BT Serial directly. How about this one? ua-cam.com/video/AFGC9iYBxFQ/v-deo.html
Hello, nice video! really helpful, but I need some help please. I have recorded and try to upload using FSBrowser.
But there is an error saying:
exit status 1
'A0' was not declared in this scope
I have searched everywhere for this but it did not fix the problem.
I can simply comment out this line: json += ", \"analog\":" + String(analogRead(A0));
and it works just fine to send the audio to the server, but the noise is too much it almost makes my voice sounds like a robot. I think it might be caused by the line I commented out in FSBrowser?
Please reply if you have any idea thank you so much
I am using M5Core2, with INMP441. My pins are different it goes like this: (WS:33), (SD:36), (SCK:32). If you have any comments on my pin connection would be helpful too thanks so much.
Hi buddy
which changes does it require if i wanna capture audio in SDcard instead of a browser?
It's temporarily stored in SPIFFS, but you can change this to your SD card.
@@ThatProject Thanks alot for tips, it works fine now. But i have one issue that we 1 minute recording is finish so it start recording from the begining, is it meaning that it is doing or how can i make it so it run only once
@@latiffaghiri1500 This is because the temporarily saved file name is the same. I think the file name should be different each time it starts.
@That Project I have seen the video before, but when I want to try to make a sound with the i2s sensor microphone on the web client, I get confused there ..
for the esp32 client side, I found this line of code to send to the websocket server: client.sendBinary((const char *) i2s_read_buff, i2s_read_len); , and on the web client side generates BLOB data, well, can it be made as a sound stream like a video stream?
You said you will include it in your project but still waiting for updates or could you pls suggest any solutions
Have you seen this video? ua-cam.com/video/vq7mPgecGKA/v-deo.html
You can get voice data received from INMP441 using the Node.js server. If you add the web client here, I think it'll be the project you want.
I followed this but it still doesn't work, please help me thanks❤️
Which part do you have a problem with?
FYI, this project was done in ESP32 version 1.0.6. If you use the latest version then try it with 1.0.6.
Nice job, I'm getting a lot of it, but I have an issue, maybe you can help.
instead of your mic I'm using a 32 Bit one and get some inconsistency regarding
time. The header should be fine by adjusting it simply to 32 Bit, but
the I2S_READ_LEN is a problem, bcause I can't figure out the right value without getting the "store prohibited" error. With the bigger FLASH_RECORD_SIZE, what will be compared with flash_wr_size I get for 10
seconds of recording 20 seconds and my file plays 10 seconds, but
stutters the rest , what was recorded more.
I haven't used a 32 bit one yet, so I don't know how to solve the problem you have. Seem like need to correct the i2s setting and the header of the wave file, and also it might require bit operations to write the file byte correctly. I'll leave a message again if there is a clue to the solution.
Sir can u send me the code link plzz
You can find it in the video description.
Hi, Im running into an issue where when i compile and run the code, the serial monitor shows that sound is recording but it takes about three minutes before it completes when I have left it at the default recording time of 20 seconds. Following this, when I compile the FSBrowser example and enter the command in my web browser, it says FileNotFound. I have checked the spelling as well so I'm not sure what the problem is now
There seems to be a problem with taking 3 minutes. First of all, please format SPIFFS to see if the space is properly empty. Also, please test it with a shorter length of about 5 seconds.
@@ThatProject thanks for your reply. I tested it with 5 seconds and now the recording seems to take approximately 20 seconds to complete. Now when i try to retrieve the file from FSBrowser, serial monitor says "handleFileRead: /recording.wav" but the file doesn't download to my computer.
@@ThatProject If you have a contactable email address, inbox me and I can show you what my monitor is printing. Probably better explained with images
I can get the wav file before, but now I get “File is not available!” message. Do you know wts the problem. Thanks
Please check your code again. Also, please check if SPIFFS is empty before recording.
Thank you for your reply. It just work again suddenly. But I got another problem that for example I set the recording time to10s but it took ~30s for the whole process. Do you know how to solve it
@@jasonttyuen This is a known issue. This problem occurs because it takes longer to write a file than to read the buffer of the data.
In conclusion, I recommend transferring voice data to another device (e.g., mobile) without writing directly to ESP32.
Thank you. I’m following your flutter app tutorial
Thank you Eric for updating Part 0 for ESP32 2.0.x., Now I use Part 4. with ESp32 2.0.x to save the mic file, it compiles but gives a few deprecation warnings, so in this Part 4 code, I modified i2s_config_t following your modifications on Part 0, and the deprecation warnings went away and I was able to read the saved wave file in the terminal after uploading the code, but when I load FSBrowser code to get the saved file, first in Serial monitor, it says "FS File: recording.wav, size: 640.04KB" but in webserver, I read FileNotFound.
Is it possible for you to modify Part 4 also for ESP32 2.0.x? Thank you so much in advance.
After uploading the webserver program, information about all files is output to the console.
Line# 231 DBG_OUTPUT_PORT.printf("FS File: %s, size: %s
", fileName.c_str(), formatBytes(fileSize).c_str());
Can you see your Wav file here?
im confused by the part "dac_value * 256 / 2048" in i2s_adc_data_scale(). esp-idf example says "dac_value * 256 / 4096". why change 4096 to 2048?
shouldnt the 12-bit to 8-bit conversion use 256/4096? anyone share some thoughts?
I adjusted the value here to forcibly increase dac_value. This can have an amplifying effect.
@@ThatProjectthank you very much for clarification. correct me if i'm wrong, so effectively you doubled the adc value?
your work on esp32 i2s brings great help to all of us. keep up the good job!
Can this be adapted for use in Rhasspy as a voice command module?
Chris Maus Hi. Wow, it's interesting.
Rhasspy Voice Assistant supports not only Node.js but also WebSocket so I'm pretty sure there is a way to use this with INMP441. But it's not supporting Arduino or ESP-IDF directly. Thus, we need to make another programming too like the Node.js server. I'll try to make a project if it has a good chance. Thanks for letting me know this.
You made an excellent project. I love it.
I try to capture to save on MicroSD too however I couldn't do that. Could you help me to save on MicroSD?
You can change the storage location from Flash to SD. Please try a test project to make sure you can read and write to the SD card first.
@@ThatProject I made it yesterday. I forgot to edit the comment. Thank you. I saw in the comments that a few people also needed it. I share it who need it.
global:
const int headerSize = 44;
byte header[headerSize];
inside setup:
wavHeader(header, FLASH_RECORD_SIZE);
SD.remove(filename);
file = SD.open(filename, FILE_WRITE);
if (!file) return;
file.write(header, headerSize);
i2sInit();
xTaskCreate(i2s_adc, "i2s_adc", 1024 * 2, NULL, 1, NULL);
Hi, thanks for your great videos! I have a question - is it possible to connect I2S mic to ESP32CAM?
Marcin Zacharzewski It's gonna be another challenge for me. Hopefully, I can deal with both of them for the new project. Stay tuned.
It will be a great feature
Hey i have done it with ESP32 CAM module. Just the problem you need to face with it , tha BrownOut timer trigerrs due to low power !!! Ping me here if you want my help there ,,,,,,, Also Great thanks to Video owner /.
@@dharmpatel5455 Hey!! I would love to know how you did this! Could you tell me more? :D
@@OneDirectiontoSA Yeah sure , you just need to repeat whole steps , but in ESP32-CAM you need to attach external power supply otherwise your brownout timer will trigger . But if you want to just record then also you can dothat without external power supply.
Do you have any other questions then ask!?
Did anyone try it with the ESP32 from Joy-it?
It seems like i can not find the right Pins, since all the data is always 0.
I tried the pins the seller of the mic recommended but still no response.
Also the recording takes much longer than the time i pass with RECORD_TIME, while the WAV-File is often shorter.
Anyone got some advice?
mac4trouble Oh, are you using the NodeMCU ESP32 from Joy-IT? Well, I've never tried it so I cannot see what your problem is. Sorry.
Thanks for the video, I have recorded the audio at 20 seconds but that it showing FileNotFound
After that i tried 30 seconds then it shows the file and i downloaded it also but its a blank file, no sound is there,i dont know why
Please help with this.
Check your SPIFFS size and for the test, just record the only 5 seconds and see the result again.
@@ThatProject Ok Thank you
Hello, I am trying this project, but the file I am saving is around 60k and the one I am reading differs, it might be 50k, 40k or so, and then when I listen to it even I have the recording time set to 20"I am able to hear only two or three seconds. Any idea why this can happen? Thanks!
Hi. In the basic partition scheme, you can only store about 1 MB in the SPIFFS (SPI Flash File System). Before you start recording, please format the SPIFFS first. If the recording is not finished, you can only listen for 2-3 seconds only. If you need to record for a long time, I recommend using the Sd card.
@@ThatProject do you have a sample code for saving the .wav file to sd card
@@richmondeustacio1416 Sorry, I don't have a code for saving a file to SD CARD. I think there are many examples of writing files to SD CARD instead of SPIFFS from googling.
Thanks for the great tutorial :-). I have two questions. The first one is, why there are two i2s_read calls before while loop ans the second, if anybody has found some improvements in code to make sound more clear and less noisy? Thanks for any advices.
The answer to the first question is to eliminate noise at the beginning. I noticed a random strange noise coming in, so I read the data in advance. The second answer is a tricky question. Please search about noise handling for digital signals rather than analog signals.
@@ThatProject thank you very much for the response :)
Thanks for the video, I am relatively new with the Microcontrollers so please excuse me if I sound stupid. When I try to change the I2S_SAMPLE_BITS to 32 instead of 16, I am getting a runtime error. I tried to understand why it is happening but I couldn't figure it out. Can you please explain to me why the code is not working if I change the I2S_SAMPLE_BITS to 32?
I also tried to change the I2S_SAMPLE_RATE to 48000 as we used in Part 1 and all I can hear is noise. Should I consider something else while changing these parameters? Thanks in Advance.
I found a solution. If I change the dma_buf_count to 32 instead of 64, it is working fine. Yet to figure out the sample rate issue though.
In order to change to 32 bits, the DMA buffer count and length also need to be changed. Because the size of the sampling increases, it exceeds the maximum allowable range, resulting in runtime errors.
The option below is best for voice recording. Please refer to it.
#define I2S_SAMPLE_RATE (16000)
#define I2S_SAMPLE_BITS (32)
#define I2S_READ_LEN (1024)
const i2s_config_t i2s_config_tx = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = I2S_SAMPLE_RATE,
.bits_per_sample = i2s_bits_per_sample_t(I2S_SAMPLE_BITS),
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 32,
.dma_buf_len = 64
};
@@ThatProject Thanks for the clarification :) . I have one more doubt that I cannot figure out on my own. We are taking I2S_SAMPLE_BITS as 32 (or 16), but the variable i2s_read_buff is of char type, and char has a size of only 8 bits. If I am not wrong, we are supposed to lose the remaining 24 bits of data (32 - 8 = 24), but this is not happening as we can listen to the audio very clearly. Is there any explanation to how this is happening?
@@potugada Sorry for the late reply.
First, i2s_read_buff is char*, not char. Put the data into char* as long as I2S_READ_LEN through the i2s_read function. Therefore, it becomes 1024 bytes.
Also, a 32-bit I2S_SAMPLE_BITS represents the length of one sample.
One sample is 4 bytes(32/8 = 4bytes) long and can have 1024/4 of data at a time with the above parameters. You can change the I2S_READ_LEN on your purpose.
Hi, Thanks for this great video!. I would like to need some of your help. Is there any possible ways to save the recorded .wav file into SD card?. I have tried many solution from the internet but it did not work well for me :(
You can simply change to the SD card instead of SPIFFS. Have you tried it based on my project?
@@ThatProject Yup, I implemented the code based on your project. I also came with several issues. During the directory listing after recording, my code was corrupted. Maybe I should fix in listSPIFFS function right?
Btw, Thanks for your helping!. Your idea can deal with my problem very much :)
@@mr.genius6872 if you have an issue from the directory listing, why don't you remove it from your side? it’s not a big deal.
@@ThatProject Hi, I have another question about the .wav file. Are there any methods to rename the filename with timestamp?
before i get wav file from esp32 how to send this wav to firebase without reload code
Well, it doesn't seem that simple.
@@ThatProject how can i make a video call with anyone by esp32 cam ?
i try to it in my smart doorbell project with esp32 , but it's too hard to do ....
if you have solution , will you post a video ?
tks
@@AlanTran18 Yeah, I hope I can handle it soon.
Very nice project I wanted this type to record audio thank you very much. I have one doubt can you make it work like walkie talkie like when we press a button it should start recording until we release the button i.e record time depends on button press? can you give me a platform so that i can contact you please I need help in this project?
Yeah, I like the walkie talkie. I was actually planning a similar project. If I have a chance, I'll create a project. Unfortunately, there is no personal contact point. Thanks for understanding.
I want to build a wireless microphone with esp32 wifi and a mems microphone. I did never find such a project. Who can help?
What about this project? ua-cam.com/video/vq7mPgecGKA/v-deo.html
it's sending captured audio data to my mac via the wireless network.
Hi! Can I send the audio to the server, right after the recording is finished?
Jonathan Allan Hello. Yes. You need to prepare the server first.
The Wav file can be transferred using HTTP POST. You can implement it in a similar way to the following video, ua-cam.com/video/RZVzZfndIS0/v-deo.html
@@ThatProject Thanks!
@@ThatProject Hello! Can you get in touch via my email john.dvp0@gmail.com? I have a project that may be of interest to you. Thank you!
Can you do the same with Bluetooth Headset Mic? I know who would sponsor it.
MrLogin0987 It cannot be with BLE. The audio is on bt classic over an hfp/a2dp connection. I hope my project video on BT CLASSIC is helpful. It goes on in a series.
Thanks im considering this topic next video can u make tutorial about using max98357 i2s audio amplifier to playback music esp 32 ?
Thắng Huy Unfortunately, I don't have a max98357. Sorry.
Hey i tried it like a dozen times what's exactly happening is whenever i am trying to record the sounds after 20 seconds i do get the file name and a good amount of size . But when i upload the fs browser sketch either the file is not there or either the size of that file is 0 bytes basically i am unable to extract it . So what do i do in this case ?
What's going on there? Please check the fs browser sketch does have not any related SPIFFS code again.
@@ThatProject i did I'm just loading it from the examples only . Also tell me something is there any other way to access spiffs ? Because i have a feeling that maine the fsbrowser is either overwriting the spiffs or my sound is not properly getting saved on the esp
@@TechInventorAman I don't understand why it happens. It's the easiest way to get a file from SPIFFS so I did in this way. One thing also I don't understand is the recorded file size becomes 0 bytes when you use this FSBrower. I've never experienced anything similar to this case. Even I don't know where to start it to touch.
@@ThatProject Can i get your email so that i can explain you the whole issue . Maybe you'll be able to help better
@@TechInventorAman So sorry. I don't take any questions via email. I want to solve the problem here.
What is the maximum recording time ?
parth kamra Hi. It depends on the SPIFFS partition scheme. Usually, it's about 300 kb in 10 seconds. You can record for about 30 seconds in the basic setting.
Amazing project! Thanks for such a nice tutorial. I have tried nearly everything good, but I am confused by the performance of fsbrowser. The serial print out everything exactly same with you, but I just cannot download it from my web browser as it always waiting for the respond from the mcu. I am not sure what's wrong?
Luckily, I transmit the file successfully with your next tutorial, Thank you very much! But I am still confused by the reason why I cannot succeed with the default FSBrowser, may be from the 80 port or some other reasons?
TAO CHEN I don't know why but it seems like the WIFI connection has an issue. Have you tried it with the other wireless router?
@@ThatProject Yeah, I tried with another router, but the situation remains, It looks like browser cannot get the reply from the mcu, so it is always waiting for the respond..
TAO CHEN oh, what about this? ESP32 only supports 2.4 GHz WIFI connection. Please make sure your wireless router turned on 2.4 GHz.
@@ThatProject Actually, I have tried both, the 2.4G and 5G Hz connections, but all fails...
By the way, could you please explain a little what SPIFFS is ?. sorry i'm new to this
SPIFFS (Serial Peripheral Interface Flash File System) is a s a light-weight file system for microcontrollers with an SPI flash chip. SPIFFS let’s you access the flash memory as if it was a normal file system like the one on your computer (but much simpler of course): you can read and write files, create folders, etc.
@@ThatProject can we use the files from SPIFFS then upload them to the live web server?
@@ThatProject example: I have a website www.project.com and I want to upload the recorded wav file to that website, is that possible?
@@achmadarifmunaji3320 It's possible if you make two parts.
[1] Preparing a server that is connected to your website. It should be ready to upload a file through the API you make.
[2] Reading a file from SPIFFS. You need to select the specific file from SPIFFS to upload this file to your server. And then upload it via the API you made above.
@@ThatProject where should I save the API file? Is it in SPIFFS? or on the website?
Hey good work on the project, but I wanna ask about mine. I used your code but for me, the result my voice was there but it's really noisy. Can you tell me how to get rid off that noise? Thank you.
One way to handle it is "i2s_adc_data_scale".
My code line#84, d_buff[j++] = dac_value * 256 / 2048;
As the volume grows, so does the noise. Try to adjust these values.
Another way is to modify the sampling bitrate to 32 bits.
The parameters I use are as follows.
#define I2S_SAMPLE_RATE (16000)
#define I2S_SAMPLE_BITS (32)
#define I2S_READ_LEN (1024)
const i2s_config_t i2s_config_rx = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = I2S_SAMPLE_RATE,
.bits_per_sample = i2s_bits_per_sample_t(I2S_SAMPLE_BITS),
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // default interrupt priority
.dma_buf_count = 32,
.dma_buf_len = 64
};
If you use this, writing the wav file directly to SPIFFS may be different.
@@ThatProject ahhhh I see, thanks. And wanna ask again, can I edit this project code so I can stream the audio using UDP or maybe if you knows better about UDP can you somehow make the code? Hehehe cause I'm little bit confused and frustrated about stream the audio using this UDP thingy 😐😂. Thank you.
@@gihon_z3r0dxd84 Sure. This is a quite simple project so you can edit whatever you want to do. There are parts that need to be implemented in UDP when sending continuous data if the packet size is bigger than 1472 bytes which is the maximum pack size of UDP at once. Anyway, let me know when you have a result.
@@ThatProject okk, so if I want to do that I don't need SPIFFS, listSPIFFS, and header parts right?
@@gihon_z3r0dxd84 I don't think both are necessary.
good job! do you have one save audio to SD card?
Unfortunately I didn't save to sd card in this project, but I think you can easily change that. I will do that on other projects when I get the chance.
@@ThatProject Thanks. I see you used esp32(lolin32 lite) board, my test used ESP32 DEV MODULE, got rebooting some time, can be the board reason? even I got: recording.wav 655404 bytes from record code, still got 'FileNotFound' in FBSrowser's IP page. what can be?
@@saydiy1528 Please test by reducing the length of the recording to about 5 seconds.
@@ThatProject Thanks. it works for 5s. and got 'FS File: recording.wav, size: 160.04KB' , the IP still shown 'FileNotFound', what can be? BTW. do you play the wav file recorded from SPIFFS?
@@saydiy1528 Could it be that the contents of Flash were deleted while using FS Browser? Check: "Erase All Flash Before Sketch Upload: "Disabled" in Arduino IDE
can you make the tutorial "how to make Bluetooth speaker use esp32" please?
haha Bluetooth Speaker? I'm gonna think about it. Thanks for your comment.
Thanks mate ! I will check that !
i use this code, but i take a so noise audio. How ? Thank you so much
d_buff[j++] = dac_value * 256 / 2048; Please adjust this part. like * 256 / 4096
@@ThatProject i changed, but not
@@uchaila9935 Are you sure all part except for the noise is working fine?
@@ThatProject i copy this code. Every is good but when open the file, it have NOT sound. Can you help me with team view? Thank you so much
@@uchaila9935 Please try to have the recording short. Around 3 seconds. Then check there is a wav file or not.
How to save .wav in sd card
I have idea related basic sd .txt file read and write but how to do on.wav file?
Shrikant Nikam Good. You can write the wav file as a binary to your SD card. You've already known how to write a text. Try to change it to the binary writing instead of the String writing.
awesome
Hi, when using this code I changed the sample rate and WAV header to specify 44100Hz. What appears to be happening is that the read loop seems to be reading for longer than necessary in order to compensate in some way. As in, when set to record for 10 seconds and 41000Hz, it actually records for 27 seconds. It seems that it's only incrementing the stored file size like a 16000Hz recorder while the file size goal has been updated accordingly (44100/16000 = 2.7... * 10 = the 27 seconds of recording). Is there another figure that I must update to actually change the sample rate of the i2s reader or am I just doing something foolish, thanks.
Zamblom _ Nice try. I've never been trying 44kHZ because I needed 16 kHz sampling rate from the first project.
Did you update the Wav file header with 44kHz? Currently, the header of the WAV file is set to 16kHZ. Please change the header[24], header[25] to 44000. soundfile.sapp.org/doc/WaveFormat/
@@ThatProject Yeah I figured that out and changed that which solved a previous issue with the output file but this issue still remains. Thanks for replying so soon.
Zamblom _ Well, I have the same problem in 44kHz. I need to drill down more.
@@ThatProject Glad to know it's not just me then at least! I'd be interested to know if you find anything. Thanks again
Have you guys found any solution?
I need code esp32 INMP441
You can find this source code in the video description.
github.com/0015/ThatProject/tree/master/ESP32_MICROPHONE/ESP32_INMP441_RECORDING
@@ThatProject how to save the recording file, i can't save the file, help❤️thanks
You Rock!!!!
Plzzzz Make A Good looking Home Automation App In flutter Plzzzz
With All Facility will avaialble In This App
please help me use the removable push button to record for five seconds, thanks THAT PROJECT
Sounds like a good project idea. Let's think about it.