Learn Before
Concept

Basics of Audio Editing using SciPy File I/O

When thinking of WAV files, you can imagine them to be a long list of sound wave amplitude measurements. The length of this list correlates with the sample rate (samples/sec) and then the file length (sec). So, a 2 second WAV file that contains data sampled at 44,100 samples/sec has 88,400 amplitude measurements stored in a list.

The SciPy library allows us to easily access this data by using the scipy.io package. To start, let's just try to see the audio data using SciPy.

import scipy.io.wavefile as spw ##I now will use my read function to open chicken.wav sample=spw.read('chicken.wav') print(sample)

This should print the following to the console:

(44100, array([ 54, 66, 70, ..., -34, -31, -28], dtype=int16))

As you can see, the read function returns the sample rate, the data as an array, and labels the data type. Thus, we have a WAV file sampled at 44,100 samples/sec, represented as an array containing integers.

What if we just wanted to grab the data in the array? It looks like the variable sample is a tuple containing the list we want as the second element. Thus, we can use indexing.

print(sample[1][0])

This should print the following to the console:

54

Now that we have established how SciPy allows us to make WAV file data explicit, we can explore ways to manipulate this data.

0

1

Updated 2021-07-06

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science