Python Project:Making a voice recorder with Python














































Python Project:Making a voice recorder with Python



prerequisites: the libraries i need for this small project are tkinter(for making gui app),threading(to use the threading option to access one member function's variable),pyaudio(to access the default microphone and default speakers), wave(for creation and operation of .wav format files)

first lets have a look on the code:

import tkinter as tk import threading import pyaudio import wave class App(): chunk = 1024 sample_format = pyaudio.paInt16 channels = 2 fs = 44100 frames = [] def __init__(self, master): self.isrecording = False self.button1 = tk.Button(main, text='rec',command=self.startrecording) self.button2 = tk.Button(main, text='stop',command=self.stoprecording) self.button1.pack() self.button2.pack() def startrecording(self): self.p = pyaudio.PyAudio() self.stream = self.p.open(format=self.sample_format,channels=self.channels,rate=self.fs,frames_per_buffer=self.chunk,input=True) self.isrecording = True print('Recording') t = threading.Thread(target=self.record) t.start() def stoprecording(self): self.isrecording = False print('recording complete') self.filename=input('the filename?') self.filename = self.filename+".wav" wf = wave.open(self.filename, 'wb') wf.setnchannels(self.channels) wf.setsampwidth(self.p.get_sample_size(self.sample_format)) wf.setframerate(self.fs) wf.writeframes(b''.join(self.frames)) wf.close() main.destroy() def record(self): while self.isrecording: data = self.stream.read(self.chunk) self.frames.append(data) main = tk.Tk() main.title('recorder') main.geometry('200x50') app = App(main) main.mainloop()

to get the understanding of tkinter please go here, i made a gui app to count the number of characters.
another gui project that i made was attendance manager using tkinter ,go here for that.

So lets talk about the recording then
The chunk is like a buffer, so therefore each buffer will contain 1024 samples, which you can then either keep or throw away. We use chunks of data, instead of a continuous amount of audio because of processing power 
Waveform Audio File Format (WAVE, or more commonly known as WAV due to its filename extension; pronounced "wave" is an audio file format standard, developed by Microsoft and IBM, for storing an audio bitstream on PCs. It is an application of the Resource Interchange File Format (RIFF) bitstream format method for storing data in "chunks".
For CD recordings, the industry standard is to store each audio sample as a 16-bit value, at 44100 samples per second.
Sound Channel refers to the independent audio signal which is collected or playback when the sound is recording or playback in different spatial position. Therefore, the number of channel is the amount of sound source when the sound is recording or the relevant speaker number when it is playback.
The pyaudio.Pyaudio helps to create the interface for recording the sound,and creates an object for microphones and speakers. And well the open function opens the required stream for recording.

To execute the application follow the screen shots:

1) first run the script , here name of the python file is recgui.py

2) then press the rec button for recording

3)after recording voice press stop

4)input the file name , hit enter. The application will close automatically.

5)and you will find your recording in the directory where you have kept your recgui.py

More Articles of Kislay Kanti Dhar:

Name Views Likes
Python Boto3:glacier remove tags from vault 178 0
Python Boto3:aws glacier delete vault access policy 153 0
Python Boto3:aws glacier get and set vault access policy 155 0
Python Boto3: aws glacier describe vault 169 0
Python boto3:aws glacier adding tags to vaults and listing them 148 0
Python Boto3 : getting list of Vaults of aws Glacier 203 0
Python boto3 : create aws glacier vault 233 0
configuring boto3 245 1
Rendering Html5 forms and getting forms data with Python Flask 296 0
Python Bisect module:sorting on the go 249 0
Python heapq: The library for implementing heaps and heapsort 191 0
Python DB2 Drop table 303 0
Python DB2 select from table 239 0
Python DB2 multiple insert record into table 276 0
Python Collections : using deque 452 0
Python Project:Making a voice recorder with Python 1697 4
Python DB2 how to get the tuples using ibm_db.fetch_tuple 467 0
Python Collections: understanding the counter 202 0
Python Collections:understanding ChainMap 276 0
Python Enum: exploring the enum datastructure 268 0
DB2: Inserting values into an existing table using Python 899 0
DB2: Creating a table with python code 775 0
DB2 :connecting IBM database server to python 754 0
IBM DB2: an introduction 228 0
Python UDP Client Server program 365 0
Python Socket: basic functions and concepts 256 0
Python TCP Client Server program 539 0
Python Project: Attendance Manager GUI application made with Tkinter 798 1
Python Program to get Google search results 205 0
Python Program for opening google search 189 0
Python program to find out the disk speed 257 0
Python Matplotlib scatter plots 294 1
Python Matplotlib plotting bar graphs 441 0
Python Matplotlib plotting a pie chart 364 0
Python Matplotlib and plotting sin and cos graphs 1326 0
Python Numpy Loading data files and operation 400 0
Python Tkinter making a gui application to count characters of input text 791 1
Python Numpy polynomials operation and implementation in Matplotlib 475 0
Python Numpy Elementwise operations 457 0
Python Numpy Indexing and slicing 299 1
Python Numpy basic visualization using Matplotlib library 418 0
Python Numpy use of ones ,zeros , eye and diag 385 1
Python Numpy use of arange and linspace functions 754 1
Python Numpy understanding the dimension of arrays and shapes using shape and ndim 727 1
Python Numpy creating arrays using array function 286 1
Python Numpy an introduction 348 1
Python Program to Print All Permutations of a String in Lexicographic Order using Recursion 1015 24

Comments

  • Mohammed Maaz
    17-Oct-2020 05:07:59 PM
    I have some issues in implementing this code with some modification. Is there any way you can help me?
    My mail id id mohdmaazshk@gmail.com