Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Create a Sideshow application in Python
Next article icon

Prerequisites:Python GUI – tkinter,Create a Voice Recorder using Python

Python provides various tools and can be used for various purposes. One such purpose is recording voice. It can be done using thesounddevice module. This recorded file can be saved using thesoundfile module

Module Needed

  • Sounddevice: The sounddevice module provides bindings for the PortAudio library and a few convenience functions to play and record NumPy arrays containing audio signals. To install this type the below command in the terminal.
pip install sounddevice
  • SoundFile:  SoundFile can read and write sound files. To install this type the below command in the terminal.
pip install SoundFile

Approach:

  • Import the required module.
  • Set frequency and duration.
  • Record voice data in NumPy array, you can use rec().
  • Store into the file using soundfile.write().

Implementation:

Step 1:Import modules

import sounddevice as sdimport soundfile as sf

Step 2:Set frequency and duration and record voice data in NumPy array, you can use rec()

fs = 48000duration = 5 myrecording = sd.rec(int(duration * fs), samplerate=fs,                     channels=2)

Note: fs is the sample rate of the recording (usually 44100 or 44800 Hz)

Step 3: Now store these array into audio files.

# Save as FLAC file at correct sampling ratesf.write('My_Audio_file.flac', myrecording, fs)

Let's create a GUI application for the same. We'll be usingTkinter for doing the same.

Python3
importsounddeviceassdimportsoundfileassffromtkinterimport*defVoice_rec():fs=48000# secondsduration=5myrecording=sd.rec(int(duration*fs),samplerate=fs,channels=2)sd.wait()# Save as FLAC file at correct sampling ratereturnsf.write('my_Audio_file.flac',myrecording,fs)master=Tk()Label(master,text=" Voice Recoder : ").grid(row=0,sticky=W,rowspan=5)b=Button(master,text="Start",command=Voice_rec)b.grid(row=0,column=2,columnspan=2,rowspan=2,padx=5,pady=5)mainloop()

Output:


How to Build a Voice Recorder using Python?
Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp