audiobusio¶
Support for audio input and output over digital buses
The audiobusio module contains classes to provide access to audio IO
over digital buses. These protocols are used to communicate audio to other
chips in the same circuit. It doesn’t include audio interconnect protocols
such as S/PDIF.
All libraries change hardware state and should be deinitialized when they
are no longer needed. To do so, either call deinit() or use a
context manager.
-
class
audiobusio.I2SOut(bit_clock: microcontroller.Pin, word_select: microcontroller.Pin, data: microcontroller.Pin, *, left_justified: bool = None)¶ Output an I2S audio signal
-
playing:Any¶ True when the audio sample is being output. (read-only)
-
paused:Any¶ True when playback is paused. (read-only)
-
deinit(self)¶ Deinitialises the I2SOut 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.
-
play(self, sample: Any, *, loop: Any = False)¶ Plays the sample once when loop=False and continuously when loop=True. Does not block. Use
playingto block.Sample must be an
audiocore.WaveFile,audiocore.RawSample, oraudiomixer.Mixer.The sample itself should consist of 8 bit or 16 bit samples.
-
stop(self)¶ Stops playback.
-
-
class
audiobusio.PDMIn(clock_pin: microcontroller.Pin, data_pin: microcontroller.Pin, *, sample_rate: int = 16000, bit_depth: int = 8, mono: bool = True, oversample: int = 64, startup_delay: float = 0.11)¶ Record an input PDM audio stream
-
sample_rate:Any¶ The actual sample_rate of the recording. This may not match the constructed sample rate due to internal clock limitations.
-
deinit(self)¶ Deinitialises the PDMIn 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.
-
record(self, destination: Any, destination_length: Any)¶ Records destination_length bytes of samples to destination. This is blocking.
An IOError may be raised when the destination is too slow to record the audio at the given rate. For internal flash, writing all 1s to the file before recording is recommended to speed up writes.
- Returns
The number of samples recorded. If this is less than
destination_length, some samples were missed due to processing time.
-