Miscellaneous§

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

The values may also be set and cleared by the user:

>>> import sounddevice as sd
>>> cf = sd.CallbackFlags()
>>> cf
<sounddevice.CallbackFlags: no flags set>
>>> cf.input_underflow = True
>>> cf
<sounddevice.CallbackFlags: input underflow>
>>> cf.input_underflow = False
>>> cf
<sounddevice.CallbackFlags: no flags set>
property 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()).

property 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()).

property 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()).

property 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.

property 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.

exception 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).

exception 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.

exception 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)