Module-wide Default Settings§

default

Get/set defaults for the sounddevice module.

class sounddevice.default[source]§

Get/set defaults for the sounddevice module.

The attributes device, channels, dtype, latency and extra_settings accept single values which specify the given property for both input and output. However, if the property differs between input and output, pairs of values can be used, where the first value specifies the input and the second value specifies the output. All other attributes are always single values.

Examples

>>> import sounddevice as sd
>>> sd.default.samplerate = 48000
>>> sd.default.dtype
['float32', 'float32']

Different values for input and output:

>>> sd.default.channels = 1, 2

A single value sets both input and output at the same time:

>>> sd.default.device = 5
>>> sd.default.device
[5, 5]

An attribute can be set to the “factory default” by assigning None:

>>> sd.default.samplerate = None
>>> sd.default.device = None, 4

Use reset() to reset all attributes:

>>> sd.default.reset()
device = (None, None)§

Index or query string of default input/output device.

If not overwritten, this is queried from PortAudio.

If a string is given, the device is selected which contains all space-separated parts in the right order. Each device string contains the name of the corresponding host API in the end. The string comparison is case-insensitive.

See also

query_devices()

channels = (None, None)§

Number of input/output channels.

The maximum number of channels for a given device can be found out with query_devices().

dtype = ('float32', 'float32')§

Data type used for input/output samples.

The types 'float32', 'int32', 'int16', 'int8' and 'uint8' can be used for all streams and functions. Additionally, play(), rec() and playrec() support 'float64' (for convenience, data is merely converted from/to 'float32') and RawInputStream, RawOutputStream and RawStream support 'int24' (packed 24 bit format, which is not supported in NumPy!).

If NumPy is available, the corresponding numpy.dtype objects can be used as well.

The floating point representations 'float32' and 'float64' use +1.0 and -1.0 as the maximum and minimum values, respectively. 'uint8' is an unsigned 8 bit format where 128 is considered “ground”.

latency = ('high', 'high')§

Suggested input/output latency in seconds.

The special values 'low' and 'high' can be used to select the default low/high latency of the chosen device. 'high' is typically more robust (i.e. buffer under-/overflows are less likely), but the latency may be too large for interactive applications.

See also

query_devices()

extra_settings = (None, None)§

Host-API-specific input/output settings.

samplerate = None§

Sampling frequency in Hertz (= frames per second).

See also

query_devices()

blocksize = 0§

See the blocksize argument of Stream.

clip_off = False§

Disable clipping.

Set to True to disable default clipping of out of range samples.

dither_off = False§

Disable dithering.

Set to True to disable default dithering.

never_drop_input = False§

Set behavior for input overflow of full-duplex streams.

Set to True to request that where possible a full duplex stream will not discard overflowed input samples without calling the stream callback. This flag is only valid for full-duplex callback streams (i.e. only Stream and RawStream and only if callback was specified; this includes playrec()) and only when used in combination with blocksize=0 (the default). Using this flag incorrectly results in an error being raised. See also http://www.portaudio.com/docs/proposals/001-UnderflowOverflowHandling.html.

prime_output_buffers_using_stream_callback = False§

How to fill initial output buffers.

Set to True to call the stream callback to fill initial output buffers, rather than the default behavior of priming the buffers with zeros (silence). This flag has no effect for input-only (InputStream and RawInputStream) and blocking read/write streams (i.e. if callback wasn’t specified). See also http://www.portaudio.com/docs/proposals/020-AllowCallbackToPrimeStream.html.

property hostapi§

Index of the default host API (read-only).

reset()[source]§

Reset all attributes to their “factory default”.