As we saw in Chapter 2, Advanced Indexing and Array Concepts, we can do neat things with WAV files. It's just a matter of downloading the file with the urllib2
standard Python module and loading it with SciPy. Let's download a WAV file and repeat it three times. We will skip some of the steps that we've already seen in Chapter 2, Advanced Indexing and Array Concepts.
Although NumPy has a
repeat()
function, in this case, it is more appropriate to use thetile()
function. Therepeat()
function would have the effect of enlarging the array by repeating individual elements and not repeating the contents of it. The following IPython session should clarify the difference between these functions:In: x = array([1, 2]) In: x Out: array([1, 2]) In: repeat(x, 3) Out: array([1, 1, 1, 2, 2, 2]) In: tile(x, 3) Out: array([1, 2, 1, 2, 1, 2])
Now, armed with this knowledge, apply the
tile()
function:repeated = np.tile(data, 3)
Plot the audio data with matplotlib...