From d5511cbe29b952ee8311ad4b0a473cc2bc581b10 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Mon, 19 Dec 2016 17:32:28 +0100 Subject: Examples: Don't use the logging module, proper exit codes --- examples/spectrogram.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'examples/spectrogram.py') diff --git a/examples/spectrogram.py b/examples/spectrogram.py index 3c378f3..24ac465 100755 --- a/examples/spectrogram.py +++ b/examples/spectrogram.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 """Show a text-mode spectrogram using live microphone data.""" import argparse -import logging import math import numpy as np import shutil @@ -59,7 +58,7 @@ try: if args.list_devices: print(sd.query_devices()) - parser.exit() + parser.exit(0) samplerate = sd.query_devices(args.device, 'input')['default_samplerate'] @@ -67,11 +66,11 @@ try: fftsize = math.ceil(samplerate / delta_f) low_bin = math.floor(low / delta_f) - cumulated_status = sd.CallbackFlags() - def callback(indata, frames, time, status): - global cumulated_status - cumulated_status |= status + if status: + text = ' ' + str(status) + ' ' + print('\x1b[34;40m', text.center(args.columns, '#'), + '\x1b[0m', sep='', flush=True) if any(indata): magnitude = np.abs(np.fft.rfft(indata[:, 0], n=fftsize)) magnitude *= args.gain / fftsize @@ -97,8 +96,6 @@ try: print('\x1b[31;40m', usage_line.center(args.columns, '#'), '\x1b[0m', sep='', flush=True) break - if cumulated_status: - logging.warning(str(cumulated_status)) except KeyboardInterrupt: parser.exit('Interrupted by user') except Exception as e: -- cgit v1.2.3