sound_device
Functions
Factory function to initialize the SoundDevice. |
|
Retrieves a list of available sound device names. |
Classes
Handles audio playback using sounddevice. |
- get_sound_devices() list[str][source]
Retrieves a list of available sound device names.
- Returns:
A list of device names.
- Return type:
list[str]
- class SoundDevice[source]
Bases:
SoundDeviceBaseHandles 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
- 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.
- load_wav(file: str) None[source]
Loads a WAV file into the playback queue.
- Parameters:
file (str) – Filename of the WAV file in the media directory.
- Raises:
FileNotFoundError – If the file does not exist.
ValueError – If sample rate mismatches or channel count is unsupported.
- 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]
- get_sound_device() SoundDeviceBase[source]
Factory function to initialize the SoundDevice.
- Returns:
An initialized SoundDevice or base class if disabled/failed.
- Return type: