From 4d524714a9bc0eef8fa880bc58594bd5792cd6dc Mon Sep 17 00:00:00 2001 From: "David A. Riggs" Date: Thu, 26 Jan 2017 11:21:00 -0800 Subject: Add get_stream() function for accessing the current stream (#70) --- sounddevice.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sounddevice.py b/sounddevice.py index bc5aaa0..50bbb81 100644 --- a/sounddevice.py +++ b/sounddevice.py @@ -587,6 +587,26 @@ def get_status(): raise RuntimeError('play()/rec()/playrec() was not called yet') +def get_stream(): + """Get a reference to the current stream. + + This applies only to streams created by calls to `play()`, `rec()`, + or `playrec()`. + + Returns + ------- + Stream + An `OutputStream`, `InputStream`, or `Stream` associated with + the last invocation of `play()`, `rec()` or `playrec()` + respectively. + + """ + if _last_callback: + return _last_callback.stream + else: + raise RuntimeError('play()/rec()/playrec() was not called yet') + + def query_devices(device=None, kind=None): """Return information about available devices. -- cgit v1.2.3