New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

opus-encode

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opus-encode

Encode audio buffer streams to ogg opus.

latest
Source
npmnpm
Version
2.0.2
Version published
Maintainers
1
Created
Source

#opus-encode

Encode audio buffer streams to ogg opus. AFAIK, this only works in the browser.

##Installation

npm install --save opus-encode

##Usage

var concat = require('concat-stream');
var encode = require('opus-encode');
var stream = require('stream');

// request an audio file
var req = new XMLHttpRequest();
req.open('GET', '/path/to/file.wav', true);
req.responseType = 'arraybuffer';

req.onload = function () {
  var res = req.response;
  var ctx = new AudioContext();

  // decode the file to audio buffers
  ctx.decodeAudioData(res, function (buf) {
    var audio = new stream.Readable({objectMode: true});

    // convert the audio buffers to an object stream
    audio._read = function () {
      this.push(buf);
      this.push(null);
    };

    // create a stream that concats all encoded data
    var doSomething = concat(function (buf) {
      // this blob contains the ogg opus encoded audio
      var blob = new Blob([buf.toArrayBuffer()]);
    });

    audio.pipe(encode()).pipe(doSomething);
  });
};

req.send();

##Disclaimer

I don't pretend to understand how the encoder actually works. I modified the encoder written by chris-rudmin in his fork of RecordJS.

##Tests

In order to run tests in the browser make sure you open your browser with the following flag:

--allow-file-access-from-files

Keywords

api

FAQs

Package last updated on 20 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts