[ SDK ] /docs/sdk/sound
site/sound
Small synthesized sounds. Silent until the visitor has interacted with the page, and when they prefer reduced motion.
import sound from "site/sound"Functions#
| Signature | Description |
|---|---|
fn beep(hz: i64, ms: i64) -> void | 40-4000 Hz, 10-1000 ms |
fn chord(notes: []i64, ms: i64) -> void | up to 6 notes, in Hz |
fn mute(on: bool) -> void | Mutes or unmutes the sounds this script makes. The visitor's own mute (the Toggle sound action) is separate and always wins. |
Examples#
import site from "site"
import sound from "site/sound"
site.action(site.Action {
name: "chime",
title: "Chime",
description: "A short chord, then a beep",
category: "Docs",
keywords: [],
run: () => {
sound.chord([262, 330, 392], 400)
sound.beep(880, 80)
},
})
sound.mute(false)
Limits#
- beep is clamped to 40-4000 Hz and 10-1000 ms. chord plays at most 6 notes, with the same limits.
- At most 20 sounds a second. Nothing plays before the visitor has interacted with the page, while sound is muted, or when the visitor prefers reduced motion.
Declaration file#
This page is generated from the file below, served as /eitri/sdk/site/sound.eith. Types and signatures are exactly what the compiler checks scripts against. Back to all modules.
// site/sound: small synthesized sounds. Silent until the visitor has
// interacted with the page, and when they prefer reduced motion.
pub fn beep(hz: i64, ms: i64) -> void // 40-4000 Hz, 10-1000 ms
pub fn chord(notes: []i64, ms: i64) -> void // up to 6 notes, in Hz
pub fn mute(on: bool) -> void