Introduction: ESP8266 Audio | Play Audio File With Esp8266 or Nodemcu Without SD CARD

About: I am an engineering student and i just love doing electronic (mcu's) and programming (C,C++,JAVA) based projects.

Hi Guys, Today in this tutorial we will store a audio file in our ESP / Nodemcu board and we will play it without any external I2S DAC.

we will encode our audio into hex format and then we will store the audio in our ESP8266 / Nodemcu and then we will play it from ESPs internal memory using a speaker.

so without wasting anymore time let's start:-

Step 1: Things You Need

Step 2: Circuit Part

you can find the attached schmatics of the project and please connect everything according to shown schamtics.

And if you want you can make a PCB for it and you can order your PCBs from PCBGOGO.com https://www.pcbgogo.com

and

Join PCBGOGO anniversary & get anniversary discount & click on below link to get the benefits now:

https://www.pcbgogo.com/5th-anniversary-discount-....

Up to $150 Coupons, Stylish Souvenirs Campaign Duration: Aug. 25th - Sep. 25th, 2020

Though PCBGOGO is only 5 years old, their factories have been providing PCB manufacturing and assembly for domestic customers in China for more than 10 years. The PCB fabrication and assembly services from prototype to mass production is fast, affordable and reliable.

Step 3: Basic Code Setup and Example

so before we proceed make sure you have arduino IDE installled in your PC and you also have installed the ESP boards in the IDE.

Then open the IDE and go to library manager in your IDE and search for "esp8266 audio" and install that library in IDE, then go to the examples of ;library and open "PlayWaveFromPROGRAMEM" and upload it to your board and the speaker attached to board will play the default audio file which is encoded in Viola.h. so we need to encode our audio and put our audio in viola.h and we are done. so let's prepare audio.

Step 4: Prepare and Encode the Audio

so as you can see i recorded a audio and converted it to a 32KHZ audio and saved it as 16 Bit PCM. and file size was 500KB near about (8 sec long) , based on that if you want a long duration audio file go for a lower project rate (from 8 KHZ - 40 KHZ ) so choose either quality or quantity but try to make a file near about 500KB or less.

Then go to a online file to hexadecimal converter :
http://tomeko.net/online_tools/file_to_hex.php?lan...

and choose your file and it will give you hex codes for your audio and just copy the hex code.

and we successfully encoded our audio into hex, now we just need to paste it into the code.

Step 5: Let's Upload the Code and See It in Action

just come to code again and in Viola.h file just remove all the hex codes and paste our hex codes which we got from online file to hexadecimal converter as shown in images.

Then after that just upload the code to your board and you will able to hear the audio you recorded and encoded.

Please refer the attached video for demo and detailed tutorial.

Thanks|||

Have fun with your ESP based audio device. |||