openwakeword-js 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,104 +1,115 @@
1
1
  # openWakeWord-JS
2
2
 
3
- **The precision JavaScript/TypeScript port of openWakeWord.**
3
+ **The high-performance, precision JavaScript/TypeScript port of openWakeWord.**
4
4
 
5
- A high-accuracy, 100% logic-aligned port of [openWakeWord](https://github.com/dscripka/openWakeWord). Designed for browser-first execution using ONNX Runtime Web, with Node.js support.
5
+ [![NPM Version](https://img.shields.io/npm/v/openwakeword-js.svg)](https://www.npmjs.com/package/openwakeword-js)
6
+ [![License](https://img.shields.io/npm/l/openwakeword-js.svg)](https://github.com/Firojpaudel/OpenWakeWord_npm_porting/blob/main/LICENSE)
6
7
 
7
- ## Credits & Acknowledgments
8
- This package is a JavaScript port of the work by David Scripka.
9
- [Original openWakeWord Repository](https://github.com/dscripka/openWakeWord)
8
+ A high-accuracy, 100% logic-aligned port of [openWakeWord](https://github.com/dscripka/openWakeWord). This implementation is designed to match the original Python behavior bit-for-bit, ensuring that your custom models perform exactly as they did in training.
10
9
 
11
10
  ---
12
11
 
13
- ## Getting Started (Technical Overview)
12
+ ## Technical Features
14
13
 
15
- To use this package, you need to understand the main directories:
16
- 1. **`node_modules/`**: Created automatically when you run `npm install`. Contains all the external libraries (like ONNX Runtime) that this package needs to run.
17
- 2. **`dist/`**: Created when you run `npm run build` (or provided by the NPM package). It contains the compiled "ready-to-use" JavaScript files.
18
- 3. **`models/`**: You must create this folder and put the required `.onnx` and `.wasm` files inside it.
19
-
20
- ### Required Model Assets
21
- You need at least three models to detect a wake word:
22
- - `melspectrogram.onnx`: Audio feature extractor.
23
- - `embedding_model.onnx`: Feature embedding generator.
24
- - **Your Custom Model**: (e.g., `hey_deepa.onnx`). The specific phrase model.
25
- - `silero_vad.onnx` (Optional): Voice Activity Detection for improved accuracy.
26
-
27
- > [!NOTE]
28
- > You can generate your own custom wake word models using this [Kaggle Notebook Link](https://www.kaggle.com/code/firojpaudel/deepa-wise).
14
+ - **Signal Parity**: Matches the original Python Mel spectrogram transforms (linear `x/10 + 2` scaling) and log-mel clamping.
15
+ - **Sliding Window Inference**: Implements the required 76-frame mel context for embeddings and 24-frame embedding context for classifiers.
16
+ - **Privacy First**: 100% local execution. No audio data ever leaves the user's device.
17
+ - **Hardware Acceleration**: Optimized via ONNX Runtime Web using WebAssembly (WASM) with SIMD and Multi-threading.
18
+ - **VAD Integration**: Optional Silero VAD gating to reduce CPU usage and prevent false triggers in silence.
29
19
 
30
20
  ---
31
21
 
32
- ## Installation & Setup
22
+ ## Step-by-Step Setup Guide
23
+
24
+ For a developer to recreate the full pipeline from scratch, follow these exact steps:
33
25
 
34
- ### 1. Install the package
26
+ ### 1. Installation
27
+ In your project directory, install the core library and the ONNX runtime:
35
28
  ```bash
36
29
  npm install openwakeword-js onnxruntime-web
37
30
  ```
38
31
 
39
- ### 2. Prepare the `models/` folder
40
- Create a folder named `models` in your project's root. You need the `.onnx` models there.
32
+ ### 2. Automatic Asset Initialization
33
+ Run this command from your project root to automatically download the base models and copy the required WebAssembly binaries:
41
34
 
42
- **Automated Setup:**
43
- Run this command to automatically download the base models (`melspectrogram`, `embedding`, and `silero_vad`) from the original repository:
44
35
  ```bash
45
- npm run download-models
36
+ npx openwakeword-js-setup
46
37
  ```
47
38
 
48
- **Manual Setup:**
49
- If you prefer to download them manually, make sure these files are in your `models/` folder:
50
- - `melspectrogram.onnx`
51
- - `embedding_model.onnx`
52
- - `silero_vad.onnx` (Optional but recommended)
53
- - **Your custom wake word model** (e.g., `hey_deepa.onnx`)
54
-
55
- **Browser Requirements:** Browsers need the `.wasm` (WebAssembly) files to run the models at high speed.
56
- - The `npm run download-models` command automatically copies these for you from `node_modules`.
57
- - Alternatively, you can use a CDN by setting the `wasmPaths` in the constructor.
39
+ ### 3. Training & Models
40
+ You will need a specific wake word model (classifier) for your chosen phrase.
41
+ - **Download Official Models**: You can find many pre-trained `.onnx` models (like `alexa.onnx`) in the [original repository](https://github.com/dscripka/openWakeWord).
42
+ - **Train Your Own**: Use this [Kaggle Notebook](https://www.kaggle.com/code/firojpaudel/deepa-wise) to train a custom model for any word, then download the exported `.onnx` file and put it in your `./models/` folder.
58
43
 
59
44
  ---
60
45
 
61
- ## Browser Demo
46
+ ## The Execution Pipeline
62
47
 
63
- A minimal browser implementation is provided in the `example/index.html` file. You can use it as a reference for handling microphone input and displaying scores.
48
+ Understanding how the data flows helps in debugging and implementation:
64
49
 
65
- To run the demo locally:
66
- 1. Install dependencies: `npm install`
67
- 2. Download models: `npm run download-models`
68
- 3. Serve the project: `npx serve .` (or any static file server)
69
- 4. Open `http://localhost:3000/example/index.html`
50
+ 1. **Audio In**: Feed 16kHz Mono audio chunks (typically 1280 samples / 80ms).
51
+ 2. **Mel Processing**: The library converts audio into Mel Spectrograms using `melspectrogram.onnx`.
52
+ 3. **Embedding Generation**: Every 8 Mel frames (shifted) generates one Embedding vector via `embedding_model.onnx`.
53
+ 4. **Classification**: Your custom model looks at a window of 24 embeddings to decide if the word was spoken.
70
54
 
71
55
  ---
72
56
 
73
- ## Usage Example
57
+ ## Usage Example (TypeScript / JavaScript)
74
58
 
75
59
  ```typescript
76
60
  import { Model } from 'openwakeword-js';
77
61
 
62
+ // Configuration
78
63
  const model = new Model({
64
+ // 1. Path to your phrase model (e.g., from Kaggle or Official repo)
79
65
  wakewordModels: ['./models/my_custom_model.onnx'],
66
+
67
+ // 2. Paths to the feature extraction models (created by download-models)
80
68
  melspectrogramModelPath: './models/melspectrogram.onnx',
81
69
  embeddingModelPath: './models/embedding_model.onnx',
82
70
 
83
- // Optional VAD for better accuracy in noisy environments
71
+ // 3. Optional VAD config
84
72
  vadModelPath: './models/silero_vad.onnx',
85
73
  vadThreshold: 0.5,
86
74
 
87
75
  inferenceFramework: 'onnx',
88
76
 
89
- // Browser ONLY: Direction to WASM files
77
+ // 4. Direction to WASM binaries (required for browser context)
90
78
  wasmPaths: './models/'
91
79
  });
92
80
 
81
+ // Initialize (Downloads/Loads models into memory)
93
82
  await model.init();
94
83
 
95
- // Feed 1280 samples of 16kHz mono audio
96
- const scores = await model.predict(audioChunk);
97
- console.log(scores);
84
+ /**
85
+ * Feed audio chunks.
86
+ * inputData can be a Float32Array (normalized -1 to 1)
87
+ * or an Int16Array (raw PCM 16-bit).
88
+ */
89
+ const scores = await model.predict(inputData);
90
+
91
+ // Output format: { "my_custom_model": 0.85 }
92
+ if (scores["my_custom_model"] > 0.5) {
93
+ console.log("Wake word detected locally!");
94
+ }
98
95
  ```
99
96
 
100
- ## Privacy
101
- Voice processing runs entirely on the user's local machine. No audio data is transmitted to external servers.
97
+ ---
98
+
99
+ ## Local Development & Demo
100
+
101
+ We have included a full working example in the `example/` folder.
102
+
103
+ 1. Clone the repo and run `npm install`.
104
+ 2. Run `npm run download-models`.
105
+ 3. Serve the root directory using a static server (e.g., `npx serve .`).
106
+ 4. Navigate to `http://localhost:3000/example/index.html`.
107
+ 5. Allow Microphone access and watch the real-time scores.
108
+
109
+ ---
110
+
111
+ ## Credits
112
+ This package is a JavaScript port of the work by **David Scripka**. We encourage support for the original project's research and model training infrastructure.
102
113
 
103
114
  ## License
104
115
  Apache-2.0
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "openwakeword-js",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Port of openWakeWord to JavaScript/TypeScript using ONNX Runtime",
5
+ "bin": {
6
+ "openwakeword-js-setup": "scripts/download_models.js"
7
+ },
5
8
  "main": "dist/index.js",
6
9
  "module": "dist/index.mjs",
7
10
  "types": "dist/index.d.ts",
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  import fs from 'fs';
2
3
  import path from 'path';
3
4
  import https from 'https';