Sound processing python project

Published on . Written by

Sound processing python project

Sound is nothing but a vibration in a medium that is propagating in a form of wave. We all know this very obvious definition of sound, right? We know music applications and software which visualize the music or audio or sound and display it on the screens in real-time which is wow! The basic need for visualizing the audio is for analyzing purposes. I know it is too fascinating to look at what audio looks like. 


Skyfi Labs Projects
As fascinating it is to look at the visualization, believe me, it is even more fascinating to code a program to visualize audio. Python has made our lives easier by reducing coding efforts with libraries such as NumPy, Pandas, and also Sci-Py. Hence, visualizing audio is not much a task for a regular coder who has some knowledge about python and its libraries. 

Read more..

SLNOTE
Given below are some easy steps to guide you through the project to visualize a live stream of audio through a microphone. We will display the real-time audio by matplotlib. 

Knowledge required: Python and its libraries, and Fourier transform (for those who are planning to build audio spectrum)

Tools needed: An IDE (suggested: Anaconda)


SLLATEST
Libraries imported: PyAudio, Struct, Numpy, and matplotlib.

  1. Start by installing PyAudio and import the libraries mentioned above.
  2. You must know that we have imported the struct library to unpack our audio data into integers instead of binary numbers.
  3. Next, you will have to create and set some audio variables which will be later used to plot the graph.
  4. Create a new variable to mention in count how many audio samples per frame will be displayed in real-time.
  5. Create another variable for channels and set it to one. And then another variable for the rate which will be the count of samples per second.
  6. Create an instance of PyAudio, this will be our main object and this will set up the portaudio system.
  7. Now use, stream the audio, and read the file.
  8. Run the program and you will see some complicated bytes displayed on your screen.
To prevent this convert these bytes into integers using unpack(). Now, you are expected to get a tuple of integers.

  1. Plot a graph of these integers using the. plot() function and pass the respective arguments. The graph will not give you a very perfect visual of the audio data in one go. You will have to manipulate it several times to get these desired waveforms. Try manipulating it by using array from NumPy and slice the array in such a way if every sample is moving down to 0 then after slicing take every other point in the array and throw the rest. 
  2. Now to display the continuous waveform of the audio data in matplotlib plot, create a line. Update the line using a loop. Create a variable that will be used for plotting and also create a line object and code in a way that you obtain the continuous wave. 
The waveform you will obtain will be fascinating but to obtain clear peaks of the audio tones passed you can create an audio spectrum. For that, you can use the Py’s FFT algorithm and for more details visit SciPy’s FFT pack documentation available on the web.


SLDYK
Kit required to develop Sound processing python project:
Technologies you will learn by working on Sound processing python project:


Any Questions?


Subscribe for more project ideas