summaryrefslogtreecommitdiff
path: root/examples/plot_input.py
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2019-09-17 20:12:20 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2019-09-18 13:10:33 +0200
commita82b9b56d44ed37c587648685826ad56b9177533 (patch)
treebd72d8becf6caaf2079cd4f31db42db4f7cba289 /examples/plot_input.py
parente8253a615d6f70f7a1f6bc662e703a857fd2e8c4 (diff)
DOC: Update examples
Diffstat (limited to 'examples/plot_input.py')
-rwxr-xr-xexamples/plot_input.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/examples/plot_input.py b/examples/plot_input.py
index ad12a9c..cf325d6 100755
--- a/examples/plot_input.py
+++ b/examples/plot_input.py
@@ -8,6 +8,11 @@ import argparse
import queue
import sys
+from matplotlib.animation import FuncAnimation
+import matplotlib.pyplot as plt
+import numpy as np
+import sounddevice as sd
+
def int_or_str(text):
"""Helper function for argument parsing."""
@@ -17,10 +22,21 @@ def int_or_str(text):
return text
-parser = argparse.ArgumentParser(description=__doc__)
+parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
'-l', '--list-devices', action='store_true',
help='show list of audio devices and exit')
+args, remaining = parser.parse_known_args()
+if args.list_devices:
+ print(sd.query_devices())
+ parser.exit(0)
+parser = argparse.ArgumentParser(
+ description=__doc__,
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ parents=[parser])
+parser.add_argument(
+ 'channels', type=int, default=[1], nargs='*', metavar='CHANNEL',
+ help='input channels to plot (default: the first)')
parser.add_argument(
'-d', '--device', type=int_or_str,
help='input device (numeric ID or substring)')
@@ -37,10 +53,7 @@ parser.add_argument(
parser.add_argument(
'-n', '--downsample', type=int, default=10, metavar='N',
help='display every Nth sample (default: %(default)s)')
-parser.add_argument(
- 'channels', type=int, default=[1], nargs='*', metavar='CHANNEL',
- help='input channels to plot (default: the first)')
-args = parser.parse_args()
+args = parser.parse_args(remaining)
if any(c < 1 for c in args.channels):
parser.error('argument CHANNEL: must be >= 1')
mapping = [c - 1 for c in args.channels] # Channel numbers start with 1
@@ -77,14 +90,6 @@ def update_plot(frame):
try:
- from matplotlib.animation import FuncAnimation
- import matplotlib.pyplot as plt
- import numpy as np
- import sounddevice as sd
-
- if args.list_devices:
- print(sd.query_devices())
- parser.exit(0)
if args.samplerate is None:
device_info = sd.query_devices(args.device, 'input')
args.samplerate = device_info['default_samplerate']