I was trying to plot time vs amplitude for all the channels of a wav file, using the code below. However I see that the matplotlib is plotting a non-existent sine wav on one of my channels. Audacity seems to be plotting the right thing, what am I missing?
import wave
import numpy as np
import matplotlib.pyplot as plt
f = wave.open('captured_Mic1_22_09_20_1738.wav')
sampleRate = f.getframerate()
totalFrames = f.getnframes()
print(f.getnchannels())
data = f.readframes(-1) # -1 is read all frames, can also use totalFrames
# print(data) # Data in Hex
dataInt = np.frombuffer(data, np.int16)
print("All Samples -> {}".format(dataInt))
dataInt.shape = -1,2
print("L and R in 2 columns \n {}" .format(dataInt))
dataInt = dataInt.T
print("L and R in two separate rows \n {}" .format(dataInt))
print("total duration of file -> {}" .format(totalFrames/float(sampleRate)))
duration = 1/float(sampleRate)
print(duration)
timeSeq = np.arange(0, totalFrames/float(sampleRate), duration)
# plt.plot(timeSeq, dataInt[0])
# plt.show()
plt.plot(timeSeq, dataInt[1])
plt.show()
I printed the entire contents of the
dataInt
buffer to see if there's actually any data using the 2 lines below.The amplitude is very small and hence looked like there was no data on audacity. Here's a screenshot with a lot of zoom on audacity.