Record Voice Message & Play it Using Python

Now you can build Voice Recorder just by writing few lines of code using Python.

Jayeeta Mondal
2 min readNov 14, 2021

Sometimes writing up a message can be boring and you feel it more easy to send a voiceover other than typing! I am sure you have gone through this type of situation. Now you can build this Voice Recorder just by writing a few lines of code using python. You can record your own voice, save it & play it to check.

So first of all three python packages are needed.

  1. Sounddevice
  2. Scipy
  3. Playsound

How to install Sounddevice Module :

pip install sounddevice

Write the above command on terminal to install sounddevice & press enter.

How to install Scipy Library :

pip install scipy

Write the above code on terminal & press enter.

How to install Playsound Module :

pip install playsound

Write the above command on terminal & press enter to install playsound.

Now with all the requirements being set, let’s get started with the coding part.

First import sounddevice, then from scipy.io.wavfile import write. After that from playsound import playsound. Now you need to create a variable to declare samplerate, which is ideally used as 4100. You need to declare a variable for seconds you want to do recording. For example let’s say you want to record voice for 10 sec. Then second = 10. Now start recording & pass the object sounddevice.rec(int(second*fs),samplerate=fs,channels=2) to the variable recording. After that call the object sounddevice.wait() to stop the recording & save it. Now save the recording into a wav file. Atlast play the recording using playsound.

Summary

This project is for the beginners. Although you can integrate it with other project & make a best use of it. I tried to write this article in a simpler way. I hope you liked this article. Feel free to ask your valuable questions in the comment section below.

--

--

Jayeeta Mondal

Data Scientist || Freelancer || Open Source Contributor