miniaudio provides Python bindings for the `miniaudio` C library, offering cross-platform audio playback and decoding capabilities. It includes built-in decoders for common formats like MP3, FLAC, OGG Vorbis, and WAV. The library is actively maintained, with frequent releases (roughly monthly to bi-monthly) often focusing on updates to the underlying C library and Python version compatibility. The current version is 1.61.
pip install miniaudioVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to generate a sine wave using NumPy and play it directly using `miniaudio.stream_raw_pcm_memory`. It sets up a `PlaybackDevice`, creates a stream from the raw audio data, plays it, and then waits for the playback duration. This avoids reliance on external audio files.
For non-blocking playback or real-time applications, run playback in a separate thread, use an asynchronous framework, or implement custom buffer management with callbacks.
Wrap `miniaudio.PlaybackDevice()` instantiation in a `try...except miniaudio.exceptions.MiniaudioError` block. Ensure necessary audio drivers are installed and the device is not exclusively locked by another application.
Carefully verify that the `sample_rate`, number of channels, and sample format (e.g., `miniaudio.SampleFormat.SIGNED16`) passed to `stream_raw_pcm_memory` or custom stream callbacks precisely correspond to the raw audio data being provided.
Ensure the audio file is a valid and supported format. If decoding fails, catch `miniaudio.exceptions.MiniaudioError` and provide user feedback. Consider using a utility to verify file format integrity if issues persist.
Check if an audio output device is connected and properly configured in your operating system settings. Ensure audio drivers are installed. On some systems, restarting the audio service or the computer may resolve temporary issues.
Verify the file path is correct and absolute, or relative to the script's execution directory. Check for typos in the filename or extension. Ensure the process has read permissions for the file.
Wrap your raw PCM `bytes` data using `miniaudio.stream_raw_pcm_memory` (or a custom generator function) to create an iterable stream that `device.play()` can consume, e.g., `device.play(miniaudio.stream_raw_pcm_memory(my_bytes_data, ...))`.
Import submodules by their full path: `import miniaudio.decoders`. You can then access members like `miniaudio.decoders.FileDecoder`.
No dependency data recorded yet.