Git Product home page Git Product logo

webrtcaec3.js's Introduction

This is a port of WebRTC's AEC3 (acoustic echo cancellation... 3) library to WebAssembly and JavaScript, so that echo cancellation can be performed on any audio, rather than trusting whatever echo cancellation getUserMedia wishes to do.

The Google WebRTC implementation from which this is derived is under a 3-clause BSD license, and so a compiled version of this library falls under the same license. The small amount of glue code provided by this library itself is under the so-called “0-clause BSD license” and does not require attribution. Additionally, library components used by WebRTC are under the Apache 2 license.

API

Include webrtcaec3.js, or import or require this library as a module. Once the library is loaded, WebRtcAec3 is a function which returns a promise for a WebRtcAec3 module instance. With a WebRtcAec3 module instance AEC3, AEC3.AEC3 is a constructor for an AEC3 instance, taking three parameters: the sample rate, and the number of channels for the render (output) and capture (input) streams, respectively. The AEC3 library itself is synchronous, so if you need asynchrony, use it in a WebWorker.

Putting that together:

const AEC3 = await WebRtcAec3();
const aec = new AEC3(sampleRate, outputChannels, inputChannels);

Note that not all sample rates will work. In fact, most won't. Basically, use 48000.

The AEC3 instances expose three methods: analyze, processSize, and process. Use analyze to analyze render (output) data:

aec.analyze(outputData /* Float32Array[] */);

Use process to process capture (input) data, cancelling echo. It deposits the processed data into an output buffer which you must provide. You can use processSize to get the necessary size of each channel of the output buffer.

const bufSz = aec.processSize(inputData);
const outBuf = [new Float32Array(bufSz)]; // one per channel
aec.process(outBuf, inputData /* Float32Array[] */);
... do something with outBuf ...

analyze, processSize, and process each take an optional “options” argument, which in particular can take a sample rate for the input data. If the sample rate for the input data does not match the sample rate with which the AEC3 instance was created, it will be resampled.

For further documentation on each method, see the types file.

webrtcaec3.js's People

Contributors

yahweasel avatar

Stargazers

Noah 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.