3.0.3 • Published 8 months ago

rustpotter-worklet v3.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

Rustpotter Worklet

Description

Run Rustpotter (an open source wake word spotter forged in rust) in the browser as an AudioWorkletProcessor.

This package exposed a RustpotterService class that you can use to create and communicate with a worklet that runs rustpotter on its thread.

The RustpotterService should be able to download the code for the worklet and the rustpotter wasm module, by default it assumes the files "/rustpotter-worker.js", "/rustpotter-worklet.js" and "/rustpotter_wasm_bg.wasm" are available for download.

Basic Usage Example

    import { RustpotterService } from "rustpotter-worklet";
    // Urls to the requires sources
    const wasmModuleUrl = new URL('../node_modules/rustpotter-worklet/dist/rustpotter_wasm_bg.wasm', import.meta.url);
    const workletUrl = new URL('../node_modules/rustpotter-worklet/dist/rustpotter-worklet.js', import.meta.url);
    const workerUrl = new URL('../node_modules/rustpotter-worklet/dist/rustpotter-worker.js', import.meta.url);
    // Init audio context
    const audioContext = new AudioContext();
    const rustpotter = await RustpotterService.new({
        workletPath: workletUrl.href,
        workerPath: workerUrl.href,
        wasmPath: wasmModuleUrl.href,
        averagedThreshold: 0.25,
        threshold: 0.5,
        sampleRate: audioContext.sampleRate
    });
    rustpotter.onDetection(d => console.log(d));
    rustpotter.addWakewordByPath("/static/wakeword.rpw");
    let rustpotterWorklet = rustpotter.getNodeProcessor();
    // get media stream source node (requires user interaction event)
    const stream = await navigator.mediaDevices.getUserMedia({
        audio: {
            autoGainControl: true,
            echoCancellation: true,
            noiseSuppression: true,
        },
        video: false,
    });
    const sourceNode = audioContext.createMediaStreamSource(stream);
    // chain rustpotter audio processor
    sourceNode.connect(rustpotterWorklet);
    ...
    // If you need to recreate the worklet because the audio streaming was interrupted
    rustpotter.disposeNodeProcessor();
    rustpotterWorklet = rustpotter.getNodeProcessor();
    ...
    // If you want to dispose rustpotter
    rustpotter.close();
3.0.0-beta.5

9 months ago

3.0.0-beta.7

8 months ago

3.0.3

8 months ago

3.0.2

8 months ago

3.0.1

8 months ago

3.0.0-rc.1

8 months ago

3.0.0-rc.0

8 months ago

3.0.0

8 months ago

3.0.0-beta.5.1

8 months ago

3.0.0-beta.5.2

8 months ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.16.0

2 years ago

0.14.4

2 years ago

0.13.1

2 years ago

0.12.3

2 years ago

0.12.2

2 years ago

0.12.1

2 years ago

0.10.2

2 years ago

0.10.1

2 years ago

0.9.1

2 years ago