stimuli.audio.backend.SoundSD🔗
- class stimuli.audio.backend.SoundSD(device, sample_rate, *, clock=<class 'stimuli.time._clock.Clock'>)[source]🔗
Sounddevice backend for audio playback.
- Parameters:
- device
int Device index of the output device as provided by
sounddevice.query_devices(). If None, the default output device is used.- sample_rate
int The sample rate of the audio data, which should match the sample rate of the output device. If None, the default sample rate of the device is used.
- clock
stimuli.time.BaseClockclass Clock object to use for timing measurements. By default, the
stimuli.time.Clockclass is used.
- device
Attributes
The clock object used for time measurement.
The duration of the audio data, in seconds.
The sample rate of the audio data.
Methods
close()Close the backend and release the resources.
initialize(data[, block_size])Initialize the backend with audio data.
play([when, blocking])Play the audio data.
stop()Interrupt immediately the playback of the audio data.
- initialize(data, block_size=32)[source]🔗
Initialize the backend with audio data.
- Parameters:
- data
ndarrayof shape (n_frames, n_channels) The audio data to play provided as a 2 dimensional array of shape
(n_frames, n_channels). The array layout must be C-contiguous. A one dimensionalndarrayof shape(n_frames,)is also accepted for mono audio.- block_size
int The number of frames passed to the stream callback function, or the preferred block granularity for a blocking read/write stream. The special value
blocksize=0may be used to request that the stream callback will receive an optimal (and possibly varying) number of frames based on host requirements and the requested latency settings.
- data
- play(when=None, *, blocking=False)[source]🔗
Play the audio data.
- Parameters:
- when
float|None The relative time in seconds when to start playing the audio data. For instance,
0.2will start playing in 200 ms. IfNone, the audio data is played as soon as possible. A duration superior to the device latency is recommended.- blocking
bool If True, the function blocks until the audio playback is finished.
- when
- property clock🔗
The clock object used for time measurement.
- property duration🔗
The duration of the audio data, in seconds.
- property sample_rate🔗
The sample rate of the audio data.