DVI Audio
CircuitPython 11 is incorporating DVI audio, using compatible Adafruit hardware like the Adafruit Fruit Jam and Metro or Feather coupled with an HSTX to DVI out board. The audio is routed to the DVI audio.
Download the Absolute Newest CircuitPython Version
For your Adafruit Fruit Jam, Metro RP2350 / Feather RP2350 with HSTX to DVI, download the Absolute Newest version of CircuitPython from CircuitPython.org:
Then select the language you want:
Then you'll see all the releases. Here there are 19 nightly releases after CircuitPython 11.0.0.alpha.1. Select the one at the top, which is the newest.
When you click the link, your browser should save the file. Then use that .uf2 file to load on to the RP2350 board, per the standard CircuitPython loading procedure. Go to the Learn Guide for your board and go to the Install CircuitPython page for the procedure which is similar to the Feather below.
How It Works
The picodvi library had been augmented with the picodvi.AudioOut() function. The single parameter is a valid picodvi.Framebuffer object. This means you are required to create a valid video framebuffer to set up DVI audio.
The function returns an object, often named audio, used to work with the audio stream.
fb = picodvi.Framebuffer(320, 240, clk_dp=board.CKP, clk_dn=board.CKN,
red_dp=board.D0P, red_dn=board.D0N,
green_dp=board.D1P, green_dn=board.D1N,
blue_dp=board.D2P, blue_dn=board.D2N)
audio = picodvi.AudioOut(fb)
picodvi.AudioOut(fb) as early as possible in your script to prevent heap fragmentation issues.
Once you have the audio object, you can call the picodvi.AudioOut functions below:
play(sample: AudioSample, *, loop: bool = False)stop()pause()resume()
And get status from the boolean functions:
audio.playingaudio.paused
A full set of documentation is on ReadTheDocs for picodvi including picodvi.AudioOut.
The following code sets up a 320x240 video framebuffer (which is not used for video in the example) and uses HDMI audio as described above. A one kilohertz sine wave is created mathematically and a tone object makes it into an audio sample with a sample rate of 48k. The tone is then played for five seconds.
The simple example works on boards without PSRAM.
Click Download Project Bundle (only code.py as the libraries are frozen in the build) and copy code.py to the CIRCUITPY drive.
# SPDX-FileCopyrightText: 2026 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import array
import math
import time
import audiocore
import board
import displayio
import picodvi
displayio.release_displays() # Ensure previous video framebuffers are gone
fb = picodvi.Framebuffer(320, 240, clk_dp=board.CKP, clk_dn=board.CKN,
red_dp=board.D0P, red_dn=board.D0N,
green_dp=board.D1P, green_dn=board.D1N,
blue_dp=board.D2P, blue_dn=board.D2N)
# Make the HDMI audio object (do this directly after creating the framebuffer for memory management)
audio = picodvi.AudioOut(fb)
# Make a 1,000 Hz sine wave
sine = array.array("h", [int(1000 * math.sin(math.pi * 2 * i / 48)) for i in range(48)])
# Make an audio sample
tone = audiocore.RawSample(sine, sample_rate=48000)
print("\n\nPlaying started\n")
audio.play(tone, loop=True)
start = time.monotonic()
while time.monotonic() - start < 5: # Play the tone for 5 seconds
time.sleep(0.1) # yield; the tone keeps looping in the background
audio.stop()
print("\nPlaying complete\n")
picodvi implementation as that is the singular rate for DVI audio support. This may change in later picodvi versions.
Playing a WAV File
Wav files are raw sample files (first defined for Windows, now ubiquitous). For DVI audio using the library, the WAV file must be 48 kHz. picodvi.AudioOut only accepts samples with a sample rate of 48000 Hz, which is why the program checks before playing. Files ripped or downloaded at 44.1 kHz or other bitrates won’t play as-is. You can use Audacity, sox or another program to change the sample rate to 48000. Below is an open source 48kHz WAV sound clip for testing, consisting of 6 notes on a piano obtained here.
Click Download Project Bundle (code.py and piano.wav) and copy them to the CIRCUITPY drive.
# SPDX-FileCopyrightText: 2026 Anne Barela
#
# SPDX-License-Identifier: MIT
#
# Example: Play a 40kHz wav file over HDMI Audio
import time
import audiocore
import board
import displayio
import picodvi
WAV_FILE = "/piano.wav" # path to a 48kHz WAV file on the CIRCUITPY drive
displayio.release_displays()
fb = picodvi.Framebuffer(320, 240, clk_dp=board.CKP, clk_dn=board.CKN,
red_dp=board.D0P, red_dn=board.D0N,
green_dp=board.D1P, green_dn=board.D1N,
blue_dp=board.D2P, blue_dn=board.D2N)
audio = picodvi.AudioOut(fb) # create soon after the Framebuffer (it needs internal RAM)
wave = audiocore.WaveFile(WAV_FILE) # Open the wav file
if wave.sample_rate != 48000:
print(f"\n{WAV_FILE} is {wave.sample_rate} Hz; picodvi.AudioOut needs 48000 Hz.")
print("Resample the file to 48 kHz and try again.\n")
else:
print(f"\n\nPlaying {WAV_FILE}\n")
audio.play(wave)
while audio.playing:
time.sleep(0.1) # yield; playback runs in the background
print("\nPlaying complete\n")
audio.deinit()
wave.deinit()
Support for WAV Files Other Than 48kHz
Current CircuitPython libraries can handle audio sample rates other than the DVI audio rate of 48kHz. It takes a couple more audio processing calls to transform the audio from its recorded rate to 48kHz and it takes up some more memory. If you anticipate WAV files at other (or unknown) rates, this is likely the upgraded algorithm you'll want to use.
This test file is an open source scary laugh encoded in 11.025 kHz stereo:
Click Download Project Bundle (code.py and laugh-stereo-11k.wav) and copy them to the CIRCUITPY drive. (note the last three characters of the filename are one-one-k).
# SPDX-FileCopyrightText: 2026 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# Play a WAV file of any sample rate through DVI/HDMI audio.
# DVI audio in CircuitPython only plays 48 kHz, so non-48 kHz files are
# wrapped in audiospeed.Resampler and played into a 48 kHz mixer.
import time
import audiocore
import audiomixer
import audiospeed
import board
import displayio
import picodvi
WAV_FILE = "/laugh-stereo-11k.wav" # path to the WAV file on CIRCUITPY
DVI_RATE = 48000 # the only rate DVI audio accepts
VOLUME = 0.15 # 0.0 = silent, 1.0 = full, up this if low volumme
displayio.release_displays()
fb = picodvi.Framebuffer(320, 240, clk_dp=board.CKP, clk_dn=board.CKN,
red_dp=board.D0P, red_dn=board.D0N,
green_dp=board.D1P, green_dn=board.D1N,
blue_dp=board.D2P, blue_dn=board.D2N)
audio = picodvi.AudioOut(fb) # create soon after the Framebuffer (needs internal RAM)
wave = audiocore.WaveFile(WAV_FILE)
print(f"\n{WAV_FILE}: {wave.sample_rate} Hz, {wave.channel_count} channel(s), "
f"{wave.bits_per_sample}-bit")
if wave.sample_rate == DVI_RATE:
print("Playing directly\n")
source = wave
else:
print(f"Resampling {wave.sample_rate} Hz -> {DVI_RATE} Hz\n")
source = audiospeed.Resampler(wave)
mixer = audiomixer.Mixer(voice_count=1, buffer_size=2048,
sample_rate=DVI_RATE,
channel_count=wave.channel_count,
bits_per_sample=wave.bits_per_sample,
samples_signed=wave.bits_per_sample == 16)
audio.play(mixer)
mixer.voice[0].level = VOLUME
mixer.voice[0].play(source)
while mixer.voice[0].playing:
time.sleep(0.1) # yield; playback runs in the background
time.sleep(0.1) # let the last buffers drain
audio.stop()
mixer.deinit()
if source is not wave:
source.deinit()
print("Playing complete\n")
audio.deinit()
wave.deinit()
Adafruit engineer Mikey Sklar developed a talking text to speech demonstration.
Several notes for this demo:
- This demo needs PR #11574 firmware, not nightly
- This demo uses a Feather RP2350 with 8 MB PSRAM, the PSRAM is required
- Add
settings.toml:"always", width 320
Text is typed and appears on screen as it is typed. Then speech synthesis code voices the sentence. It is a great demonstration of video, speech and audio.
Page last edited October 14, 2026