Git Product home page Git Product logo

ogg-vorbis-encoder-js's Introduction

OggVorbisEncoder.js

What is it?

OggVorbisEncoder.js is a JavaScript library that encodes audio data to Ogg Vorbis on web browsers.

libogg and libvorbis are used for encoding engine. Emscripten is used to convert libogg/libvorbis C code into JavaScript.

Acknowledgement

It was originally a fork of https://github.com/Garciat/libvorbis.js (and also its ancestors). API has been totally re-designed and simplified. Now it has been a lower layer part of WebAudioRecorder.js.

Demo

https://boo-higuma.ssl-lolipop.jp/gh-pages/ogg-vorbis-encoder-js/

Library files

lib/ contains library files.

  • OggVorbisEncoder.js: JavaScript library (uncompressed)
  • OggVorbisEncoder.min.js: JavaScript library (minified)
  • OggVorbisEncoder.min.js.mem: memory initializer data for OggVorbisEncoder.min.js

Using library

Uncompressesd library is a single file. You can use it from both HTML and Web Worker.

  • from HTML: <script src="javascripts/OggVorbisEncoder.js"></script>
  • from Worker: importScripts("javascripts/OggVorbisEncoder.js");

Using minified library is same way. But you must pay attention to memory initializer location.

  • from HTML: default directory is same as HTML which loads OggVorbisEncoder.min.js
  • from Worker: default directory is same as OggVorbisEncoder.min.js path

To change memory initializer path from HTML:

<script>
// default path is on the same directory as this HTML
OggVorbisEncoderConfig = {
  memoryInitializerPrefixURL: "javascripts/"   // must end with slash
  // => changed to javascripts/OggVorbisEncoder.min.js.mem
};
</script>
<script src="javascripts/OggVorbisEncoder.min.js"></script>

From Worker:

// default path is on the same directory as OggVorbisEncoder.min.js
self.OggVorbisEncoderConfig = {
  memoryInitializerPrefixURL: "javascripts/memory/"
  // => changed to javascripts/memory/OggVorbisEncoder.min.js.mem
};
importScripts("javascripts/OggVorbisEncoder.min.js");

API

encoder = new OggVorbisEncoder(sampleRate, numChannels, quality)

Create an encoder object.

  • Parameters
    • samleRate: sampling rate [Hz]
    • numChannels: number of audio channels
    • quality: Vorbis quality (-0.1 <= quality <= 1)
  • Returns
    • encoder object

Current implementation supports VBR encoding only.

encoder.encode(buffers)

Encode audio buffers.

  • Parameters
    • buffers: array of sample buffers ([Float32Array, Float32Array ...])
  • Returns
    • (none)

buffers must be an array of Float32Array audio data (range = [-1, 1]). Array length must be same as number of channels. It supports stream (incremental) processing. Sample buffers are processed to Ogg Vorbis stream and appended to internal data.

blob = encoder.finish([mimeType])

Finish encoding and get Ogg Vorbis as a Blob.

  • Parameters
    • mimeType(optional): MIME type (default = "audio/ogg")
  • Returns
    • Blob object

After calling .finish(), all internal data is cleared (to avoid resource leak). You must create a new encoder object to encode another audio data.

encoder.cancel()
  • Parameters
    • (none)
  • Returns
    • (none)

Cancel encoding and clear all internal data.

You should call .cancel() manually to avoid resource leak when recording is canceled (encoder's internal memory is not deallocated by unbinding an object variable).

Build

Emscripten and ruby are required to build the library.

$ rake

Download and extract libogg + libvorbis, build library files (see Rakefile for more details).

License

libogg and libvorbis are released under Xiph's BSD-like license below. JavaScript-converted part of this library follows the same license.

http://www.xiph.org/licenses/bsd/

C and JavaScript wrapper API part of this library is released under MIT licence (see LICENSE.txt).

ogg-vorbis-encoder-js's People

Contributors

higuma avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.