|
1 | | -# web-voice-processor |
2 | | -a framework for real-time voice processing in web browsers |
| 1 | +# Web Voice Processor |
| 2 | + |
| 3 | +Made in Vancouver, Canada by [Picovoice](https://picovoice.ai) |
| 4 | + |
| 5 | +This is a library for real-time voice processing in web browsers. |
| 6 | + |
| 7 | +* Uses [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker) to offload compute-intensive work to background |
| 8 | +threads. |
| 9 | +* Converts the microphone sampling rate to 16000 which is used by (almost all) voice processing engines. |
| 10 | +* Provides a flexible interface to pass in arbitrary voice processing workers. |
| 11 | + |
| 12 | +## Compatibility |
| 13 | + |
| 14 | +The library makes use of [Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API), which is |
| 15 | +supported on all modern browsers except Internet Explorer. |
| 16 | + |
| 17 | +## How to Install |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install web-voice-processor |
| 21 | +``` |
| 22 | + |
| 23 | +## How to Use |
| 24 | + |
| 25 | +Add the following to your HTML |
| 26 | + |
| 27 | +```html |
| 28 | +<script src="{PATH_TO_WEB_VOICE_PROCESSOR_JS}"></script> |
| 29 | +``` |
| 30 | + |
| 31 | +Replace `{PATH_TO_WEB_VOICE_PROCESSOR_JS}` with the path to [src/web_voice_processor.js](/src/web_voice_processor.js). |
| 32 | + |
| 33 | +The library adds `WebVoiceProcessor` as a singleton to the global scope. |
| 34 | + |
| 35 | +### Start Processing |
| 36 | + |
| 37 | +Start processing |
| 38 | + |
| 39 | +```javascript |
| 40 | +window.WebVoiceProcessor.start(engines, downsamplerScript, errorCallback) |
| 41 | +``` |
| 42 | + |
| 43 | +`engines` is a list of voice processing [Workers]((https://developer.mozilla.org/en-US/docs/Web/API/Worker)) |
| 44 | +implementing the following interface within their `onmessage` method |
| 45 | + |
| 46 | + |
| 47 | +```javascript |
| 48 | +onmessage = function (e) { |
| 49 | + switch (e.data.command) { |
| 50 | + |
| 51 | + ... |
| 52 | + |
| 53 | + case 'process': |
| 54 | + process(e.data.inputFrame); |
| 55 | + break; |
| 56 | + |
| 57 | + ... |
| 58 | + |
| 59 | + } |
| 60 | +}; |
| 61 | +``` |
| 62 | + |
| 63 | +where `e.data.inputFrame` is an `Int16Array` of 512 audio samples. |
| 64 | + |
| 65 | +`downsamplerScript` is the path to [downsampling_worker.js](/src/downsampling_worker.js) relative to HTML file. |
| 66 | + |
| 67 | +The `errorCallback` is executed if audio acquisition fails. |
| 68 | + |
| 69 | +### Stop Processing |
| 70 | + |
| 71 | +Stop processing |
| 72 | + |
| 73 | +```javascript |
| 74 | +window.WebVoiceProcessor.stop() |
| 75 | +``` |
| 76 | + |
0 commit comments