audiocore

Support for audio samples

audiocore._AudioSample

An audio sample for playback with audioio.AudioOut, audiobusio.I2SOut or audiopwmio.PWMAudioOut.

Supported sources are audiocore.WaveFile, audiocore.RawSample, audiomixer.Mixer and audiomp3.MP3Decoder.

class audiocore.RawSample(buffer: ReadableBuffer, *, channel_count: int = 1, sample_rate: int = 8000)

A raw audio sample buffer in memory

sample_rate :Optional[int]

32 bit value that dictates how quickly samples are played in Hertz (cycles per second). When the sample is looped, this can change the pitch output without changing the underlying sample. This will not change the sample rate of any active playback. Call play again to change it.

deinit(self)

Deinitialises the AudioOut and releases any hardware resources for reuse.

__enter__(self)

No-op used by Context Managers.

__exit__(self)

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

class audiocore.WaveFile(file: typing.BinaryIO, buffer: ReadableBuffer)

Load a wave file for audio playback

A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating an internal buffer.

sample_rate :int

32 bit value that dictates how quickly samples are loaded into the DAC in Hertz (cycles per second). When the sample is looped, this can change the pitch output without changing the underlying sample.

bits_per_sample :int

Bits per sample. (read only)

channel_count :int

Number of audio channels. (read only)

deinit(self)

Deinitialises the WaveFile and releases all memory resources for reuse.

__enter__(self)

No-op used by Context Managers.

__exit__(self)

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.