MCPcopy Index your code
hub / github.com/Picovoice/leopard

github.com/Picovoice/leopard @3.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 3.0.0 ↗ · + Follow
1,332 symbols 3,302 edges 174 files 121 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Leopard

GitHub release GitHub

Maven Central Maven Central npm npm npm npm Nuget CocoaPods Pub Version PyPI

Made in Vancouver, Canada by Picovoice

Twitter URL YouTube Channel Views

Leopard is an on-device speech-to-text engine. Leopard is:

  • Private; All voice processing runs locally.
  • Accurate
  • Compact and Computationally-Efficient
  • Cross-Platform:
  • Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64)
  • Android and iOS
  • Chrome, Safari, Firefox, and Edge
  • Raspberry Pi (3, 4, 5)

Table of Contents

AccessKey

AccessKey is your authentication and authorization token for deploying Picovoice SDKs, including Leopard. 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. Everyone who signs up for Picovoice Console receives the Free Tier usage rights described here. If you wish to increase your limits, you can purchase a subscription plan.

Language Support

Demos

Python Demos

Install the demo package:

pip3 install pvleoparddemo

Run the following in the terminal:

leopard_demo_file --access_key ${ACCESS_KEY} --audio_paths ${AUDIO_FILE_PATH}

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console and ${AUDIO_FILE_PATH} with a path to an audio file you wish to transcribe.

C Demo

Build the demo:

cmake -S demo/c/ -B demo/c/build && cmake --build demo/c/build

Run the demo:

./demo/c/build/leopard_demo -a ${ACCESS_KEY} -l ${LIBRARY_PATH} -m ${MODEL_FILE_PATH} ${AUDIO_FILE_PATH}

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console, ${LIBRARY_PATH} with the path to appropriate library under lib, ${MODEL_FILE_PATH} to path to default model file (or your custom one), and ${AUDIO_FILE_PATH} with a path to an audio file you wish to transcribe.

iOS Demo

To run the demo, go to demo/ios/LeopardDemo and run:

pod install

Replace let accessKey = "${YOUR_ACCESS_KEY_HERE}" in the file ViewModel.swift with your AccessKey.

Then, using Xcode, open the generated LeopardDemo.xcworkspace and run the application.

Android Demo

Using Android Studio, open demo/android/LeopardDemo as an Android project and then run the application.

Replace "${YOUR_ACCESS_KEY_HERE}" in the file MainActivity.java with your AccessKey.

Node.js Demo

Install the demo package:

yarn global add @picovoice/leopard-node-demo

Run the following in the terminal:

leopard-file-demo --access_key ${ACCESS_KEY} --input_audio_file_path ${AUDIO_FILE_PATH}

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console and ${AUDIO_FILE_PATH} with a path to an audio file you wish to transcribe.

For more information about Node.js demos go to demo/nodejs.

Flutter Demo

To run the Leopard demo on Android or iOS with Flutter, you must have the Flutter SDK installed on your system. Once installed, you can run flutter doctor to determine any other missing requirements for your relevant platform. Once your environment has been set up, launch a simulator or connect an Android/iOS device.

Run the prepare_demo script from demo/flutter with a language code to set up the demo in the language of your choice (e.g. de -> German, ko -> Korean). To see a list of available languages, run prepare_demo without a language code.

dart scripts/prepare_demo.dart ${LANGUAGE}

Replace "${YOUR_ACCESS_KEY_HERE}" in the file main.dart with your AccessKey.

Run the following command from demo/flutter to build and deploy the demo to your device:

flutter run

React Native Demo

To run the React Native Leopard demo app you will first need to set up your React Native environment. For this, please refer to React Native's documentation. Once your environment has been set up, navigate to demo/react-native/LeopardDemo/src to run the following commands:

For Android:

yarn android-install          # sets up environment
yarn android-run ${LANGUAGE}  # builds and deploys to Android

For iOS:

yarn ios-install              # sets up environment
yarn ios-run ${LANGUAGE}      # builds and deploys to iOS

Java Demo

The Leopard Java demo is a command-line application that lets you choose between running Leopard on an audio file or on microphone input.

From demo/java run the following commands from the terminal to build and run the file demo:

cd demo/java
./gradlew build
cd build/libs
java -jar leopard-file-demo.jar -a ${ACCESS_KEY} -i ${AUDIO_FILE_PATH}

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console and ${AUDIO_FILE_PATH} with a path to an audio file you wish to transcribe.

For more information about Java demos go to demo/java.

.NET Demo

Leopard .NET demo is a command-line application that lets you choose between running Leopard on an audio file or on real-time microphone input.

From demo/dotnet/LeopardDemo run the following in the terminal:

dotnet run -c FileDemo.Release -- --access_key ${ACCESS_KEY} --input_audio_path ${AUDIO_FILE_PATH}

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console and ${AUDIO_FILE_PATH} with a path to an audio file you wish to transcribe.

For more information about .NET demos, go to demo/dotnet.

Web Demos

Vanilla JavaScript and HTML

From demo/web run the following in the terminal:

yarn
yarn start

(or)

npm install
npm run start

Open http://localhost:5000 in your browser to try the demo.

React Demo

From demo/react run the following in the terminal:

yarn
yarn start ${LANGUAGE}

(or)

npm install
npm run start ${LANGUAGE}

Open http://localhost:3000 in your browser to try the demo.

SDKs

Python

Install the Python SDK:

pip3 install pvleopard

Create an instance of the engine and transcribe an audio file:

import pvleopard

leopard = pvleopard.create(access_key='${ACCESS_KEY}')

print(leopard.process_file('${AUDIO_FILE_PATH}'))

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console and ${AUDIO_FILE_PATH} to path an audio file. Finally, when done be sure to explicitly release the resources using leopard.delete().

C

Create an instance of the engine and transcribe an audio file:

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#include "pv_leopard.h"

pv_leopard_t *leopard = NULL;
bool enable_automatic_punctuation = false;
bool enable_speaker_diarization = false;
const char *device = "best";

pv_status_t status = pv_leopard_init(
  "${ACCESS_KEY}",
  "${MODEL_FILE_PATH}",
  device,
  enable_automatic_punctuation,
  enable_speaker_diarization,
  &leopard);
if (status != PV_STATUS_SUCCESS) {
    // error handling logic
}

char *transcript = NULL;
int32_t num_words = 0;
pv_word_t *words = NULL;
status = pv_leopard_process_file(
    leopard,
    "${AUDIO_FILE_PATH}",
    &transcript,
    &num_words,
    &words);
if (status != PV_STATUS_SUCCESS) {
    // error handling logic
}

fprintf(stdout, "%s\n", transcript);
for (int32_t i = 0; i < num_words; i++) {
    fprintf(
            stdout,
            "[%s]\t.start_sec = %.1f .end_sec = %.1f .confidence = %.2f .speaker_tag = %d\n",
            words[i].word,
            words[i].start_sec,
            words[i].end_sec,
            words[i].confidence,
            words[i].speaker_tag);
}

pv_leopard_transcript_delete(transcript);
pv_leopard_words_delete(words);

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console, ${MODEL_FILE_PATH} to path to default model file (or your custom one), and ${AUDIO_FILE_PATH} to path an audio file. Finally, when done be sure to release resources acquired using pv_leopard_delete(leopard).

iOS

The Leopard 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 'Leopard-iOS'

Create an instance of the engine and transcribe an audio_file:

import Leopard

let modelPath = Bundle(for: type(of: self)).path(
        forResource: "${MODEL_FILE}", // Name of the model file name for Leopard
        ofType: "pv")!

let leopard = Leopard(accessKey: "${ACCESS_KEY}", modelPath: modelPath)

do {
    let audioPath = Bundle(for: type(of: self)).path(forResource: "${AUDIO_FILE_NAME}", ofType: "${AUDIO_FILE_EXTENSION}")
    let result = leopard.process(audioPath)
    print(result.transcript)
} catch let error as LeopardError {
} catch { }

Replace ${ACCESS_KEY} with yours obtained from Picovoice Console, ${MODEL_FILE} a custom trained model from console or the default model, ${AUDIO_FILE_NAME} with the name of the audio file and ${AUDIO_FILE_EXTENSION} with the extension of the audio file.

Android

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:leopard-android:${LATEST_VERSION}'
}

Create an instance of the engine and transcribe an audio file:

```java import ai.picovoice.leopard.*;

final String accessKey = "${ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/) final String mo

Extension points exported contracts — how you extend this code

Chainable (Interface)
(no doc)
binding/react/cypress/support/index.ts
Chainable (Interface)
(no doc)
binding/web/cypress/support/index.ts

Core symbols most depended-on inside this repo

getFirstMatch
called by 86
lib/wasm/pv_leopard_simd.js
getFirstMatch
called by 86
lib/wasm/pv_leopard_pthread.js
_defineProperty
called by 50
lib/wasm/pv_leopard_simd.js
_defineProperty
called by 50
lib/wasm/pv_leopard_pthread.js
stop
called by 33
demo/python/leopard_demo_mic.py
build
called by 28
binding/java/src/ai/picovoice/leopard/Leopard.java
map
called by 26
lib/wasm/pv_leopard_simd.js
setInt
called by 25
lib/wasm/pv_leopard_simd.js

Shape

Function 581
Method 532
Class 211
Enum 6
Interface 2

Languages

TypeScript63%
Java21%
Python7%
C#7%
Kotlin1%
C1%

Modules by API surface

lib/wasm/pv_leopard_pthread.js320 symbols
lib/wasm/pv_leopard_simd.js264 symbols
binding/web/src/leopard_errors.ts41 symbols
binding/react-native/src/leopard_errors.tsx36 symbols
binding/nodejs/src/errors.ts29 symbols
binding/python/_leopard.py28 symbols
binding/dotnet/Leopard/LeopardException.cs25 symbols
binding/dotnet/Leopard/Leopard.cs25 symbols
binding/dotnet/LeopardTest/MainTest.cs22 symbols
binding/java/test/ai/picovoice/leopard/LeopardTest.java21 symbols
demo/android/LeopardDemo/leopard-demo-app/src/main/java/ai/picovoice/leoparddemo/MainActivity.java19 symbols
binding/web/src/leopard.ts17 symbols

For agents

$ claude mcp add leopard \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact