|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Pass input directly to output. |
| 3 | +
|
| 4 | +See https://www.assembla.com/spaces/portaudio/subversion/source/HEAD/portaudio/trunk/test/patest_wire.c |
| 5 | +
|
| 6 | +""" |
| 7 | +import argparse |
| 8 | + |
| 9 | +parser = argparse.ArgumentParser(description=__doc__) |
| 10 | +parser.add_argument("-i", "--input-device", type=int, help="input device ID") |
| 11 | +parser.add_argument("-o", "--output-device", type=int, help="output device ID") |
| 12 | +parser.add_argument("-c", "--channels", type=int, default=2, |
| 13 | + help="number of channels") |
| 14 | +parser.add_argument("-t", "--dtype", help="audio data type") |
| 15 | +parser.add_argument("-s", "--samplerate", type=float, help="sampling rate") |
| 16 | +parser.add_argument("-b", "--blocksize", type=int, help="block size") |
| 17 | +parser.add_argument("-l", "--latency", type=float, help="latency in seconds") |
| 18 | +args = parser.parse_args() |
| 19 | + |
| 20 | +try: |
| 21 | + import sounddevice as sd |
| 22 | + |
| 23 | + callback_status = sd.CallbackFlags() |
| 24 | + |
| 25 | + def callback(indata, outdata, frames, time, status): |
| 26 | + global callback_status |
| 27 | + callback_status |= status |
| 28 | + outdata[:] = indata |
| 29 | + |
| 30 | + with sd.Stream(device=(args.input_device, args.output_device), |
| 31 | + samplerate=args.samplerate, blocksize=args.blocksize, |
| 32 | + dtype=args.dtype, latency=args.latency, |
| 33 | + channels=args.channels, callback=callback): |
| 34 | + print("#" * 80) |
| 35 | + print("press Return to quit") |
| 36 | + print("#" * 80) |
| 37 | + input() |
| 38 | + |
| 39 | + if callback_status: |
| 40 | + print(callback_status) |
| 41 | +except BaseException as e: |
| 42 | + # This avoids printing the traceback, especially if Ctrl-C is used. |
| 43 | + raise SystemExit(str(e)) |
0 commit comments