1.0.0 • Published 3 months ago

@vonage/noise-suppression v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

@vonage/noise-suppression

Noise-suppression library for web.

Installation

npm i @vonage/noise-suppression

Example

cd example/create-vonage-noise-suppression
# or
cd example/insertable-stream

npm i
npm run start

Usage

// Basic example
import { createVonageNoiseSuppression } from "@vonage/noise-suppression";

/** 
 * Process an audio stream in order to remove noise.
 * Return a new audio stream with processed source.
 */
async function suppressNoiseFromAudioStream(source: MediaStream): MediaStream {
    const processor = createVonageNoiseSuppression();
    await processor.init();
    const connector = await processor.getConnector();
    const track = await connector.setTrack(source.getAudioTracks()[0]);
    const output = new MediaStream();
    output.addTrack(track);
    return output;
}
// Using the transformer with opentok
import { NoiseSuppressionTransformer } from "@vonage/noise-suppression";
import { MediaProcessor, MediaProcessorConnector } from "@vonage/media-processor";


/** 
 * Create an OpenTok session with noise suppression audio processor piped
 */
async function initSessionWithNoiseSuppression() {
    // Processor init
    const processor = createVonageNoiseSuppression();
    await processor.init();
    const connector = await processor.getConnector();
    
    // OT init
    const session = OT.initSession(apiKey, sessionId);
    const publisher = OT.initPublisher('publisher', {}, handleError);
    await publisher.setAudioMediaProcessorConnector(noiseSuppressionConnector);

    session.connect(token, (error) => {
        if (error) {
            handleError(error);
        } else {
            publisher.setAudioMediaProcessorConnector(noiseSuppressionConnector);
        }
    });
}
// Using the transformer with @vonage/media-processor
import { NoiseSuppressionTransformer } from "@vonage/noise-suppression";
import { MediaProcessor, MediaProcessorConnector } from "@vonage/media-processor";


/** 
 * Process a audio stream in order to remove noise.
 * Return a new audio stream with processed source.
 */
async function suppressNoiseFromAudioStream(source: MediaStream): MediaStream {
    const processor = new MediaProcessor();
    const transformer = new NoiseSuppressionTransformer();
    await transformer.init();
    await processor.setTransformers([
        transformer,
        // my other audio transformers
    ])
    const connector = new MediaProcessorConnector(processor);
    const track = await connector.setTrack(source.getAudioTracks()[0]);
    const output = new MediaStream();
    output.addTrack(track);
    return output;
}

Multithreaded wasm

Enabling WebAssembly multithreading can significantly boost the performance by harnessing the power of multiple CPU cores. To enable this feature, users must allow shared array buffers, which come with specific security prerequisites.

These prerequisites include:

  • Serving your web application over HTTPS for secure data transmission.
  • Setting the 'Cross-Origin-Opener-Policy' header to 'same-origin' to restrict execution contexts to trusted sources.
  • Setting the 'Cross-Origin-Embedder-Policy' header with 'require-corp' or 'credentialless' values to ensure secure usage of shared array buffers.

By default, the library will try to start the wasm in multithreaded mode and will print a warning message if the security conditions did not match. You can disable this message by disabling multithreading manually using the proper option.

// Using the helper
 const processor = createVonageNoiseSuppression();
 await processor.init({
    disableWasmMultiThread: true
 });

// Using the transformer
const transformer = new NoiseSuppressionTransformer();
await transformer.init({
    disableWasmMultiThread: true
 });

Hosting the static resources

In order to reduce the impact of the library until it is used, worker, wasm and model are loaded dynamically when the transformer is created.

These resources are served by default by Vonage CDN, but could be provided from a custom server.

You can specify the server url as an option of the transformer.

// Using the helper
 const processor = createVonageNoiseSuppression();
 processor.init({
    assetsDirBaseUrl: "https://my-custom-server/path/to/the/resources/root"
 });

// Using the transformer
const transformer = new NoiseSuppressionTransformer();
transformer.init({
    assetsDirBaseUrl: "https://my-custom-server/path/to/the/resources/root"
 });

Documentation

Replace version with the expected version documentation: https://vonage.github.io/client-media-processing-docs/noise-suppression/{VERSION}/

1.0.0

3 months ago

1.0.0-beta.9

5 months ago

1.0.0-beta.8-dev.1

5 months ago

1.0.0-beta.8

5 months ago

1.0.0-beta.7

5 months ago

1.0.0-beta.6

6 months ago

1.0.0-beta.5

6 months ago

1.0.0-beta.4

6 months ago

1.0.0-beta.3

6 months ago

1.0.0-beta.2

7 months ago

1.0.0-beta.1

7 months ago

1.0.0-alpha.2

8 months ago

1.0.0-alpha.1

8 months ago