summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2015-07-06 11:23:46 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2015-07-21 15:40:11 +0200
commit65ddfbeaed7157d86993be60dda3163b17f22fc0 (patch)
treed6e810bf1329b8b61d4d8c6c61066320cc602e7a /examples
parentfb8ca298c1f511e3308777fae358bd44ca3dd9dc (diff)
Add "wire" example
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/wire.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/wire.py b/examples/wire.py
new file mode 100755
index 0000000..3c4edcb
--- /dev/null
+++ b/examples/wire.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+"""Pass input directly to output.
+
+See https://www.assembla.com/spaces/portaudio/subversion/source/HEAD/portaudio/trunk/test/patest_wire.c
+
+"""
+import argparse
+
+parser = argparse.ArgumentParser(description=__doc__)
+parser.add_argument("-i", "--input-device", type=int, help="input device ID")
+parser.add_argument("-o", "--output-device", type=int, help="output device ID")
+parser.add_argument("-c", "--channels", type=int, default=2,
+ help="number of channels")
+parser.add_argument("-t", "--dtype", help="audio data type")
+parser.add_argument("-s", "--samplerate", type=float, help="sampling rate")
+parser.add_argument("-b", "--blocksize", type=int, help="block size")
+parser.add_argument("-l", "--latency", type=float, help="latency in seconds")
+args = parser.parse_args()
+
+try:
+ import sounddevice as sd
+
+ callback_status = sd.CallbackFlags()
+
+ def callback(indata, outdata, frames, time, status):
+ global callback_status
+ callback_status |= status
+ outdata[:] = indata
+
+ with sd.Stream(device=(args.input_device, args.output_device),
+ samplerate=args.samplerate, blocksize=args.blocksize,
+ dtype=args.dtype, latency=args.latency,
+ channels=args.channels, callback=callback):
+ print("#" * 80)
+ print("press Return to quit")
+ print("#" * 80)
+ input()
+
+ if callback_status:
+ print(callback_status)
+except BaseException as e:
+ # This avoids printing the traceback, especially if Ctrl-C is used.
+ raise SystemExit(str(e))