Bat Spoken Language Identification
Web API
API Reference for the Bat Web SDK (npm).
Bat
Class for the Bat Spoken Language Identification engine.
Bat.create()
Creates an instance of the Bat Spoken Language Identification engine.
Parameters
accessKeystring : AccessKey obtained from Picovoice Console.scoresCallback(scores: BatScores | null) => void : User-defined callback to run after receiving scores result.modelBatModel : Bat model options.optionsBatOptions : Optional configuration arguments.
Returns
Bat: An instance of the Bat engine.
Bat.process()
Processes a frame of audio. The required sample rate can be retrieved from sampleRate and the length of frame
(number of audio samples per frame) can be retrieved from frameLength.
The audio must be single-channel and 16-bit linearly-encoded.
Language identification scores are returned via the scoresCallback defined during init.
Parameters
pcmInt16Array : A frame of audio samples.
Bat.release()
Releases resources acquired by the Bat Web SDK.
Bat.frameLength
Number of audio samples per frame.
Bat.sampleRate
Audio sample rate accepted by Bat.
Bat.version
Bat version string.
Bat.listAvailableDevices()
Lists all available devices that Bat can use for inference. Each entry in the list can be the used as the device argument for the .create() method.
Returns
- string[] : List of all available devices that Bat can use for inference.
BatModel
Bat model type.
base64string: The model file (.pv) in base64 string to initialize Bat.publicPathstring: The model file (.pv) path relative to the public directory.customWritePathstring : Custom path to save the model in storage. Set to a different name to use multiple models acrossbatinstances.forceWriteboolean : Flag to overwrite the model in storage even if it exists.versionnumber : Version of the model file. Increment to update the model file in storage.
BatOptions
Bat options type.
devicestring : Optional. String representation of the device (e.g., CPU or GPU) to use. If set tobest, the most suitable device is selected automatically. If set togpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument togpu:${GPU_INDEX}, where${GPU_INDEX}is the index of the target GPU. If set tocpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument tocpu:${NUM_THREADS}, where${NUM_THREADS}is the desired number of threads.voiceThresholdnumber : Sensitivity threshold for detecting voice. The value should be a number within [0, 1]. A higher threshold increases detection confidence at the cost of potentially missing frames of voice.processErrorCallback(error: string) => void : User-defined callback invoked if any error happens while processing the audio stream. Its only input argument is the error message.
BatScores
Bat scores type.
BatLanguages
Bat languages enum type.
NUM_BAT_LANGUAGES
Number of languages contained in the BatLanguages enum type.
batLanguageToString
Returns string representation of BatLanguages enum value.
Parameters
languageBatLanguages :BatLanguagesenum value.
Returns
- string | null : String representation or
niliflanguageis not valid.
batLanguageFromString
Returns BatLanguages enum value given string representation.
Parameters
languageString : String representation of enum value.
Returns
- BatLanguages | null :
BatLanguagesenum value ornullif string representation is not valid.
BatWorker
A class for running the Bat Spoken Language Identification engine as a web worker thread.
BatWorker.create()
Creates an instance of BatWorker.
Parameters
accessKeystring : AccessKey obtained from Picovoice Console.scoresCallback(scores: BatScores | null) => void : User-defined callback to run after receiving scores result.modelBatModel : Bat model options.optionsBatOptions : Optional configuration arguments.
Returns
BatWorker: An instance ofBatWorker.
BatWorker.process()
Processes a frame of audio. The required sample rate can be retrieved from 'sampleRate' and the length of frame (number of audio samples per frame) can be retrieved from 'frameLength'. The audio must be single-channel and 16-bit linearly-encoded.
Language identification scores are returned via the scoresCallback defined during init.
Parameters
pcmInt16Array : A frame of audio samples.
BatWorker.release()
Releases resources acquired by the Bat Web SDK.
BatWorker.terminate()
Force terminates the instance of BatWorker.
BatWorker.frameLength
Number of audio samples per frame.
BatWorker.sampleRate
Audio sample rate accepted by Bat.
BatWorker.version
Bat version string.