11#!/usr/bin/env python3
2- """Plot the live microphone signal(s) with matplotlib."""
2+ """Plot the live microphone signal(s) with matplotlib.
3+
4+ Matplotlib and NumPy have to be installed.
5+
6+ """
37import argparse
4- from queue import Queue , Empty
8+ import queue
9+ import sys
510
611
712def int_or_str (text ):
@@ -39,15 +44,15 @@ def int_or_str(text):
3944if any (c < 1 for c in args .channels ):
4045 parser .error ('argument CHANNEL: must be >= 1' )
4146mapping = [c - 1 for c in args .channels ] # Channel numbers start with 1
42- queue = Queue ()
47+ q = queue . Queue ()
4348
4449
4550def audio_callback (indata , frames , time , status ):
4651 """This is called (from a separate thread) for each audio block."""
4752 if status :
48- print (status , flush = True )
53+ print (status , file = sys . stderr )
4954 # Fancy indexing with mapping creates a (necessary!) copy:
50- queue .put (indata [::args .downsample , mapping ])
55+ q .put (indata [::args .downsample , mapping ])
5156
5257
5358def update_plot (frame ):
@@ -61,8 +66,8 @@ def update_plot(frame):
6166 block = True # The first read from the queue is blocking ...
6267 while True :
6368 try :
64- data = queue .get (block = block )
65- except Empty :
69+ data = q .get (block = block )
70+ except queue . Empty :
6671 break
6772 shift = len (data )
6873 plotdata = np .roll (plotdata , - shift , axis = 0 )
@@ -81,7 +86,7 @@ def update_plot(frame):
8186
8287 if args .list_devices :
8388 print (sd .query_devices ())
84- parser .exit ()
89+ parser .exit (0 )
8590 if args .samplerate is None :
8691 device_info = sd .query_devices (args .device , 'input' )
8792 args .samplerate = device_info ['default_samplerate' ]
0 commit comments