I've used the PyAudio default recording example, and added numpy and scipy.
I can only use scipy.io.wavefile.read('FILE.wav')
, after recording the file, however, and it also gives me this random tuple, eg:
(44100, array([[ 0, 0],
[-2, 0],
[ 0, -2],
...,
[-2, -2],
[ 1, 3],
[ 2, -1]], dtype=int16))
.
What does this array give me and do you know how else you can get the frequency/amplitude of each frame of a wav file, preferably while recording?
Asked
Active
Viewed 1.1k times
6

jewz
- 71
- 1
- 1
- 3
1 Answers
12
The array is not random data, it's the wave data of your stereo sound, and 44100 is the sampling rate. use the following code to plot the wave of left channel:
import scipy.io.wavfile as wavfile
import numpy as np
import pylab as pl
rate, data = wavfile.read('FILE.wav')
t = np.arange(len(data[:,0]))*1.0/rate
pl.plot(t, data[:,0])
pl.show()
To get the frequency and amplitude of you wave, do FFT. Following code plot the power of every frequency bin:
p = 20*np.log10(np.abs(np.fft.rfft(data[:2048, 0])))
f = np.linspace(0, rate/2.0, len(p))
pl.plot(f, p)
pl.xlabel("Frequency(Hz)")
pl.ylabel("Power(dB)")
pl.show()

HYRY
- 94,853
- 25
- 187
- 187
-
1OMG, this is beautiful. – yPhil Aug 05 '13 at 13:59
-
What could mean this error with certain wav files : IndexError: too many indices for array ?? – Raul H Feb 18 '18 at 20:51