npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@generative-music/web-recorder

v2.0.0

Published

A library for recording web audio systems

Downloads

3

Readme

@generative-music/web-recorder

A library for recording web audio systems.

Usage

This package exports a function which accepts a Piece and optionally a pieceConfig object, a recordingConfig object, and an array of MediaStreamTrack objects.

record()

The default export of this package is a function which creates a recording of a given Piece and returns an RxJS Subscribable object that produces one or more Blob objects containing the recording data.

Syntax

record(piece, pieceConfig, recordingConfig, videoTracks).subscribe(blob => {
  // do something with the blob(s)
});
Parameters
  • piece - The Piece to record.
  • pieceConfig (Optional) - An object passed as an argument to the Piece function. Note that any audioContext and destination properties defined on this object are ignored and overridden by the record function.
  • recordingConfig (Optional) - An object with the following properties:
    • lengthS (Optional) - A number specifying the length, in seconds, of the recording. This can be set to Infinity to record indefinitely. The default value is 0.
    • fadeInS (Optional) - A number specifying the length, in seconds, to fade in the audio at the beginning of the recording. The default value is 0.
    • fadeOutS (Optional) - A number specifying the length, in seconds, to fade out the audio at the end of the recording. The default value is 0.
    • timeslice (Optional) - A number specifying the length, in milliseconds, to record into each Blob. See the timeslice parameter of MediaRecorder.start().
    • mimeType (Optional) - A MIME type to use for the recording. Acceptable values vary per browser. The default value is 'audio/wav'.
  • videoTracks (Optional) - An array of MediaStreamTrack objects to be mixed with the audio and recorded.
Return value

An RxJS Subscribable object which produces one or more Blob objects that contain the recording data. If recordingConfig.timeslice was defined, the recording will be split into separate Blob objects of the specified length (see above). Otherwise, the entire recording will be returned as a single Blob. Each subscription yields a separate recording.

checkSupport()

checkSupport is a named export from this package which can be used to determine whether recording is supported by the environment.

Syntax

checkSupport.then(isSupported => {
  // do something with the result
});
Return Value

A Promise which resolves to true if recording is supported by the environment or false otherwise.

Example

if (record.isSupported) {
  // call record()
} else {
  // record is not supported; exit
}

Examples

Fixed-length recording

This example creates a 10 minute recording with a 30 second fade out of a Piece defined in the file './some-piece.js'.

import record from '@generative-music/web-recorder';
import piece from './some-piece';

record(piece, {}, { lengthS: 10 * 60, fadeOutS: 30 }).subscribe(blob => {
  // got a Blob with the entire recording
});

Indefinite recording

This example creates indefinitely records a Piece defined in the file './some-piece.js' in 1-second chunks. It also passes some extra options to the Piece.

import record from '@generative-music/web-recorder';
import piece from './some-piece';

record(piece, {}, { lengthS: Infinity, timeslice: 1000 }).subscribe(blob => {
  // got a Blob with 1 second of recorded audio
});

Checking for support

This example checks whether record is supported and logs the result.

import record, { checkSupport } from '@generative-music/web-recorder';
import piece from './some-piece';

checkSupport().then(isSupported => {
  if (isSupported) {
    console.log('Recording is supported; okay to call record()');
  } else {
    console.log('Recording is NOT supported');
  }
});

Custom piece configuration

This example passes in a custom pieceConfig object which will be passed to piece defined upon recording.

import record from '@generative-music/web-recorder';
import piece from './some-piece';

const pieceConfig = {
  somePieceOption: true,
};

record(piece, pieceConfig, { lengthS: 20 }).subscribe(blob => {
  // pieceConfig was passed to piece
});