Voice note
Book the dentist for next Tuesday morning, and move the gym to the evening.
One entry in a list of voice notes: when it was recorded, what was said and the recording to check it against. While transcription runs it holds its place with a waveform and placeholder lines.
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
import { synthClip } from "@/components/forme/audio-player/demo-clip";
import { VoiceButton } from "@/components/forme/voice-button/voice-button";
import type { VoiceButtonState } from "@/components/forme/voice-button/voice-button";
import { VoiceNote } from "@/components/forme/voice-note/voice-note";
interface Note {
id: number;
createdAt: Date;
transcript?: string;
}
const dictations = [
"Pick up the framed print on the way home, the shop closes at six.",
"Idea for the newsletter: a short piece on how the team plans a release.",
"Ask Sam whether the venue can do a vegetarian menu for forty.",
];
function clipFor(seed: number) {
return synthClip(
Array.from({ length: 8 + seed * 2 }, (_, i) => ({
start: 0.3 + i * 0.45,
end: 0.62 + i * 0.45,
})),
1 + (8 + seed * 2) * 0.45,
);
}
export function VoiceNoteDemo() {
const clips = useMemo(() => [0, 1, 2].map(clipFor), []);
const [state, setState] = useState<VoiceButtonState>("idle");
const [notes, setNotes] = useState<Note[]>(() => [
{
id: 1,
createdAt: new Date(Date.now() - 3 * 60_000),
transcript: "Book the dentist for next Tuesday morning, and move the gym to the evening.",
},
{
id: 0,
createdAt: new Date(Date.now() - 26 * 3_600_000),
transcript:
"The client liked the second direction. Send them the revised timeline by Friday.",
},
]);
const next = useRef(2);
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
useEffect(() => () => timers.current.forEach(clearTimeout), []);
function stop() {
const id = next.current++;
setNotes((current) => [{ id, createdAt: new Date() }, ...current]);
setState("processing");
timers.current.push(
setTimeout(() => {
setNotes((current) =>
current.map((note) =>
note.id === id ? { ...note, transcript: dictations[id % dictations.length] } : note,
),
);
setState("idle");
}, 2200),
);
}
return (
<div className="flex w-full max-w-md flex-col gap-4">
<VoiceButton
mode="toggle"
state={state}
onStart={() => setState("recording")}
onStop={stop}
className="self-center"
/>
<div className="flex flex-col gap-3">
{notes.map((note) => (
<VoiceNote
key={note.id}
src={clips[note.id % clips.length]}
createdAt={note.createdAt}
transcript={note.transcript}
transcribing={!note.transcript}
onDelete={() => setNotes((current) => current.filter((n) => n.id !== note.id))}
/>
))}
</div>
</div>
);
}Adds the component, its registry dependencies, and the token stylesheet you import once.
Read from the source, so it is the API of the file you install. A prop marked * is required.
One entry in a list of voice notes: when it was recorded, what was said and the recording to check it against. While the speech model is still working the transcript is a waveform and two placeholder lines, which the text replaces in place — the card does not change size by much, so a list of them does not jump.
| Prop | Type | Default | Description |
|---|---|---|---|
createdAt* | Date | — | |
src | string | Blob | — | The recording. Without it the card is text only. |
transcript | ReactNode | — | What was said. Leave it out while the recording is still being transcribed. |
transcribing | boolean | false | Shows the transcribing state instead of the transcript. |
title | ReactNode | "Voice note" | |
onDelete | () => void | — | Shows a delete button. Ask for confirmation in here if the note matters. |
className | string | — |
A transport bar for one recording: skip back and forward, play, a seek bar, time, volume and speed. Its ref is a small handle, so a transcript or a chapter list can seek and play it from outside.
The record button of a voice interface: push to talk or tap to toggle, a live waveform and a running clock while recording, then transcribing, done or try again. You drive the state; it records nothing itself.
A transcript that follows the audio: the current line is marked and kept in view, the word being said lights within it, and any line or word seeks back to where it was spoken. One tab stop, arrow keys between lines.
Book the dentist for next Tuesday morning, and move the gym to the evening.
The client liked the second direction. Send them the revised timeline by Friday.