summaryrefslogtreecommitdiff
path: root/examples/spectrogram.py
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2016-08-05 09:40:51 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2016-08-05 09:40:51 +0200
commit5408733e7f7b3ed1f350bbae8d74e758a00f0be7 (patch)
treebdac9db11b3e428a521342666ede37c087f2fc38 /examples/spectrogram.py
parent104d912af4bd54bc34521c43ab53332e933425a0 (diff)
Accept device substrings in all examples
Diffstat (limited to 'examples/spectrogram.py')
-rwxr-xr-xexamples/spectrogram.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/examples/spectrogram.py b/examples/spectrogram.py
index c952b95..d0d5026 100755
--- a/examples/spectrogram.py
+++ b/examples/spectrogram.py
@@ -7,6 +7,14 @@ import shutil
usage_line = ' press <enter> to quit, +<enter> or -<enter> to change scaling '
+
+def int_or_str(text):
+ """Helper function for argument parsing."""
+ try:
+ return int(text)
+ except ValueError:
+ return text
+
try:
columns, _ = shutil.get_terminal_size()
except AttributeError:
@@ -20,7 +28,8 @@ parser.add_argument('-b', '--block-duration', type=float,
help='block size (default %(default)s milliseconds)')
parser.add_argument('-c', '--columns', type=int, default=columns,
help='width of spectrogram')
-parser.add_argument('-d', '--device', type=int, help='input device ID')
+parser.add_argument('-d', '--device', type=int_or_str,
+ help='input device (numeric ID or substring)')
parser.add_argument('-g', '--gain', type=float, default=10,
help='initial gain factor (default %(default)s)')
parser.add_argument('-r', '--range', type=float, nargs=2,
@@ -30,7 +39,7 @@ args = parser.parse_args()
low, high = args.range
if high <= low:
- parser.error("HIGH must be greater than LOW")
+ parser.error('HIGH must be greater than LOW')
# Create a nice output gradient using ANSI escape sequences.
# Stolen from https://gist.github.com/maurisvh/df919538bcef391bc89f