@molecule/app-audio-recording-media-recorder

Provider bond · audio-recording · App (browser) · v1.0.0 · Apache-2.0

Audio recording with the browser MediaRecorder API.

npm install @molecule/app-audio-recording-media-recorder

npm · Source on GitHub · Implements @molecule/app-audio-recording

How it works

@molecule/app-audio-recording-media-recorder is a provider bond on the app (browser) side: it implements the audio-recording core interface (@molecule/app-audio-recording) with a concrete vendor or library behind it.

Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.

import { setProvider } from '@molecule/app-audio-recording'
import { provider } from '@molecule/app-audio-recording-media-recorder'

setProvider(provider)

Works with: @molecule/app-audio-recording, @molecule/app-filesystem

Reference

Audio recording in browsers using a microphone stream and MediaRecorder. Unsupported format preferences use the browser's default encoding. Use a secure origin and start recording in response to a user action.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { setProvider } from '@molecule/app-audio-recording'
import { provider } from '@molecule/app-audio-recording-media-recorder'

setProvider(provider)

Type

provider

Installation

npm install @molecule/app-audio-recording-media-recorder @molecule/app-audio-recording @molecule/app-filesystem

API

Functions

getMediaRecorderOptions(recorder, mimeType)

Negotiates a preferred format before constructing a MediaRecorder.

function getMediaRecorderOptions(
  recorder: typeof MediaRecorder,
  mimeType?: string,
): MediaRecorderOptions | undefined
  • recorder — The browser's MediaRecorder constructor.
  • mimeType — The caller's preferred format.

Returns: Options for a supported preference, or undefined for the browser default.

isMicrophonePermissionError(cause)

Recognizes browser errors that mean microphone access was denied.

function isMicrophonePermissionError(cause: unknown): boolean
  • cause — The failure from the microphone permission request.

Returns: Whether access failed with a browser permission error.

createBrowserAudioRecording(chunks, recorderMimeType, durationSeconds)

Packages recorded chunks for existing Blob consumers and portable uploads.

function createBrowserAudioRecording(
  chunks: Blob[],
  recorderMimeType: string,
  durationSeconds: number,
): AudioRecording
  • chunks — Data emitted by MediaRecorder.
  • recorderMimeType — The format reported by MediaRecorder.
  • durationSeconds — Active recording time in whole seconds.

Returns: The same encoded bytes as a Blob and a portable file.

Constants

provider

Audio recording provider for browsers with MediaRecorder and getUserMedia.

const provider: RecordingProvider

Core Interface

Implements @molecule/app-audio-recording interface.

Bond Wiring

Setup function to register this provider with the core interface:

import { setProvider } from '@molecule/app-audio-recording'
import { provider } from '@molecule/app-audio-recording-media-recorder'

export function setupAudioRecordingMediaRecorder(): void {
  setProvider(provider)
}

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-audio-recording ^1.0.0
  • @molecule/app-filesystem ^1.1.0

Runtime Dependencies

  • @molecule/app-audio-recording
  • @molecule/app-filesystem