Project 17:Voice Recorder

0 15 Medium

In the previous lesson, we used the speaker to make a music player. In this lesson, we will further expand on this, conduct an integrated design with the microphone, realize the function of controlling audio recording and playback via different buttons, and finish making a voice recorder.


Project Objectives


Knowledge Objectives


1.Understand how microphone recording works.
2.Record and play sound on the UNIHIKER K10.


Practical Objective 


Make a voice recorder using a microphone and buttons: Press Button A—a prompt tone sounds, sound recording starts (supporting multiple recordings); Press Button B to play the latest recorded audio.


Materials List

HARDWARE LIST
UNIHIKER K10
MicroSD Memory Card
USB Cable
Card Reader

Preparations


Hardware


Insert the TF card into the corresponding slot on the UNIHIKER K10, then connect the UNIHIKER K10 to the computer with a USB cable.

 

Software


Open Mind+ 2.0, switch to“Upload Mode”, connect the UNIHIKER K10 as shown in the figure below, and load the UNIHIKER K10 library.

 

Hands-on Practice


Next, we'll use buttons to control the microphone and speaker for a voice recorder.
Task 1: One-Time Recording
First, we'll use Button A to control the microphone — after a prompt tone sounds, the audio will be recorded and saved to the TF card.
Task 2: Play Back Recordings
Then, we'll use Button B to control the speaker to play audio recorded in Task 1.
Task 3: Make a Voice Recorder
Last ,we'll use Button A to record and store multiple audio clips, and display the total number of currently recorded audio clips on the screen. Meanwhile, press Button B to play the latest stored audio to complete a voice recorder. 


Task 1: One-Time Recording


Code 


Audio recording on the UNIHIKER K10 uses the microphone. During recording, the status indicator stays on to remind you it's in progress, and turns off when recording ends. Their specific positions on the UNIHIKER K10 are as follows:

Sound recording uses the "Audio" in UNIHIKER K10 :“record audio to TF card (sound.wav) for (10)”block, as shown below.

Prompt tone is realized by playing note pitch via the speaker, using the”play tone (Low C/C3) for (1) beat”block under the "Audio" in UNIHIKER K10.
The complete program code is shown below:

Note: Images have no background (like a photo frame) and can only display properly (no black background) with a TF card.


Run the Code


Click the“Upload”button.After upload completes, press Button A—a prompt tone sounds, the status indicator lights up, and recording starts. Recording ends after 5 seconds, and the status indicator turns off.

After recording, remove the TF card from UNIHIKER K10.You can view and download the audio (sound.wav) on the TF card via a computer.

Code Review


 

Category

Blocks

Function

Record audio for a specified long period of time, name it and save it on a TF memory card, save the audio format as wav.


Task 2: Play Back Recordings


Code


Playback of recordings uses "play TF card audio (music.wav) in backgroud”block under "Audio" in UNIHIKER K10.
The complete program code is shown below:


Run the Code


Click the“Upload”button. After upload completes, press Button B to play the audio recorded in Task 1.


Task 3: Make a Voice Recorder


Code


In the above tasks, after one recording and playback, pressing Button A again starts recording and saves the file as sound.wav. As the file name is the same as the previous recording, the new file overwrites the old one. 
To record multiple times, use unique filenames for each recording, such as "sound+number.wav". Use the variable "number" to distinguish files and save multiple recordings.
The corresponding code is as follows:

To play the latest saved audio when Button B is pressed, modify the function for Button B and use the variable "number" for the audio filename. When number=1, it means no recording exists and no audio can be played. The corresponding code is as follows:

Finally, add code to the main program to display the number of currently recorded audios.
The complete program code is shown below:

Run the Code


Click the“Upload”button . After upload completes, press Button A multiple times to save multiple audio clips; press Button B to play the latest saved audio.

Similarly, using the TF reader, you can view and download recorded audio on a computer, as shown below.

 

Knowledge Base


Next, let's learn and summarize the hardware knowledge used in this lesson.


How microphone recording works


1.The concept of a microphone


A microphone is a transducer that converts sound energy into electrical energy. Its core function is acoustic-electric conversion, which lays the foundation for later signal amplification, transmission, and recording.
oduce higher-frequency signals, accurately reproducing volume and pitch.
When speaking or singing, vocal cord vibrations create alternating dense and sparse sound waves in the air. Amplitude determines volume (larger amplitude means louder sound), and frequency determines pitch (higher frequency means higher pitch). The microphone's sensitive element captures air vibrations and converts them into regular electrical signals. Stronger vibrations yield larger - amplitude signals, and faster vibrations yield higher - frequency signals, accurately reproducing volume and pitch. 
Essentially, a microphone acts as an energy bridge between sound and electricity. The electrical signals are amplified and transmitted to produce clear audio.


2.Principle of the Microphone


A microphone is an energy conversion device for acoustic-to-electric conversion. All microphones follow the same core principle: 
First, sound waves as air vibrations reach the thin elastic diaphragm inside the microphone. The diaphragm vibrates in sync with the sound waves, receiving the sound signals. 
Next, the diaphragm's mechanical vibration triggers physical effects via internal structures, converting sound vibrations into physical changes. 
Then, these physical changes are turned into weak electrical signals, with frequency corresponding to pitch and amplitude to volume. 
Finally, the weak signals are amplified and optimized by a circuit, becoming clear standard outputs for devices. 
In short, the principle is: Sound waves → Diaphragm vibration → Physical effect → Electrical signal → Amplified output. Different microphones vary only in the physical mechanism of the “mechanical vibration to electrical signal” stage, but their core acoustic-to-electric conversion logic is the same.

The UNIHIKER K10 is equipped with dual MEMS microphones, which are small in size, low in power consumption, and less affected by ambient temperature and humidity.Dual microphones provide better noise reduction, improve the accuracy of voice wake-up and recognition, and ensure clear recording quality.The use of the speech recognition function will be described in detail in Part 3. 


Challenge Task


Create a voice memo for daily recording of content of different lengths.
1.Press Button A to record a 3-second quick keyword (such as a shopping list or temporary reminder), and the RGB LED will light up blue as a reminder.
2.Press Button B to record an 8-second detailed note (such as brief meeting points), and the RGB LED will light up red as a reminder.
3.Finally, display the number of recorded audio files, as well as the name and duration of each audio file on the screen.
Tip: Based on this project, you can use the variable "number" to control the number of rows for displaying audio filenames and durations. 
The reference program code is as follows:


 

icon peoject 17.zip 37KB Download(0)
License
All Rights
Reserved
licensBg
0