In [64]:
import aifc
import wave

In [144]:
file_contents = []
audioFile = wave.open("/Users/raymondklass/Desktop/A_reference_note_n2.wav", "rb")
print(audioFile.getsampwidth())
print(audioFile.getnframes())
print(audioFile.getnchannels())

# Sample Rate: 44100

import numpy as np

nframes = audioFile.getnframes()
strsig = audioFile.readframes(nframes)

print "Frame Rate: {}".format(audioFile.getframerate())
y = np.fromstring(strsig, np.short).byteswap()

print "y shape: {}".format(y.shape)


2
130939
1
Frame Rate: 44100
y shape: (130939,)

In [148]:
import numpy as np
import scipy
import matplotlib.pyplot as plt
import math

samples_x = [(x / 44100.0) for x in range(150)]
plt.plot(samples_x, y[100:250])
plt.show()



In [146]:
from scipy.fftpack import fft
# Number of sample points
N = 1000
start = 100
# sample spacing
T = 1.0 / 44100.0
x = np.linspace(0.0, N*T, N)
#y = np.sin(440.0 * 2.0*np.pi*x)
y = y[100:1100]
yf = fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N//2)
import matplotlib.pyplot as plt
plt.plot(xf, 2.0/N * np.abs(yf[0:N//2]))
plt.grid()
plt.show()

print(yf.argmax())


0

In [ ]:


In [ ]: