audiocn

Waveform

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

Installation

$ pnpm dlx shadcn@latest add @audiocn/waveform

Usage

import { Waveform } from "@/components/ui/waveform";
const player = useAudioPlayer({ src });
const { peaks, duration } = useWaveformData(src);

<Waveform
  duration={duration}
  onSeekCommitted={player.seek}
  peaks={peaks}
  time={player.time}
/>;

Pass time (a frame source) for a playhead that moves every frame without re-rendering React, or 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

Prop

Type

WaveformRegion

Prop

Type

WaveformMarker

Prop

Type