
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
vosk-browser
Advanced tools
Kaldi in-browser speech recognition based on a WASM build of the Vosk library
A somewhat opinionated speech recognition library for the browser using a WebAssembly build of Vosk
Checkout the demo running in-browser speech recognition of microphone input or audio files in 13 languages.
You can install vosk-browser as a module:
$ npm i vosk-browser
You can also use a CDN like jsdelivr to add the library to your page, which will be accessible via the global variable Vosk:
<script type="application/javascript" src="https://cdn.jsdelivr.net/npm/vosk-browser@0.0.3/dist/vosk.js"></script>
One of the simplest examples that assumes vosk-browser is loaded via a script tag. It loads the model named model.tar.gzlocated in the same path as the script and starts listening to the microphone. Recognition results are logged to the console.
async function init() {
const model = await Vosk.createModel('model.tar.gz');
const recognizer = new model.KaldiRecognizer();
recognizer.on("result", (message) => {
console.log(`Result: ${message.result.text}`);
});
recognizer.on("partialresult", (message) => {
console.log(`Partial result: ${message.result.partial}`);
});
const mediaStream = await navigator.mediaDevices.getUserMedia({
video: false,
audio: {
echoCancellation: true,
noiseSuppression: true,
channelCount: 1,
sampleRate: 16000
},
});
const audioContext = new AudioContext();
const recognizerNode = audioContext.createScriptProcessor(4096, 1, 1)
recognizerNode.onaudioprocess = (event) => {
try {
recognizer.acceptWaveform(event.inputBuffer)
} catch (error) {
console.error('acceptWaveform failed', error)
}
}
const source = audioContext.createMediaStreamSource(mediaStream);
source.connect(recognizerNode);
}
window.onload = init;
The library loads models as gzipped tar archives of a model folder following the model structure expected by Vosk.
new Model(modelUrl: string): Model
The Model constructor. Creates a new Model that will spawn a new Web Worker in the background. modelUrl can be a relative or absolute URL but be aware that CORS also applies to Workers. As Model initialization can take a while depending on the model size, you should either wait for the load event or use the createModel function.
ready: boolean;
A property that specifies if the model is loaded and ready.
new model.KaldiRecognizer(): KaldiRecognizer
Creates a new KaldiRecognizer. Multiple recognizers can be created from the same model
setLogLevel(level: number): void
Sets the log level: -2: Error -1: Warning 0: Info 1: Verbose 2: More verbose 3: Debug
terminate(): void
Will terminate the Web Worker as well as free all allocated memory. Make sure to call this method when you are done using a model in order to avoid memory leaks. The method will also remove all existing KaldiRecognizer instances.
A Model will also emit some useful events:
.on('load', function(message: {
event: "load";
result: boolean;
}) {
// If the model load was successful or not
})
.on('error', function(message: {
event: "error";
error: string;
}) {
// An error occured
})
id: string;
A unique ID for this KaldiRecognizer instance, passed in every event as recognizerId
acceptWaveform(buffer: AudioBuffer): void;
Preprocesses AudioBuffers and transfers them to the Web Worker for inference.
setWords(words: boolean): void;
Return word timestamps in the recognition message
remove(): void
Will remove a recognizer from the model and free all allocated memory. Make sure to call this method when you are done using a recognizer in order to avoid memory leaks.
In order to obtain recognition results you should listen to the events of the KaldiRecognizer:
.on('result', function(message: {
event: "result";
recognizerId: string;
result: {
result: Array<{
conf: number;
start: number;
end: number;
word: string;
}>;
text: string;
};
}) {
// A final recognition result
})
.on('partialresult', function(message: {
event: "partialresult";
recognizerId: string;
result: {
partial: string;
};
}) {
// A partial recognition result
})
FAQs
Kaldi in-browser speech recognition based on a WASM build of the Vosk library
The npm package vosk-browser receives a total of 5,882 weekly downloads. As such, vosk-browser popularity was classified as popular.
We found that vosk-browser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.