Raw Streams§

class sounddevice.RawStream(samplerate=None, blocksize=None, device=None, channels=None, dtype=None, latency=None, extra_settings=None, callback=None, finished_callback=None, clip_off=None, dither_off=None, never_drop_input=None, prime_output_buffers_using_stream_callback=None)[source]§

PortAudio input/output stream (using buffer objects).

This is the same as Stream, except that the callback function and read()/write() work on plain Python buffer objects instead of on NumPy arrays. NumPy is not necessary for using this.

To open a “raw” input-only or output-only stream use RawInputStream or RawOutputStream, respectively. If you want to handle audio data as NumPy arrays instead of buffer objects, use Stream, InputStream or OutputStream.

Parameters:
  • dtype (str or pair of str) – The sample format of the buffers provided to the stream callback, read() or write(). In addition to the formats supported by Stream ('float32', 'int32', 'int16', 'int8', 'uint8'), this also supports 'int24', i.e. packed 24 bit format. The default value can be changed with default.dtype. See also samplesize.

  • callback (callable) – User-supplied function to consume, process or generate audio data in response to requests from an active stream. The callback must have this signature:

    callback(indata: buffer, outdata: buffer, frames: int,
             time: CData, status: CallbackFlags) -> None
    

    The arguments are the same as in the callback parameter of Stream, except that indata and outdata are plain Python buffer objects instead of NumPy arrays.

read(frames)§

Read samples from the stream into a buffer.

This is the same as Stream.read(), except that it returns a plain Python buffer object instead of a NumPy array. NumPy is not necessary for using this.

Parameters:

frames (int) – The number of frames to be read. See Stream.read().

Returns:

  • data (buffer) – A buffer of interleaved samples. The buffer contains samples in the format specified by the dtype parameter used to open the stream, and the number of channels specified by channels. See also samplesize.

  • overflowed (bool) – See Stream.read().

write(data)§

Write samples to the stream.

This is the same as Stream.write(), except that it expects a plain Python buffer object instead of a NumPy array. NumPy is not necessary for using this.

Parameters:

data (buffer or bytes or iterable of int) – A buffer of interleaved samples. The buffer contains samples in the format specified by the dtype argument used to open the stream, and the number of channels specified by channels. The length of the buffer is not constrained to a specific range, however high performance applications will want to match this parameter to the blocksize parameter used when opening the stream. See also samplesize.

Returns:

underflowed (bool) – See Stream.write().

class sounddevice.RawInputStream(samplerate=None, blocksize=None, device=None, channels=None, dtype=None, latency=None, extra_settings=None, callback=None, finished_callback=None, clip_off=None, dither_off=None, never_drop_input=None, prime_output_buffers_using_stream_callback=None)[source]§

PortAudio input stream (using buffer objects).

This is the same as InputStream, except that the callback function and read() work on plain Python buffer objects instead of on NumPy arrays. NumPy is not necessary for using this.

Parameters:
  • dtype (str) – See RawStream.

  • callback (callable) – User-supplied function to consume audio data in response to requests from an active stream. The callback must have this signature:

    callback(indata: buffer, frames: int,
             time: CData, status: CallbackFlags) -> None
    

    The arguments are the same as in the callback parameter of RawStream, except that outdata is missing.

See also

RawStream, Stream

class sounddevice.RawOutputStream(samplerate=None, blocksize=None, device=None, channels=None, dtype=None, latency=None, extra_settings=None, callback=None, finished_callback=None, clip_off=None, dither_off=None, never_drop_input=None, prime_output_buffers_using_stream_callback=None)[source]§

PortAudio output stream (using buffer objects).

This is the same as OutputStream, except that the callback function and write() work on plain Python buffer objects instead of on NumPy arrays. NumPy is not necessary for using this.

Parameters:
  • dtype (str) – See RawStream.

  • callback (callable) – User-supplied function to generate audio data in response to requests from an active stream. The callback must have this signature:

    callback(outdata: buffer, frames: int,
             time: CData, status: CallbackFlags) -> None
    

    The arguments are the same as in the callback parameter of RawStream, except that indata is missing.

See also

RawStream, Stream