Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@picovoice/leopard-web
Advanced tools
Leopard Speech-to-Text engine for web browsers (via WebAssembly)
Made in Vancouver, Canada by Picovoice
Leopard is an on-device speech-to-text engine. Leopard is:
IndexedDB is required to use Leopard
in a worker thread. Browsers without IndexedDB support
(i.e. Firefox Incognito Mode) should use Leopard
in the main thread.
Using yarn
:
yarn add @picovoice/leopard-web
or using npm
:
npm install --save @picovoice/leopard-web
Leopard requires a valid Picovoice AccessKey
at initialization. AccessKey
acts as your credentials when using Leopard SDKs.
You can get your AccessKey
for free. Make sure to keep your AccessKey
secret.
Signup or Login to Picovoice Console to get your AccessKey
.
Create a model in Picovoice Console or use one of the default language models found in lib/common.
For the web packages, there are two methods to initialize Leopard.
NOTE: Due to modern browser limitations of using a file URL, this method does not work if used without hosting a server.
This method fetches the model file from the public directory and feeds it to Leopard. Copy the model file into the public directory:
cp ${LEOPARD_MODEL_FILE} ${PATH_TO_PUBLIC_DIRECTORY}
NOTE: This method works without hosting a server, but increases the size of the model file roughly by 33%.
This method uses a base64 string of the model file and feeds it to Leopard. Use the built-in script pvbase64
to
base64 your model file:
npx pvbase64 -i ${LEOPARD_MODEL_FILE} -o ${OUTPUT_DIRECTORY}/${MODEL_NAME}.js
The output will be a js file which you can import into any file of your project. For detailed information about pvbase64
,
run:
npx pvbase64 -h
Leopard saves and caches your model file in IndexedDB to be used by WebAssembly. Use a different customWritePath
variable
to hold multiple models and set the forceWrite
value to true to force re-save a model file.
Either base64
or publicPath
must be set to instantiate Leopard. If both are set, Leopard will use the base64
model.
const leopardModel = {
publicPath: ${MODEL_RELATIVE_PATH},
// or
base64: ${MODEL_BASE64_STRING},
// Optionals
customWritePath: "leopard_model",
forceWrite: false,
version: 1,
}
Set enableAutomaticPunctuation
to true, if you wish to enable punctuation in transcript.
// Optional
const options = {
enableAutomaticPunctuation: true
}
Create an instance of Leopard
in the main thread:
const handle = await Leopard.create(
${ACCESS_KEY},
leopardModel,
options // optional options
);
Or create an instance of Leopard
in a worker thread:
const handle = await LeopardWorker.create(
${ACCESS_KEY},
leopardModel,
options // optional options
);
The process result is an object with:
transcript
: A string containing the transcribed data.words
: A list of objects containing a word
, startSec
, endSec
, and confidence
. Each object indicates the start, end time and confidence (between 0 and 1) of the word.function getAudioData(): Int16Array {
... // function to get audio data
return new Int16Array();
}
const result = await handle.process(getAudioData());
console.log(result.transcript);
console.log(result.words);
For processing using worker, you may consider transferring the buffer instead for performance:
let pcm = new Int16Array();
const result = await handle.process(pcm, {
transfer: true,
transferCallback: (data) => { pcm = data }
});
console.log(result.transcript);
console.log(result.words);
Clean up used resources by Leopard
or LeopardWorker
:
await handle.release();
Terminate LeopardWorker
instance:
await handle.terminate();
For example usage refer to our Web demo application.
FAQs
Leopard Speech-to-Text engine for web browsers (via WebAssembly)
We found that @picovoice/leopard-web demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.