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

recorderx

v2.0.2

Published

Record and export audio in the browser via WebRTC api

Downloads

75

Readme

recorderx

Record and export audio in the browser via WebRTC api.

Support output raw, pcm and wav format.

Support Typescript.


English | 简体中文

Check your browser

Demo

Install

NPM

npm install recorderx --sava

Yarn

yarn add recorderx

Quick Start

import Recorderx, { ENCODE_TYPE } from "recorderx";

const rc = new Recorderx();

// start recorderx
rc.start()
  .then(() => {
    console.log("start recording");
  })
  .catch(error => {
    console.log("Recording failed.", error);
  });

// pause recorderx
rc.pause();

// get wav, a Blob
var wav = rc.getRecord({
  encodeTo: ENCODE_TYPE.WAV,
  compressible: true
});

// get wav, but disable compression
var wav = rc.getRecord({
  encodeTo: ENCODE_TYPE.WAV
});

Usage

Recorderx constructor

Creates a recorderx instance

  • recordable: boolean

    Whether to support continuous recording, default to true.

  • sampleRate: number

    Wav sampling rate, default to 16000.

  • sampleBits: number

    Wav sampling bits, default to 16.

    Optional value: 16 or 8

  • bufferSize: number

    The buffer size in units of sample-frames, default to 16384.

    Optional value: 256, 512, 1024, 2048, 4096, 8192, 16384.

interface RecorderxConstructorOptions {
  recordable?: boolean
  bufferSize?: number
  sampleRate?: number
  sampleBits?: number
}

constructor ({ recordable, bufferSize, sampleRate, sampleBits }?: RecorderxConstructorOptions)

Recorderx property

recorder state

enum RECORDER_STATE {
  READY,
  RECORDING
}

readonly state: RECORDER_STATE

AudioContext instance

readonly ctx: AudioContext

Recorderx methods

start recording

audioprocessCallback: The onaudioprocess event handler of the ScriptProcessorNode, refer to MDN

data: current frame audio data

You can do special processing on the audio data of each frame in this callback function

start (audioprocessCallback?: (data: Float32Array) => any): Promise<MediaStream>

pause recording

pause (): void

clear recording buffer

clear (): void

get recording data

Support for exporting WAV, PCM, RAW

  • encodeTo: ENCODE_TYPE

    Export format, default to RAW.

  • compressible: boolean

    Whether to enable compression, default to false.

    • If compression is enabled, the exported WAV, PCM, RAW will be compressed data, and the audio sample rate is the sampleRate passed in when the Recorderx is instantiated.

    • If compression is enabled, the exported WAV, PCM, RAW will be compressed data, and the audio sample rate is the sampleRate passed in when the Recorderx is instantiated.

    • The compression algorithm is based on linear extraction and is distorted at some sample rates.

enum ENCODE_TYPE {
  RAW = 'raw',
  PCM = 'pcm',
  WAV = 'wav'
}

/**
 * Get RAW recording data.
 */
getRecord ({ encodeTo, compressible }?: { encodeTo?: ENCODE_TYPE.RAW, compressible?: boolean }): Float32Array

/**
 * Get PCM recording data.
 */
getRecord ({ encodeTo, compressible }?: { encodeTo?: ENCODE_TYPE.PCM, compressible?: boolean }): ArrayBuffer

/**
 * Get WAV recording data.
 */
getRecord ({ encodeTo, compressible }?: { encodeTo?: ENCODE_TYPE.WAV, compressible?: boolean }): Blob

Audio Tools

import { audioTools } from "Recorderx";

/*
audioTools.merge();
audioTools.compress();
audioTools.encodeToPCM();
audioTools.encodeToWAV();
*/

Merge Float32Array

function merge(bufferList: Array<Float32Array>, length: number): Float32Array;

Compress Float32Array

function compress(
  buffer: Float32Array,
  inputSampleRate: number,
  outputSampleRate: number
): Float32Array;

Convert to PCM

function encodeToPCM(bytes: Float32Array, sampleBits: number): ArrayBuffer;

Convert to WAV

function encodeToWAV(
  bytes: Float32Array,
  sampleBits: number,
  sampleRate: number
): Blob;

Browser Support

All browsers that implement getUserMedia.

WeChat browser is not supported, only Safari is supported under IOS.

For details, please refer to MDN

License

MIT

Else

Audio compression and conversion to wav method reference from recording.