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

recording-audio-engine

v0.0.4

Published

A simple library that handles the Audio Context by providing lots of convenience functions.

Downloads

23

Readme

Audio Engine

A simple and small (under 2kB gzipped, currently) library that specializes in simple audio input / output and marshalling to various audio formats by wrapping the browser's Audio Context and providing a bunch of convenience functions. Currently only supports mono audio. See the TODO section below for more explanation.

Usage

npm install --save recording-audio-engine

Check out the example/ folder for a decent example. Here is a basic use case:

import { Recording } from 'recording-audio-engine'

// start recording with max length of 5 seconds
Recording.startRecording(5).then(recording => {
  recordings.push(recording) // add recording to store
  console.log('recording as encoded wav blob', recording.wavBlob)
  console.log('recording as audio buffer', recording.audioBuffer)
  console.log('recording as Float32Array', recording.rawData)
})

function handleStopRecordingImmediately() {
  Recording.stopRecording()
}

function handleRecordingPlay(recording) {
  recording.play().then(() => {
    console.log('recording just finished playing!')
  })
}

function handleStopPlayingImmediately(recording) {
  recording.stop()
}

Note: This library does concern itself with managing a complicated state. Basically you have to manage all of that yourself. When the 'startRecording promise' resolves (either it reached the timeout you set OR you called .stopRecording()), it provides the recording. You just have to do something with it, as in the above example.

You can also create your own recording objects (for example, maybe you downloaded a file from the internet):

import { MonoRecording } from 'recording-audio-engine'
const recording = new Recording(new Float32Array([1, 2, 3, 4]), 44100)
const automaticallyEncodedWavBlob = recording.wavBlob

In the above example, the sampling rate is optional. It will default to your browser's default sampling rate if you don't set it.

It provides a single running instance of the browser's AudioContext. If you still need to use it for some reason, you can access it without creating a new one:

import { AudioContextInstance } from 'recording-audio-engine'
console.log('sample rate is', AudioContextInstance.sampleRate)

Finally, it comes with some utils.

import { Utils } from 'recording-audio-engine'
import axios from 'axios'
axios
  .get('www.example.com/audio.wav', { responseType: 'arraybuffer' })
  .then(res => Utils.decodeAudioData(res.data))
  .then(res => new MonoRecording(res.getChannelData(0)))
import { Utils } from 'recording-audio-engine'
const synthesizedRecording = Utils.makeSynthesizedMonoRecording([
  monoRecording1,
  monoRecording2,
  monoRecording3
])
import { Utils } from 'recording-audio-engine'
const fileAsString = await exportBlobAsBase64(wavFileBlob)

Dev

TODO:

  • have an example project that uses the lib for development purposes
  • Support multi-channel everywhere: As this was developed out of projects that make use of the microphone, the MVP was built around mono audio. Some parts are built with multi-channel in mind but the API will assume mono until the whole code base has multi-channel support.

Note about tests

  • I'm using karma for tests (as opposed to the much more light weight and easy to use jest) because it runs tests in the browser as opposed to node. This is important for this project because it relies heavily on the Web Audio API. There are various libraries for mocking the Web Audio API in node but none of these suffice for the type of tests that I want to write (and many are incomplete...)
npm run test # run tests once
npm run test:dev # run tests in watch mode