npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vonage/noise-suppression

v1.0.0

Published

Noise-suppression library for web.

Downloads

2,108

Readme

@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}/