flutterLeopard - Flutter Quick Start

Platforms

  • Flutter (1.20.0+)
  • Android (4.4+, API 19+)
  • iOS (9.0+)

Requirements

Picovoice Account & AccessKey

Signup or Login to Picovoice Console to get your AccessKey. Make sure to keep your AccessKey secret.

Quick Start

Setup

  1. Install Flutter SDK.

  2. Run flutter doctor to determine any missing requirements.

  3. Add the Leopard plugin to your app project by referencing it in pubspec.yaml:

dependencies:
leopard_flutter: ^<version>
  1. Enable the proper permission for recording with the hardware's microphone on both iOS and Android:

iOS

Open your Info.plist and add the following line:

<key>NSMicrophoneUsageDescription</key>
<string>[Permission explanation]</string>


Android

Open your AndroidManifest.xml and add the following line:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET"/>


Leopard Model File Integration

Add the Leopard model file to your Flutter application by:

  1. Either creating a model in Picovoice Console or using the default model.
  2. Add the model file to an assets folder in your project directory.
  3. Then add it to your pubspec.yaml:
flutter:
assets:
- assets/leopard_model.pv
  1. In this example, the path to the model file in code would then be as follows:
String modelPath = "assets/leopard_model.pv";

Usage

An instance of Leopard is created by passing a model file path into its static constructor create:

import 'package:leopard_flutter/leopard.dart';
const accessKey = "{ACCESS_KEY}" // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
void createLeopard() async {
try {
_leopard = await Leopard.create(accessKey, '{LEOPARD_MODEL_PATH}');
} on LeopardException catch (err) {
// handle Leopard init error
}
}

Transcribe an audio file by passing in the path:

try {
String transcript = = await _leopard.processFile("${AUDIO_FILE_PATH}");
} on LeopardException catch (err) { }

When done resources have to be released explicitly:

leopard.delete();

Demo

For the Leopard Flutter SDK, we offer demo applications that demonstrate how to use the Speech-to-Text engine on audio recordings.

Setup

Clone the Leopard repository from GitHub using HTTPS:

git clone --recurse-submodules https://github.com/Picovoice/leopard.git

Usage

  1. Replace {YOUR_ACCESS_KEY_HERE} with a valid AccessKey in the demo/flutter/lib/main.dart file:

  2. Copy assets:

cd leopard/demo/flutter
bash copy_assets.sh

NOTE: on Windows, Git Bash or another bash shell is required, or you will have to manually copy the leopard demo model file

  1. Build and deploy the demo to your device:
flutter run

For more information on our Leopard demos for Flutter, head over to our GitHub repository.

Resources

Packages

API

GitHub

Benchmark


Issue with this doc? Please let us know.