Talking Clock using ESP32. How to?

Python is a widely used high-level programming language for general-purpose programming.Tutorial, Question, Experiment, or Project can discuss or post here.
User avatar
Princess Anna
Posts: 27
Joined: Fri Feb 03, 2017 2:40 pm

Talking Clock using ESP32. How to?

Wed Aug 08, 2018 7:14 pm

The MP3 shield that has come from aliexpess for a mere $1.3 a piece was lying on the table for quite some time as I was really not able to find a spare micro SD card to check out how it works! Then Reon, my friend’s son asked me for a talking clock which will alert him at a different time of day with different kinds of music of his choice. The clock should also be able to speak up other parameters like sensors value etc.
550px-Miniplayer_pin_map.png (97.88 KiB) Viewed 2246 times
Construction hurdle
Since the entire MP3 capability is inbuilt into the shield, not much computing power is required to run and manipulate the song sequences while in use. Therefore, an Arduino UNO is enough for it. But the problem comes when I tried to attach a TFT display ( ILI9163 128*128 ) with the UNO, the UNO could not run it. Therefore, I preferred my favourite MCU – ESP32 which has more muscle power, low power consumption and more GPIOs to tinker with.
esp32.jpg (102.4 KiB) Viewed 2246 times
Sound files preparation
For the preparation of sound file one can use his own voice, microphone and recording system. Audacity is an excellent sound software for creating the mp3 files from microphone sound. However, my choice is Python with a text-to-speech facility. First I install python and then I install python-text-to-speech (pyttsx / gTTS) and then create my mp3 files from simple sentences. There are about 52 languages in which you can create your own mp3 files.
sudo apt-get install python
sudo pip install pyttsx
sudo pip install gTTS
After installing these softwares you can straight away create your mp3 files from command line itself. “1” -l en -o /home/mp3/0001.mp3 “2” -l en -o /home/mp3/0001-speak-two.mp3 “The time is now” -l en -o /home/mp3/0101-speak-time-now.mp3
However, I’ve included a file to create your mp3 files at relax. Therefore, the first big job for the task is to create the mp3 files and then save them in the format like 0001.mp3, 0002.mp3 etc. Some discretions can be added like
However, the MP3 shield will pick up the 0001-speak-one.mp3 as the first file and 0002.mp3 as the 2nd file etc.

Type of MP3 files
The MP3 shield has an SD card on it’s back. In the root directory of it, create a folder called ‘mp3’ and then dump all the mp3 files in it. For clock sound you will require all the sounds from 0 to 59. To start the dialog you may like to have an mp3 file like – “The time is now”. You also may like to have a music at the beginning of the speech. Dump all these variety of files in the mp3 directory of the sd card and you are done for the mp3 file creations.

Special note: In case you find there is sputtering noise from the speaker then put a 1K resistor between ESP32 Tx and MP3 Rx pin.

RTC module DS3231 which comes for about $1.5 a-piece from is far more superior to the other RTC module as it has inbuilt quartz which is again corrected by an inbuilt temperature sensor. It’s very precise, runs on 3.3 volt and maintains precision over a very long period of time.

RTC DS3231
DS3231-RTC-Pinout.png (23.52 KiB) Viewed 2246 times
rtc-ds3231-high-precision-clock-module-for-raspberry-pi-b-824-500x500.jpg (17.46 KiB) Viewed 2246 times
Is developed on Arduino IDE using ESP32 dev. board. Besides talking about initial music, day, date, time, AM or PM the clock also speaks the temperature from the RTC inbuilt temperature sensor. First we have to set the RTC clock for which I’ve put the codes in the setup section to set the time. Every time while flushing the ESP32 with the sketch the time get set. But you need to care about the time of the computer. I’ve also added a separate sketch for setting up & displaying the time.

It requires only 6 wires to run the MP3 module – Tx, Rx, Vcc, Gnd, Spk1, Spk2. The RTC runs on I2C bus and the TFT runs on SPI bus. The entire schematic is shown in the picture. On ESP32 the Tx1 and Rx1, I could not run so I choose Tx2 and Rx2 and it works. The maximum volume level of the MP3 shield is 30. Beyond 30 it will be limited to 30 only.

Clock with NTP time server
In the absence of RTC3231, one can run the clock using time from the NTP server. For that, I’ve also added the sketch where one has to enter the wifi id and password.

Power supply
Any 5 volt smartphone charger is enough to run the clock. However it can also be run from a Li-Ion 3.7 volt cell by giving the supply on the 3.3 volt line and the ground line.


This inexpensive talking machine can be used for more sensible purposes like audio alarm for gas leakage with leakage level and wind direction. It’s the moment when people neither can see, nor can comprehend. They only need direction to follow
….. Gas leakage at Post A, Run towards B gate. The machine will measure leakage level, identify wind direction and then issue instruction. All can be achieved instantly.

Other than this can also be used during crisis situations like – Fire alarm when people will be directed to use staircases in a smoke-filled atmosphere when none can open their eyes nor they can see but hear. So it can be used during stampede situations when crowd will be directed vide voice instructions – how and where to move or just to remain stand still… etc.

ESP32 $7.5
TFT 1.44” $3.5
RTC DS3231 $1.2
8 Ohm speaker (0.3 watts), Micro SD Card, wires, board, power supply etc extra.

Source Code can be downloaded here:
(11.63 KiB) Downloaded 75 times

Return to “Python and OpenCV”