Sound
A sound the page plays when something happens: a timer ran out, a step is done, a button was pressed. Works the same in the app and on the site.
Do not confuse it with
*Sound
(with the asterisk) — that is a film track, a scene layer that is heard only in the preview and in the export.
Type:
wrapper
— draws its child or nothing.
State @left:90
Sound src:"data/sounds/kitchen_timer.mp3" when:{left <= 0}
Text $"${left} s"
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
src
|
string | — |
Sound file: a path in the project (
data/sounds/ding.mp3
) or an address with a scheme
|
when
|
boolean |
false
|
Rings when the condition goes from false to true |
at
|
number (ms) or list | — |
Rings at this moment (ms since the epoch, like
now()
) or at every moment of a list — in a background tab too
|
volume
|
number 0…1 |
1
|
Volume; 1 — as recorded |
play
|
output
@name
|
— | A ready callback for a button |
ready
|
output
@name
|
— | Whether it can sound right now: on the site false until the first touch on the page after loading — show "tap to enable the alarm" |
When
when:
rings
Only on a
transition
from false to true. It does not ring when the page loads, even if the condition is already true: a page opened after the timer ended shows that time is up, and an alarm on every reload would lie. From true to false — silence, true again — it rings again. A condition that stays true (
left
goes below zero) rings once. Only
true
rings — a number or a string does not count as "true".
Timer:
at:
, not
when:
For a timer give
Sound
a MOMENT, not a condition:
at:{end}
, where
end
is the end time in ms (
now() + 90000
). A browser wakes the timers of a background tab once a minute, and a condition like "ended in the last 3 seconds" is missed — the alarm stays silent. A sound set for a moment is queued on the site in Web Audio, which the audio clock drives, and rings on time, in the background too. A new
at
moves the ring;
0
or a moment in the past does not ring. The audio clock needs one touch on the page (tapping "Start" is enough); until then a fallback timer rings — later in the background, but it rings.
Several timers on a page — give
at:
a LIST of their ends:
at:{map(values(timers), (t){t['end'] ?? 0})}
. All moments are queued at once. If you give only the nearest end, the next alarm is queued only after the previous one and is up to a minute late in a background tab. A new list leaves the remaining moments alone, removes the dropped ones and adds the new ones; a sound that is playing finishes.
Where the file lives
In the project under
data/
— the site serves project files only from there; a path outside
data/
is silent on the site, and the editor warns about it. A missing file is the
asset_not_found
diagnostic. Formats: MP3 and WAV play everywhere, OGG does not play in Safari.
Limitations
- Browser. A page can make sound only after the person has touched it at least once. A timer started by a tap has already met this condition.
-
Not a player.
Soundplays over everything that is playing — music, video, a film track in the editor preview — and over anotherSound: the system mixes them. It has no pause or seek: it plays from the start and ends by itself. - App. The sound is held in memory whole and is cut off at 30 seconds.
- A build without a sound engine stays silent and does not crash.
Examples
A recipe step alarm and a "Test sound" button
State @left:60
Sound src:"data/sounds/kitchen_timer.mp3" when:{left <= 0} play:@ring volume:0.8
Column
Text $"${left} s left"
ElevatedButton onPressed:$ring
Text "Test sound"
The button also gives the browser that first touch: after it the alarm on the site is guaranteed to ring.