0.1.1 • Published 4 years ago

psittacus v0.1.1

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

Psittacus

Build Status

Instruction

psittacus is a simple library to recorder audio in browser.

Preparation

Before use it, you should known some knowledge of Audio format.

Audio Format

Common audio formats like wav, ogg, pcm, mp3 is a 'container' which means it is used to store codecs and data of audio.

Sample Rate

The rate of capture and playback is called the sample rate.

Bit Depth

The number of bits used to describe each sample is called the bit depth.

Bit Rate

The number of bits transmitted per second is the bit rate.

 bitRate = bitDepth * sampleRate

https://www.presonus.com/learn/technical-articles/sample-rate-and-bit-depth

Channels

Sound Channel refers to the independent audio signal which is collected or playback when the sound is recording or playback in different spatial position. Therefore, the number of channel is the amount of sound source when the sound is recording or the relevant speaker number when it is playback

https://www.gearbest.com/blog/how-to/6-types-of-sound-channels-2896

MediaRecorder VS AudioContext

By default, psittacus use AudioContext as default. This is because. :point_down:

MediaRecorder

  • there’s no bitrate control

  • there’s no sample rate or audio quality control

  • .webm files (with Vorbis/Opus audio and VP8/VP9 video) will have to be converted before they playback on virtually anything else other than the browsers they were recorded in

HTML5’s Media Recorder API in Action on Chrome and Firefox

Audio Information

There is a table made by Remus Negrota.

nameCHROME 49+CHROME 52+FIREFOX 30 AND UP
Containerwebmwebmwebm
Audio codecOpusOpusVorbis
Sample rate48kHz48kHz44.1 kHz

webm is an open source format that contains video compressed with VP8 or VP9 codecs and audio compressed with Vorbis or Opus codecs. The format is usually used for media content on web pages and it is supported by all the popular web-browser.

AudioContext

Audio context can let user to control the sample rate and bit rate in recording. For compatibility and flexibility, psittacus use ScriptProcessorNode instead AudioWorkletProcessor by default.

Reference

MDN-MediaStreamAudioSourceNode

MDN-AudioContext

Usage

psittacus is an simple library for web recording. You only have to learn six methods: open, start, pause, resume, stop, clear.

Crash Course

ES6

   import Psittacus from 'Psittacus'

   let recorder = new Psittacus();
   recorder.start();

   recorder.stop();

   recorder.export('wav',async (blob)=>{
       const url = URL.createObjectURL(object);

       // Use <audio></audio> to play it.
       audio.src = url;

       // Get binary data of audio
       const binary = await blob.arrayBuffer()
   })

See examples for more details.

API

constructor(config)

Initialize a psittacus instance.

config

{
  method: "AudioContext"
  type: "wav",
  bufferSize: 4096,
  sampleRate: 16000,
}

example:

const recorder = new fast({
    method: "AudioContext",
});

start()

Start Recording.

example:

recorder.start();

stop()

Stop Recording.

example:

recorder.stop(cb)

url is an object url.

pause()

Pause Recording.

example:

recorder.pause();

resume()

Resume Recording.

example:

recorder.resume();

export(audioType, callback)

Export specified format audio.

audioType

'wav'|'pcm'

callback

function(blob). Get a blob object.

example

recorder.export('wav',cb);
0.1.1

4 years ago

0.1.0

4 years ago