:mod:`audioio` ============== .. py:module:: audioio .. autoapi-nested-parse:: Support for audio output The `audioio` module contains classes to provide access to audio IO. All classes change hardware state and should be deinitialized when they are no longer needed if the program continues after use. To do so, either call :py:meth:`!deinit` or use a context manager. See :ref:`lifetime-and-contextmanagers` for more info. Since CircuitPython 5, `RawSample` and `WaveFile` are moved to :mod:`audiocore`, and `Mixer` is moved to :mod:`audiomixer`. For compatibility with CircuitPython 4.x, some builds allow the items in `audiocore` to be imported from `audioio`. This will be removed for all boards in a future build of CircuitPython. .. py:class:: AudioOut(left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 32768) Output an analog audio signal .. attribute:: playing :annotation: :Any True when an audio sample is being output even if `paused`. (read-only) .. attribute:: paused :annotation: :Any True when playback is paused. (read-only) .. method:: deinit(self) Deinitialises the AudioOut and releases any hardware resources for reuse. .. method:: __enter__(self) No-op used by Context Managers. .. method:: __exit__(self) Automatically deinitializes the hardware when exiting a context. See :ref:`lifetime-and-contextmanagers` for more info. .. method:: play(self, sample: Any, *, loop: Any = False) Plays the sample once when loop=False and continuously when loop=True. Does not block. Use `playing` to block. Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`. The sample itself should consist of 16 bit samples. Microcontrollers with a lower output resolution will use the highest order bits to output. For example, the SAMD21 has a 10 bit DAC that ignores the lowest 6 bits when playing 16 bit samples. .. method:: stop(self) Stops playback and resets to the start of the sample. .. method:: pause(self) Stops playback temporarily while remembering the position. Use `resume` to resume playback. .. method:: resume(self) Resumes sample playback after :py:func:`pause`.