diff options
| author | Matthias Geier <Matthias.Geier@gmail.com> | 2016-12-19 17:32:28 +0100 |
|---|---|---|
| committer | Matthias Geier <Matthias.Geier@gmail.com> | 2016-12-19 17:33:12 +0100 |
| commit | d5511cbe29b952ee8311ad4b0a473cc2bc581b10 (patch) | |
| tree | 07605bc574932967f2fa09cec1e88f765f3b2cdd /examples/spectrogram.py | |
| parent | b728182025874ba4293a7a4405fd61a3fdaa4da2 (diff) | |
Examples: Don't use the logging module, proper exit codes
Diffstat (limited to 'examples/spectrogram.py')
| -rwxr-xr-x | examples/spectrogram.py | 13 |
1 files changed, 5 insertions, 8 deletions
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: |
