summaryrefslogtreecommitdiff
path: root/examples/play_file.py
diff options
context:
space:
mode:
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: