Devices
minispeaker.devices
default_speaker
def default_speaker() -> str
Retrieves the default speaker.
Internally implemented using pyminiaudio's internal library, which is subject to change.
Raises:
MiniaudioError
- If speaker enumeration fails
Returns:
str
- The name of the default speaker.
available_speakers
def available_speakers() -> List[str]
Retrieves all available speakers by name.
Returns:
List[str]
- A list of available speakers
MaDeviceState
class MaDeviceState(Enum)
Miniaudio equivalent enum of ma_device_state
.
Arguments:
Enum
type - Pythonic version ofma_device_state
Attributes:
UNINITIALIZED
- Device has not been initialized yetSTOPPED
- Device is initialized but not actively processing audioSTARTED
- Device is actively processing audioSTOPPING
- Device is in the process of stoppingSTARTING
- Device is in the process of starting
ConcurrentPlaybackDevice
class ConcurrentPlaybackDevice(PlaybackDevice)
Modified miniaudio PlaybackDevice
class with accessible ma_device_state
and thread-safe concurrency.
Arguments:
*args
- Variable length argument list passed to parentPlaybackDevice
.stopped
Event - Used to signal when aPlaybackDevice
is finished.**kwargs
- Arbitrary keyword arguments passed to parentPlaybackDevice
.
Attributes:
state
MaDeviceState - Current state of the audio device.volume
float | None - Volume level of the PlaybackDevice (0.0 to 1.0+).starting
bool - True if the device is currently starting.stopping
bool - True if the device is currently stopping.stopped
bool - True if the device has stopped.closed
bool - True if the device is uninitialized/closed.started
bool - True if the device has started and is running.
ConcurrentPlaybackDevice.state
@property
def state()
Retrieves ma_device_state
from PlaybackDevice
.
ConcurrentPlaybackDevice.volume
@property
def volume() -> float | None
Unlike Speaker
volume, this volume
represents the volume of the local PlaybackDevice
itself, before Python processing.
Returns:
float | None: Volume of PlaybackDevice
.
ConcurrentPlaybackDevice.volume
@volume.setter
def volume(vol: float)
Attempts to internally sets the volume of the internal PlaybackDevice.
Uses internal implementation _device.masterVolumeFactor, so this function may not work if harmful changes are made to miniaudio or pyminiaudio.
Function is no-op if it does not dynamically pass sanity checks on internal implementation.
Arguments:
vol
float - The initial volume of the speaker as a percent decimal.
ConcurrentPlaybackDevice.wait
def wait() -> bool | Coroutine[Any, Any, Literal[True]]
Waits for the PlaybackDevice
to be stopped.
Returns:
bool | Coroutine[Any, Any, Literal[True]]: Either a synchronous or asynchronous return result of Event.wait
ConcurrentPlaybackDevice.starting
@property
def starting() -> bool
Is the PlaybackDevice
starting?
ConcurrentPlaybackDevice.stopping
@property
def stopping() -> bool
Is the PlaybackDevice
stopping?
ConcurrentPlaybackDevice.stopped
@property
def stopped() -> bool
Has the PlaybackDevice
stopped?
ConcurrentPlaybackDevice.closed
@property
def closed() -> bool
Is the PlaybackDevice
uninitialized?
ConcurrentPlaybackDevice.started
@property
def started()
Has the PlaybackDevice
started?
ConcurrentPlaybackDevice.start
def start(callback_generator: PlaybackCallbackGeneratorType)
Starts Playback with thread-safety. Is no-op on subsequent start requests while running.
Arguments:
callback_generator
PlaybackCallbackGeneratorType - Any valid miniaudio playback generator.
ConcurrentPlaybackDevice.stop
def stop()
Stops Playback with thread-safety. Is no-op on subsequent stop requests while not running.