# Voice note

> A voice message you can scrub and read along with: the waveform fills, the time rolls, and the transcript highlights each word as it’s said.

Voice messages are quick to send and slow to receive: you can’t skim them, and you can’t listen in a meeting. Its wave is drawn in hairlines, one every 3px along a smooth envelope, standing on a hairline baseline with a faint, shorter reflection under it, and it rises out of the baseline when it arrives. Play and the triangle splits and squares off into pause; a hairline playhead with a dot on the baseline glides through the wave every frame, the lines it has passed turn to ink, and the time rolls up. Press anywhere on the wave and drag: the lines under your finger swell like a lens and the time follows, and when you let go it carries on from there. The speed rolls from 1× to 1.5× and 2×. Open the transcript and a highlight glides from word to word as they’re said, the words still to come waiting in grey; tap a word and it plays from there. Only one voice note plays at a time on a page.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/voice-note.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`
- Docs and live preview: https://hairlineui.com/ui/voice-note
- Registry item (source): https://hairlineui.com/r/voice-note.json

## Usage

```tsx
import { VoiceNote } from "@/components/voice-note";

<VoiceNote
  src="/notes/sam.mp3"
  label="Voice note from Sam"
  unread
  transcript={[{ text: "Hey,", start: 0.1 }, { text: "quick", start: 0.8 }, /* … */]}
/>
```

## With a transcription API

Store the word timings your speech-to-text returns next to the file, and the peaks too so the waveform shows before the audio loads.

```tsx
"use client";
import { VoiceNote } from "@/components/voice-note";

type Message = {
  audioUrl: string;
  seconds: number;
  peaks: number[]; // e.g. 96 loudness values worked out on upload
  words: { word: string; start: number }[]; // from Whisper, Deepgram, AssemblyAI…
  read: boolean;
};

export function VoiceMessage({ message, from }: { message: Message; from: string }) {
  return (
    <VoiceNote
      src={message.audioUrl}
      duration={message.seconds}
      peaks={message.peaks}
      transcript={message.words.map((w) => ({ text: w.word, start: w.start }))}
      unread={!message.read}
      label={`Voice note from ${from}`}
      onPlay={() => markRead(message)}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `src` | `string` | – | The audio file. |
| `peaks` | `number[]` | – | Loudness from 0 to 1, any length; eased into a smooth envelope at one hairline per 3px. Without them the file is fetched and decoded to work them out. |
| `duration` | `number` | – | Seconds, shown until the audio’s own length is known. |
| `transcript` | `{ text: string; start: number }[]` | – | The words in order with when each is said. Adds the Transcript fold. |
| `defaultTranscriptOpen` | `boolean` | `false` | Start with the transcript open. |
| `speeds` | `number[]` | `[1, 1.5, 2]` | What the speed pill steps through. |
| `unread` | `boolean` | `false` | Show the dot until it’s played. |
| `label` | `string` | `"Voice note"` | Names the group for assistive tech, e.g. "Voice note from Sam". |
| `onPlay / onEnded` | `() => void` | – | When it starts playing, and when it reaches the end. |

## States

- **arrive**: The wave rises out of its baseline over 900ms, left to right; above the baseline in ink or grey, below it a reflection at about a third of the strength.
- **play / pause**: One icon of two quads: the halves of the triangle slide and square off into the two pause bars (clip-path, 320ms). A hairline playhead with a dot on the baseline follows the audio every frame (no re-render); the lines it has passed turn to ink; the time counts up in rolling digits.
- **scrub**: Pressing pauses it; the hairlines near the pointer swell up to 1.55× with a soft falloff and the time shows where you are; releasing seeks there and plays on if it was playing.
- **speed**: 1× → 1.5× → 2× roll in place; the pitch stays the same.
- **transcript**: Folds open under the note (grid rows, 420ms). The current word’s highlight glides to the next word (260ms); words already said are in ink, the rest in grey. Tapping a word plays from its start.
- **end**: Holds full for 500ms, then the fill runs back to the start (600ms) and the time rolls back to the length.
- **unread**: A small dot by the time; it shrinks away the first time it plays.

## What it handles

Voice messages are quick to send and slow to receive: you cannot skim them, and you cannot listen to one in a meeting. This shows a waveform, lets you scrub it, and reads along with a transcript.

- **A waveform you can scrub**: Press and drag and the hairlines under your finger swell. Letting go carries on from there.
- **Play, pause and speed**: The icon morphs between play and pause, and the speed steps through 1×, 1.5× and 2× without changing the pitch.
- **A transcript that follows**: A highlight glides from word to word as they are said. Tap a word to play from there.
- **Quick to show**: Pass the waveform peaks up front and the file does not have to be downloaded just to draw it.
- **One at a time**: Starting one voice note pauses any other on the page.
- **Unread and keyboard**: A dot marks unplayed notes. The waveform is a slider where arrow keys move two seconds.

## Replaces

an audio player, waveform drawing, a scrub bar, a speed control, a word-by-word transcript, an unread dot

## Where it fits

- **Chat and messaging apps**: Voice messages that can be scrubbed and read along with.
- **Voicemail inboxes**: Messages with a transcript, so they can be skimmed.
- **Call recordings and interviews**: Audio with a transcript that follows the playback.
- **Community and social apps**: Audio replies in a thread.

## Notes

- The waveform is a slider: arrow keys move two seconds, Home and End go to the ends, and it reads its position as "0:04 of 0:11".
- The play button says Play or Pause, the speed pill says its speed, and the transcript is plain text in the page.
- Starting one voice note pauses any other on the page.
- Peaks given up front avoid downloading the whole file just to draw it; without them the audio is decoded once with Web Audio (the file has to be same-origin or allow CORS).
- Installs Number roll. With reduced motion the wave, icon, highlight and fold change in place.

License: MIT (https://hairlineui.com/license#components)
