Path: blob/master/Audio Analysis in Python.ipynb
133 views
Kernel: Python 3
Table of Contents
Loading an audio file
In [1]:
In [14]:
Playing Audio
Using IPython.display.Audio, to play the audio
In [15]:
Out[15]:
You can even use an mp3 or a WMA format for the audio example.
Visualizing Audio
Waveform
We can plot the audio array using librosa.display.waveplot:
In [45]:
Out[45]:
<matplotlib.collections.PolyCollection at 0x1285c0668>
Here, we have the plot the amplitude envelope of a waveform.
Spectrogram
We can also display a spectrogram using librosa.display.specshow.
In [20]:
Out[20]:
<matplotlib.colorbar.Colorbar at 0x1236f2d30>
Log Frequency axis
In [21]:
Out[21]:
<matplotlib.colorbar.Colorbar at 0x123496208>
Creating an audio signal
Let us now create an audio signal at 220Hz. We know an audio signal is a numpy array, so we shall create one and pass it on to the audio function.
In [22]:
Playing the sound
In [24]:
Out[24]:
Saving the signal
In [67]:
Feature Extraction
In [68]:
Out[68]:
In [69]:
Out[69]:
<matplotlib.collections.PolyCollection at 0x137da34a8>
1. Zero Crossing Rate
In [37]:
Out[37]:
I count 6 zero crossings. Let's compute the zero crossings using librosa.
In [38]:
Out[38]:
(100,)
In [39]:
Out[39]:
6
2.Spectral Centroid
In [43]:
Out[43]:
(775,)
In [46]:
Out[46]:
[<matplotlib.lines.Line2D at 0x12856ca58>]
3.Spectral Rolloff
In [71]:
Out[71]:
4.MFCC
In [57]:
Out[57]:
<matplotlib.collections.PolyCollection at 0x12ed3f358>
In [60]:
Out[60]:
(20, 97)
<matplotlib.axes._subplots.AxesSubplot at 0x135def400>
Feature Scaling
Let's scale the MFCCs such that each coefficient dimension has zero mean and unit variance:
In [61]:
Out[61]:
[ 3.52524424e-16 -5.37943115e-17 4.72130925e-17 4.76136885e-16
-2.40357562e-17 7.43963882e-17 6.81013092e-17 -6.52399097e-17
2.77555756e-17 6.40953499e-17 7.67570429e-17 1.50223476e-16
6.75290293e-17 8.69865463e-17 -8.24083070e-17 -4.74992325e-17
7.35379684e-17 -3.25913409e-16 2.80417156e-17 -4.14330655e-16]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
In [62]:
Out[62]:
<matplotlib.axes._subplots.AxesSubplot at 0x13613b748>
Chroma Frequencies
In [75]:
Out[75]:
In [76]:
Out[76]:
<matplotlib.axes._subplots.AxesSubplot at 0x136d96320>
In [ ]: