audiocn-svelte
Esc

Start typing to search the docs

Waveform

A static waveform of a clip with a smooth playhead, seeking, hover time, regions and markers.

2 min read · 317 words

Installation

$ pnpm dlx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/waveform.json

Usage

<script lang="ts">
	import { Waveform } from "#lib/components/ui/waveform/index.js";
	import { useAudioPlayer } from "#lib/hooks/use-audio-player.svelte.js";
	import { useWaveformData } from "#lib/hooks/use-waveform-data.svelte.js";

	let { src }: { src: string } = $props();

	const player = useAudioPlayer(() => ({ src }));
	const waveform = useWaveformData(() => src);
</script>

<Waveform
	duration={waveform.duration}
	onSeekCommit={player.seek}
	peaks={waveform.peaks}
	time={player.time}
/>

Pass time (a frame source) for a playhead that moves every frame without going through Svelte state, or bind currentTime for plain controlled use.

Anatomy

<Waveform>
	<WaveformCanvas />
	<WaveformCursor />
	<WaveformHover />
	<WaveformRegion />
	<WaveformMarker />
</Waveform>

Examples

Variants

bars
mirror
line

Regions and markers

Intro ends

Clip 0:09 – 0:22

Theming

Variable or attributeMeaning
--waveformUnplayed colour, default muted-foreground
--waveform-progressPlayed colour, default primary
--waveform-cursorPlayhead colour
--waveform-positionLive playhead position, 0..1
data-loading, data-dragging, data-disabledState

Accessibility

When interactive, the waveform is a slider with aria-valuetext such as "1:24 of 3:40". Arrow keys seek by step, Shift by largeStep, and Home and End jump to the ends. Region edges are separate sliders.

API reference

Waveform

PropTypeDefault
peaks

0..1, from useWaveformData.

ArrayLike<number> | null—
duration

Seconds.

number—
currentTime

Playhead in seconds. Bindable.

number0
time

A smooth playhead with no state updates.

FrameSource<number> | null—
onSeek

While seeking.

(time) => void—
onSeekCommit

On release or after keyboard seeking.

(time) => void—
step / largeStep

Seconds for the keyboard.

number5 / 15
variant "bars" | "line" | "mirror""bars"
barWidth / barGap / barRadius

Pixels.

number2 / 1 / 1
interactive

false is display only.

booleantrue
loading

Shows a skeleton.

booleanfalse
disabled booleanfalse

WaveformRegion

PropTypeDefault
start / end

Seconds. Bindable.

number—
onValueChange ({ start, end }) => void—
resizable

Drag the edges.

booleantrue
draggable

Drag the whole region.

booleantrue
minLength

Seconds.

number0.1

WaveformMarker

PropTypeDefault
time

Seconds. Children become the label.

number—
Last updated on October 7, 2026