diff options
| author | Matthias Geier <Matthias.Geier@gmail.com> | 2015-06-20 21:01:25 +0200 |
|---|---|---|
| committer | Matthias Geier <Matthias.Geier@gmail.com> | 2015-06-20 21:01:25 +0200 |
| commit | eb399e6ce6170325dc0d97fddadf53aba7053f7a (patch) | |
| tree | 726cbc04a68ddcaad034ea16910e6a2657543c8e /examples/play_file.py | |
Initial commit0.1.0
Diffstat (limited to 'examples/play_file.py')
| -rwxr-xr-x | examples/play_file.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/play_file.py b/examples/play_file.py new file mode 100755 index 0000000..ef530cb --- /dev/null +++ b/examples/play_file.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +"""Load an audio file and play its contents. + +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") +parser.add_argument("-d", "--device", type=int, help="device ID") +args = parser.parse_args() + +try: + data, fs = sf.read(args.filename, dtype='float32') + sd.play(data, fs, device=args.device, blocking=True) +except: + # This avoids printing the traceback, especially if Ctrl-C is used. + sys.exit(sys.exc_info()[1]) |
