Miscellaneous

sleep Put the caller to sleep for at least msec milliseconds.
get_portaudio_version Get version information for the PortAudio library.
CallbackFlags Flag bits for the status argument to a stream callback.
CallbackStop Exception to be raised by the user to stop callback processing.
CallbackAbort Exception to be raised by the user to abort callback processing.
PortAudioError This exception will be raised on PortAudio errors.
sounddevice.sleep(msec)[source]

Put the caller to sleep for at least msec milliseconds.

The function may sleep longer than requested so don’t rely on this for accurate musical timing.

sounddevice.get_portaudio_version()[source]

Get version information for the PortAudio library.

Returns the release number and a textual description of the current PortAudio build, e.g.

(1899, 'PortAudio V19-devel (built Feb 15 2014 23:28:00)')
class sounddevice.CallbackFlags(flags=0)[source]

Flag bits for the status argument to a stream callback.

If you experience under-/overflows, you can try to increase the latency and/or blocksize settings. You should also avoid anything that could block the callback function for a long time, e.g. extensive computations, waiting for another thread, reading/writing files, network connections, etc.

See also

Stream

Examples

This can be used to collect the errors of multiple status objects:

>>> import sounddevice as sd
>>> errors = sd.CallbackFlags()
>>> errors |= status1
>>> errors |= status2
>>> errors |= status3
>>> # and so on ...
>>> errors.input_overflow
True
input_underflow

Input underflow.

In a stream opened with blocksize=0, indicates that input data is all silence (zeros) because no real data is available. In a stream opened with a non-zero blocksize, it indicates that one or more zero samples have been inserted into the input buffer to compensate for an input underflow.

This can only happen in full-duplex streams (including playrec()).

input_overflow

Input overflow.

In a stream opened with blocksize=0, indicates that data prior to the first sample of the input buffer was discarded due to an overflow, possibly because the stream callback is using too much CPU time. In a stream opened with a non-zero blocksize, it indicates that data prior to one or more samples in the input buffer was discarded.

This can happen in full-duplex and input-only streams (including playrec() and rec()).

output_underflow

Output underflow.

Indicates that output data (or a gap) was inserted, possibly because the stream callback is using too much CPU time.

This can happen in full-duplex and output-only streams (including playrec() and play()).

output_overflow

Output overflow.

Indicates that output data will be discarded because no room is available.

This can only happen in full-duplex streams (including playrec()), but only when never_drop_input=True was specified. See default.never_drop_input.

priming_output

Priming output.

Some of all of the output data will be used to prime the stream, input data may be zero.

This will only take place with some of the host APIs, and only if prime_output_buffers_using_stream_callback=True was specified. See default.prime_output_buffers_using_stream_callback.

class sounddevice.CallbackStop[source]

Exception to be raised by the user to stop callback processing.

If this is raised in the stream callback, the callback will not be invoked anymore (but all pending audio buffers will be played).

class sounddevice.CallbackAbort[source]

Exception to be raised by the user to abort callback processing.

If this is raised in the stream callback, all pending buffers are discarded and the callback will not be invoked anymore.

class sounddevice.PortAudioError[source]

This exception will be raised on PortAudio errors.

args

A variable length tuple containing the following elements when available:

  1. A string describing the error
  2. The PortAudio PaErrorCode value
  3. A 3-tuple containing the host API index, host error code, and the host error message (which may be an empty string)