Made in Vancouver, Canada by Picovoice
Bat is an on-device spoken language understanding engine. Bat is:
- Private; All voice processing runs locally.
- Cross-Platform:
- Linux (x86_64), macOS (x86_64, arm64), and Windows (x86_64, arm64)
- Android and iOS
- Chrome, Safari, Firefox, and Edge
- Raspberry Pi (3, 4, 5)
AccessKey is your authentication and authorization token for deploying Picovoice SDKs, including Bat. Anyone who is using Picovoice needs to have a valid AccessKey. You must keep your AccessKey secret. You would need internet connectivity to validate your AccessKey with Picovoice license servers even though the voice recognition is running 100% offline.
AccessKey also verifies that your usage is within the limits of your account. You can see your usage limits and real-time usage on your Picovoice Console Profile. To continue using Picovoice after your trial or renew and adjust your usage limits, please reach out to our Enterprise Sales Team or your existing Picovoice contact.
- Bat spoken language understanding currently supports English, French, Spanish, Italian, German, Portuguese, Japanese, and Korean.
Install the demo package:
pip3 install pvbatdemobat_demo_mic --access_key ${ACCESS_KEY}If using SSH, clone the repository with:
git clone --recurse-submodules [email protected]:Picovoice/bat.gitIf using HTTPS, clone the repository with:
git clone --recurse-submodules https://github.com/Picovoice/bat.gitBuild the demo:
cmake -S demo/c/ -B demo/c/build && cmake --build demo/c/buildRun the demo:
./demo/c/build/bat_demo_mic -a ${ACCESS_KEY} -m ${MODEL_PATH} -l ${LIBRARY_PATH}Replace ${ACCESS_KEY} with yours obtained from Picovoice Console, ${LIBRARY_PATH} with the path to appropriate
library under lib, and ${MODEL_PATH} to path to default model file.
To run the demo, go to demo/ios/BatDemo and run:
pod installReplace let accessKey = "${YOUR_ACCESS_KEY_HERE}" in the file ViewModel.swift with your AccessKey.
Then, using Xcode, open the generated BatDemo.xcworkspace and run the application.
Using Android Studio, open demo/android/BatDemo as an Android project and then run the application.
Replace "${YOUR_ACCESS_KEY_HERE}" in the file MainActivity.java with your AccessKey.
From demo/web run the following in the terminal:
yarn
yarn start(or)
npm install
npm run startOpen http://localhost:5000 in your browser to try the demo.
Install the Python SDK:
pip3 install pvbatCreate an instance of the engine and detect spoken language:
import pvbat
handle = pvbat.create(access_key='${ACCESS_KEY}')
def get_next_audio_frame():
pass
while True:
language_scores = handle.process(get_next_audio_frame())
if language_scores:
print(language_scores)Create an instance of the engine and detect spoken language:
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "pv_bat.h"
pv_bat_t *handle = NULL;
const pv_status_t status = pv_bat_init("${ACCESS_KEY}", "${MODEL_PATH}", "${DEVICE}", 0.4f, &handle);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}
extern const int16_t *get_next_audio_frame(void);
while (true) {
float *language_scores = NULL;
const pv_status_t status = pv_bat_process(
handle,
get_next_audio_frame(),
&language_scores);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}
if (language_scores != NULL) {
// do something with language_scores
}
pv_bat_scores_delete(language_scores);
}Replace ${ACCESS_KEY} with yours obtained from Picovoice Console and ${MODEL_PATH} to path to
default model file. Finally, when done be sure to release
resources acquired using pv_bat_delete(handle).
The Bat iOS binding is available via CocoaPods. To import it into your iOS project, add the following line to your Podfile and run pod install:
pod 'Bat-iOS'Create an instance of the engine and detect spoken language:
import Bat
let bat = Bat(accessKey: "${ACCESS_KEY}")
func getNextAudioFrame() -> [Int16] {
// .. get audioFrame
return audioFrame;
}
while true {
do {
let languageScores = try bat.process(getNextAudioFrame())
if languageScores != nil {
// do something with languageScores
}
} catch let error as BatError {
// handle error
} catch { }
}Replace ${ACCESS_KEY} with yours obtained from Picovoice Console.
To include the package in your Android project, ensure you have included mavenCentral() in your top-level build.gradle file and then add the following to your app's build.gradle:
dependencies {
implementation 'ai.picovoice:bat-android:${LATEST_VERSION}'
}Create an instance of the engine and detect spoken language:
import ai.picovoice.bat.*;
final String accessKey = "${ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
short[] getNextAudioFrame() {
// .. get audioFrame
return audioFrame;
}
try {
Bat bat = new Bat.Builder().setAccessKey(accessKey).build(appContext);
while true {
HashMap<BatLanguages, Float> languageScores = bat.process(getNextAudioFrame());
if (languageScores != null) {
// take action based on languageScores
}
};
} catch (BatException ex) { }Replace ${ACCESS_KEY} with yours obtained from Picovoice Console.
Install the web SDK using yarn:
yarn add @picovoice/bat-webor using npm:
npm install --save @picovoice/bat-webCreate an instance of the engine using BatWorker and process an audio file:
import { BatWorker } from "@picovoice/bat-web";
import batParams from "${PATH_TO_BASE64_BAT_PARAMS}";
function scoresCallback(scores: BatScores | null) {
if (scores !== null) {
// take action based on scores
}
}
function getAudioData(): Int16Array {
// ... function to get audio data
return new Int16Array();
}
const bat = await BatWorker.create(
"${ACCESS_KEY}",
scoresCallback,
{ base64: batParams }
);
for (;;) {
bat.process(getAudioData());
// break on some condition
}Replace ${ACCESS_KEY} with yours obtained from Picovoice Console. Finally, when done release the resources using bat.release().
- Initial release