Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mic_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def open_mic():
outputs: int16 data array
"""
def get_data(stream,pa):
input_data = stream.read(CHUNK_SIZE)
input_data = stream.read(CHUNK_SIZE, exception_on_overflow=False)
data = np.fromstring(input_data,np.int16)
return data

Expand Down
22 changes: 11 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
funcsigs==0.4
matplotlib==1.4.3
mock==1.3.0
nose==1.3.7
numpy==1.9.2
pbr==1.4.0
PyAudio==0.2.8
pyparsing==2.0.3
python-dateutil==2.4.2
pytz==2015.4
six==1.9.0
funcsigs>=0.4
matplotlib>=1.4.3
mock>=1.3.0
nose>=1.3.7
numpy>=1.9.2
pbr>=1.4.0
PyAudio>=0.2.8
pyparsing>=2.0.3
python-dateutil>=2.4.2
pytz>=2015.4
six>=1.9.0
13 changes: 7 additions & 6 deletions run_specgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
inputs: audio stream and PyAudio object
outputs: int16 array
"""
def get_sample(stream,pa):
def get_sample(stream, pa):
data = mic_read.get_data(stream,pa)
return data
"""
Expand All @@ -54,8 +54,8 @@ def get_specgram(signal,rate):
inputs: iteration number
outputs: updated image
"""
def update_fig(n):
data = get_sample(stream,pa)
def update_fig(n, stream, pa, im):
data = get_sample(stream, pa)
arr2D,freqs,bins = get_specgram(data,rate)
im_data = im.get_array()
if n < SAMPLES_PER_FRAME:
Expand All @@ -74,8 +74,8 @@ def main():
"""
Launch the stream and the original spectrogram
"""
stream,pa = mic_read.open_mic()
data = get_sample(stream,pa)
stream, pa = mic_read.open_mic()
data = get_sample(stream, pa)
arr2D,freqs,bins = get_specgram(data,rate)
"""
Setup the plot paramters
Expand All @@ -90,7 +90,8 @@ def main():
##plt.colorbar() #enable if you want to display a color bar

############### Animate ###############
anim = animation.FuncAnimation(fig,update_fig,blit = False,
upd_fig = lambda n: update_fig(n, stream=stream, pa=pa, im=im)
anim = animation.FuncAnimation(fig,upd_fig,blit = False,
interval=mic_read.CHUNK_SIZE/1000)


Expand Down