Audio synthesis and playback via I2S DAC
Plays audio through the T-Deck speaker via I2S. Supports multiple formats: WAV files (PCM, 8/16-bit, mono/stereo), MP3 files (decoded with Helix), and raw PCM samples. Also provides tone synthesis for beeps and alerts. Use play() for automatic format detection, or play_wav()/play_mp3() directly. Audio output is mono at 44100Hz with volume control.
| Parameter | Description |
|---|---|
| count | Number of beeps (default 1) |
| frequency | Tone frequency in Hz (default 1000) |
| on_ms | Beep duration in ms (default 100) |
| off_ms | Pause between beeps in ms (default 50) |
ez.audio.beep() -- Single default beep
ez.audio.beep(2) -- Two beeps
ez.audio.beep(3, 2000) -- Three high-pitched beeps
ez.audio.beep(1, 500, 200, 0) -- One low 200ms beep
local vol = ez.audio.get_volume()
print("Current volume:", vol .. "%")
ez.audio.play_tone(440, 500)
while ez.audio.is_playing() do
ez.system.delay(10)
end
print("Tone finished!")
| Parameter | Description |
|---|---|
| filename | Path to audio file (.wav, .mp3, or .pcm) |
-- Play different formats
ez.audio.play("click.wav")
ez.audio.play("notify.mp3")
ez.audio.play("beep.pcm")
-- Play from SD card
ez.audio.play("/sd/sounds/music.mp3")
| Parameter | Description |
|---|---|
| filename | Path to .mp3 file (relative to /sounds/ for LittleFS, or full path starting with /sd/ for SD card) |
-- Play from internal storage
ez.audio.play_mp3("startup.mp3")
-- Play from SD card
ez.audio.play_mp3("/sd/music/song.mp3")
| Parameter | Description |
|---|---|
| handle | Handle returned by preload() |
local click = ez.audio.preload("click.wav")
-- Play instantly when button is pressed
ez.audio.play_preloaded(click)
| Parameter | Description |
|---|---|
| handle | Handle returned by preload() |
local click = ez.audio.preload("tap_01.pcm")
-- Fire and forget — UI stays responsive
ez.audio.play_preloaded_async(click)
| Parameter | Description |
|---|---|
| filename | Path to .pcm file (relative to /sounds/, extension optional) |
-- Play a notification sound
ez.audio.play_sample("notify")
-- Play with full path
ez.audio.play_sample("alerts/warning.pcm")
| Parameter | Description |
|---|---|
| frequency | Frequency in Hz (20-20000) |
| duration_ms | Duration in milliseconds |
-- Play a 440Hz (A4) beep for half a second
ez.audio.play_tone(440, 500)
-- Play a higher alert tone
ez.audio.play_tone(880, 200)
| Parameter | Description |
|---|---|
| filename | Path to .wav file (relative to /sounds/ for LittleFS, or full path starting with /sd/ for SD card) |
-- Play from internal storage
ez.audio.play_wav("click.wav")
-- Play from SD card
ez.audio.play_wav("/sd/music/song.wav")
| Parameter | Description |
|---|---|
| filename | Path to .wav or .pcm file |
-- Preload UI sounds at startup
local click = ez.audio.preload("click.wav")
local beep = ez.audio.preload("beep.wav")
-- Later, play with zero latency
ez.audio.play_preloaded(click)
| Parameter | Description |
|---|---|
| frequency | Frequency in Hz (20-20000) |
ez.audio.start()
for freq = 200, 800, 50 do
ez.audio.set_frequency(freq)
ez.system.delay(50)
end
ez.audio.stop()
| Parameter | Description |
|---|---|
| level | Volume level 0-100 |
ez.audio.set_volume(50) -- Half volume
ez.audio.beep()
ez.audio.set_volume(100) -- Full volume
ez.audio.set_frequency(1000)
ez.audio.start()
-- Tone plays continuously until stopped
ez.system.delay(2000)
ez.audio.stop()
ez.audio.start() -- Start continuous tone
ez.system.delay(1000)
ez.audio.stop() -- Stop after 1 second
| Parameter | Description |
|---|---|
| handle | Handle returned by preload() |
local click = ez.audio.preload("click.wav")
-- ... use it ...
ez.audio.unload(click) -- Free memory