summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2015-06-22 11:22:04 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2015-06-22 11:22:04 +0200
commitacabf69c944298fddd3e8bdbe64922db5e9a7ad8 (patch)
tree617fc7b69e7a4ea5d0f3426b0496a11b9840a9d5
parent45169f8dbdb508018402fb7c5ce0001ee87a25e8 (diff)
play_file example: make exception handling more idiomatic
-rwxr-xr-xexamples/play_file.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/examples/play_file.py b/examples/play_file.py
index ef530cb..7161ceb 100755
--- a/examples/play_file.py
+++ b/examples/play_file.py
@@ -5,9 +5,6 @@ PySoundFile (https://github.com/bastibe/PySoundFile/) has to be installed!
"""
import argparse
-import sounddevice as sd
-import soundfile as sf
-import sys
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("filename", help="audio file to be played back")
@@ -15,8 +12,10 @@ parser.add_argument("-d", "--device", type=int, help="device ID")
args = parser.parse_args()
try:
+ import sounddevice as sd
+ import soundfile as sf
data, fs = sf.read(args.filename, dtype='float32')
sd.play(data, fs, device=args.device, blocking=True)
-except:
+except BaseException as e:
# This avoids printing the traceback, especially if Ctrl-C is used.
- sys.exit(sys.exc_info()[1])
+ raise SystemExit(str(e))