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

@aikuma/webaudio

v0.4.0

Published

Aikuma Microphone and WebPlayer Library

Downloads

22

Readme

Aikuma Web Audio javascript library

Web Audio-based library created for use with language apps/sites.

  • Microphone library
  • Web Audio player library
  • ES6 module with Typescript definitions
  • Repo has client testing framework (work in progress)

Microphone

  • Web Audio microphone
  • Records audio segments to support undo operations
  • Segments are resampled to given supplied sample rate
  • Supports wav export of segments or entire recording (all segments)
  • Simple fade in/out to avoid start/stop clicking
  • Microphone recording time observable (decoupled from script processor node)
  • Exports as Wav Blob
  • Basic playback
  • Experimental: Stores raw PCM audio to indexeddb to minimize RAM usage (with service worker)

Web Audio Player

  • Web Audio player service
  • Intended for large files and random playback seek position
  • Playback progress time observable (decoupled from script processor node)

Developer documentation

how to build and test:

  • clone the repository
  • in the cloned folder, run npm install
  • run npm test to build and test the code in both nodejs and browser

how to debug (browser):

  • run npm start to run a development server
  • open http://localhost:8080/webtest.bundle to run live tests that will update while you change the source code

Based on https://github.com/wix/typescript-boilerplate

Microphone documentation

API example

import { Microphone } from '@aikuma/webaudio'
const mic = new Microphone({debug: true, resampleRate: 16000})
mic.observeProgress().subscribe((time) => {
  console.log('time:',time)
})
mic.record()
...
mic.stop().then(() => {
  wavblob = mic.exportAllWav()
})

Constructor

const mic = new Microphone(config)

Config is optional. Valid config properties are bufferLen (number) defaulting to 8192, numChannels (number) defaulting to 1, and sampleRate (number) defaulting to 16,000, debug (boolean) defaulting to false and experimentalStorage (boolean) defaulting to false.

Methods

connect()

Requests microphone access via getUserMedia() and creates a MediaStreamSourceNode. Throws an error if either operation fails. connect() must be performed before other methods.

record()

Begins recording audio. A service worker will write raw pcm audio to persistent storage. This data will be the native sample rate of the audio context, usually 48,000.

record() will throw an error if the service is not ready to record (you should check canRecord() first), or there is no source node (usually because connect() has not been called yet).

destroy()

Stops the audio stream and completes the progress observable.

getElapsed()

Returns a number in milliseconds which is calculated from the samples in the final buffers plus a temporary timer for temporary buffers.

isRecording()

Returns a boolean representing current recording state.

isPlaying()

Returns a boolean that is true if the built-in player is currently playing.

hasRecordedData()

Returns a boolean which is true if there is some recorded data.

observeProgress()

Returns an RXJS Observable which emits record progress in milliseconds as recording progresses.

pause()

Returns a Promise which completes if not currently recording, or otherwise when the recorder is finished recording. This is an async operation because buffers need to be emptied.

canRecord()

Returns a boolean which is true if the recorder can record. It will be false if, for example, the recorder is currently waiting to stop, e.g. following pause().

resume()

This continues recording of the same segment.

stop()

Stop recording the current segment. Returns a Promise that resolves when the operation is complete. This is asynchronous because buffers needed to be cleared and because the raw samples will be fetched from the service worker and resampled. The list of recording segments will have this resampled segment appended.

getLastLength()

Returns information on the last recorded segment. The object has offset, frames and ms properties which are all numbers. Offset represents the offset time from the beginning of the first segment, in milliseconds. frames and ms represent duration in absolute frames (samples) and milliseconds respectively.

getTotalLength()

Returns an object with frames and ms properties. frames and ms represent duration of all segments in absolute frames (samples) and milliseconds respectively.

getSegmentCount()

Returns the number if recorded segments.

clear()

Resets the microphone service. Recording is stopped. All temporary buffers and segments are cleared.

playSegment(segment: number)

Plays the given segment. Throws an error if the segment is out of range. Returns a Promise that resolves when the playback is complete.

exportSegmentWav(segment: number)

A synchronous operation that returns an audio Wav Blob of the given recorded segment. Throws an error if the segment is out of range.

exportAllWav()

A synchronous operation that returns a Wav Blob of all of the segments concatenated.

To Do

  • Add web audio player docs
  • Add tests for web audio player