Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wave
- import numpy as np
- import scipy
- import matplotlib.pyplot as plt
- wr = wave.open('/home/volta/Dokumenty/predmety/zns/programy/zvuk/youparse/piano/18.wav', 'r')
- sz = 44100 # Read and process 1 second at a time.
- data = np.fromstring(wr.readframes(-1), dtype=np.int16)
- previous = 0
- sample_rate = 22050
- for i in range(1,int(len(data)/sample_rate)):
- print(i)
- plt.figure(1)
- #plt.plot(data[previous:i*sample_rate])
- #plt.show()
- dataFFT = abs(np.fft.rfft(data[previous:i*sample_rate]))
- #b = plt.subplot(212)
- #b.set_xscale('log')
- #plt.plot(dataFFT)
- #plt.show()
- previous += sample_rate
- '''plt.figure(1)
- a = plt.subplot(211)
- #r = 2**16/2
- r = 2**15
- a.set_ylim([-r, r])
- a.set_xlabel('time [s]')
- a.set_ylabel('sample value [-]')
- x = np.arange(44100)/(44100)
- print(len(x))
- print(len(left))
- plt.plot(x, data )
- plt.show()
- b = plt.subplot(212)
- b.set_xscale('log')
- b.set_xlabel('frequency [Hz]')
- b.set_ylabel('|amplitude|')
- plt.plot(FFT)
- plt.show()
- plt.savefig('sample-graph.png')
- '''
Add Comment
Please, Sign In to add comment