SoundDevice
- class SoundDevice[source]
Bases:
objectHandles audio playback using sounddevice.
- samplerate
Audio sample rate.
- Type:
int
- channels
Number of audio channels.
- Type:
int
- latency
Latency setting for sounddevice.
- Type:
str
- index
Index of the used sound device.
- Type:
int
- error
Error message.
- Type:
str
- stream
The active audio stream (internal).
- Type:
sd.OutputStream
- sound
The current sound buffer.
- Type:
np.ndarray
- command_queue
Queue for processing audio commands in a thread.
- Type:
queue.Queue
- thread
Background thread for audio processing.
- Type:
threading.Thread
- thread_running
Flag to control the background thread.
- Type:
bool
- __init__() None[source]
Initializes the SoundDevice with settings.
Methods
__init__()Initializes the SoundDevice with settings.
create_sound_vec(left, right)Interleaves left and right channels into a stereo array.
get_sound_from_wav(file)load(left, right)Loads sound data into the playback queue.
play()Triggers playback of the loaded sound.
shutdown()Shuts down the audio thread and stream.
stop()Stops playback.
- load(left: Any, right: Any) None[source]
Loads sound data into the playback queue.
- Parameters:
left (Any) – Left channel data (array-like).
right (Any) – Right channel data (array-like).
- Raises:
ValueError – If inputs are invalid or lengths differ.
- get_sound_from_wav(file: str) tuple[numpy.ndarray, numpy.ndarray][source]
- play() None[source]
Triggers playback of the loaded sound.
- stop() None[source]
Stops playback.
- shutdown() None[source]
Shuts down the audio thread and stream.
- static create_sound_vec(left: numpy.ndarray, right: numpy.ndarray) numpy.ndarray.numpy.float32[source]
Interleaves left and right channels into a stereo array.
- Parameters:
left (np.ndarray) – Left channel data.
right (np.ndarray) – Right channel data.
- Returns:
Interleaved stereo data.
- Return type:
np.ndarray[np.float32]