flutterCheetah - 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 Cheetah plugin to your app project by referencing it in pubspec.yaml:

dependencies:
cheetah_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"/>


Cheetah Model File Integration

Add the Cheetah 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/cheetah_model.pv
  1. In this example, the path to the model file in code would then be as follows:
String modelPath = "assets/cheetah_model.pv";

Usage

n instance of Cheetah is created by passing a model file path into it's static constructor create:

import 'package:cheetah_flutter/cheetah.dart';
const accessKey = "{ACCESS_KEY}" // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
void createCheetah() async {
try{
_cheetah = await Cheetah.create(accessKey, '{CHEETAH_MODEL_PATH}');
} on CheetahException catch (err) {
// handle Cheetah init error
}
}

Transcribe audio:

List<int> buffer = getAudioFrame();
String transcript = "";
while true {
CheetahTranscript transcriptObj = await _cheetah.process(getAudioFrame());
transcript += transcriptObj.transcript;
if (transcriptObj.isEndpoint) {
CheetahTranscript endpointTranscriptObj = await _cheetah.flush();
transcript += endpointTranscriptObj.transcript;
}
}

When done resources have to be released explicitly:

cheetah.delete();

Demo

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

Setup

Clone the Cheetah repository from GitHub using HTTPS:

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

Usage

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

  2. Copy assets:

cd cheetah/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 cheetah demo model file

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

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

Resources

Packages

API

GitHub

Benchmark


Issue with this doc? Please let us know.