Skip to content
Calm motion: animations on this site only fade, with no movement

AudioRecorder ​

Record from the microphone, with a preview

Records a voice note, a comment, or an answer, in the browser, with the native MediaRecorder. People hear the recording before your app uploads it. To play a file, use the audio player. To show the shape of a sound, use the waveform.

Basic

  • Record asks for the microphone. The browser asks for permission only then, not when the page opens.
  • While it records, bars show the loudness, and the clock counts. Pause stops the clock and the recording, and Resume continues the same recording.
  • Stop releases the microphone, sends the recording as a Blob with record, and shows a player for it. Record again starts a new one.
  • maxDuration stops the recording after that many seconds. mimeType asks for a type, for example audio/webm or audio/mp4, if the browser supports it. Otherwise the browser chooses.
  • When there is no microphone or no permission, a line says so, and error sends the reason. Record stays, so people can try again after they allow it.
  • A status line says "Recording", "Paused", and the length when it stops, so a screen reader follows the state. The bars are hidden from screen readers.
  • The microphone needs a secure page (HTTPS or localhost).
  • Change the words with labels or a label pack: the buttons and the status words.

Usage ​

ts
import { BlessAudioRecorder } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
maxDurationnumber—stop by itself after this many seconds
mimeTypestring—a type for MediaRecorder, for example `audio/webm`; used when the browser supports it
barsnumber40level bars drawn while recording
labelsPartial<{ record: string; pause: string; resume: string; stop: string; again: string; recording: string; paused: string; done: string; unavailable: string; }>—

Events

NamePayloadDescription
error[error: unknown]
record[audio: Blob]

Released under the MIT License. Character names and artwork belong to their owners.