Skip to content
Sign in
AudioA/B switchMenu

A/B switchPro

Two takes playing in sync with one key to switch, a 30 ms crossfade, the waveform of the take you hear and keep A or B.

ProTwo takes playing in sync: press X anywhere to switch and the position never moves.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/audio-ab-switch

Usage

tsx
import { AudioAbSwitch } from "@/components/ui/chatcn/pro/audio-ab-switch"

<AudioAbSwitch a={{ label: "A", source: takeA }} b={{ label: "B", source: takeB }} onKeep={keep} />

Both takes play the whole time and only their gains change, so the position never jumps and the comparison is honest. The toggle key works anywhere on the page except in text fields.

The examples play a demo synthesizer built on the Web Audio API (renderStem and renderSong in @/lib/chatcn-pro-music): drums, bass, keys and a sung line in a key and tempo, rendered offline. Pass your own audio as URLs or buffers instead.

Examples

States

ProB kept and disabled.

Props

PropTypeNotes
a, bAbTakeRequired. Label, note, source, peaks
value, defaultValue, onValueChange"a" | "b"
onKeep, keptKeep A or B
toggleKeystring | nullDefault "x"
labelsPartial<AudioAbLabels>Every string the switch shows or announces, for translation

Keyboard

KeyAction
XSwitch between A and B
← → on the takesPick a take
← → on the positionSeek

Accessibility

  • The takes are a radio group; switching announces which take you hear.

Motion

  • Switching is instant to the eye and a 30 ms crossfade to the ear.