summaryrefslogtreecommitdiff
path: root/examples/play_file.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/play_file.py
parent104d912af4bd54bc34521c43ab53332e933425a0 (diff)
Accept device substrings in all examples
Diffstat (limited to 'examples/play_file.py')
-rwxr-xr-xexamples/play_file.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/examples/play_file.py b/examples/play_file.py
index 402d814..29a594c 100755
--- a/examples/play_file.py
+++ b/examples/play_file.py
@@ -7,9 +7,18 @@ PySoundFile (https://github.com/bastibe/PySoundFile/) has to be installed!
import argparse
import logging
+
+def int_or_str(text):
+ """Helper function for argument parsing."""
+ try:
+ return int(text)
+ except ValueError:
+ return text
+
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("filename", help="audio file to be played back")
-parser.add_argument("-d", "--device", type=int, help="device ID")
+parser.add_argument('-d', '--device', type=int_or_str,
+ help='output device (numeric ID or substring)')
args = parser.parse_args()
try: