react-nativeCheetah - React Native Quick Start

Platforms

  • 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. Setup the React Native environment.

  2. Install the npm packages:

npm install @picovoice/cheetah-react-native
  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" />

Adding Cheetah Models

Android

Add the Cheetah model file to your Android application by:

  1. Create a custom model using the Picovoice Console or use the default model.
  2. Add the model as a bundled resource by placing it under the android/src/main/assets directory of your Android application.

iOS

Open ./ios/Cheetah.xcodeproj in Xcode and add the Cheetah model file in Xcode by:

  1. Create a custom model using the Picovoice Console or use the default model.
  2. Add the model as a bundled resource by selecting Build Phases and adding it to Copy Bundle Resources step.

Usage

Create an instance of Cheetah using a model from Picovoice console or using the default model.

import {Cheetah, CheetahErrors} from '@picovoice/cheetah-react-native';
const accessKey = "${ACCESS_KEY}"
const modelPath = "${MODEL_FILE}"
try {
const cheetah = await Cheetah.create(accessKey, modelPath)
} catch (err: any) {
if (err instanceof CheetahErrors) {
// handle error
}
}

Transcribe real-time audio:

const getAudioFrame = () => {
// get audio frames
}
const transcript = ""
try {
while (1) {
const [partialTranscript, isEndpoint] = await cheetah.process(getAudioFrame())
transcript += partialTranscript
if (isEndpoint) {
const finalTranscript = await cheetah.flush()
transcript += finalTranscript
}
}
} catch (err: any) {
if (err instanceof CheetahErrors) {
// handle error
}
}

Free resources used by Cheetah:

cheetah.delete()

Demo

For the Cheetah React Native SDK, there is a React Native demo project available on the Picovoice GitHub repository.

Setup

Clone the Picovoice repository from GitHub:

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

Usage

  1. Install dependencies and setup environment:
cd cheetah/demo/react-native
npm run android-install
# or
npm run ios-install
  1. Connect a mobile device or launch a simulator and run:
npm run android-run
# or
npm run ios-run

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

Resources

Packages

API

GitHub

Benchmark


Issue with this doc? Please let us know.