Skip to main content

Quick Start

Get up and running with react-native-sherpa-onnx by building a simple speech-to-text or text-to-speech example.
This guide assumes you’ve already installed the library and configured your platforms.

Choose Your Use Case

Speech-to-Text

Transcribe audio files to text

Text-to-Speech

Generate speech from text

Speech-to-Text Example

Transcribe an audio file to text using offline STT.

Step 1: Download a Model

First, download a pre-trained model. For this example, we’ll use a small English Whisper model:
1

Download the model

Download the sherpa-onnx-whisper-tiny.en model from sherpa-onnx releases:
2

Add to your project

Copy the extracted model folder to your app’s assets:
Or place it in a location accessible via the file system.

Step 2: Create the STT Engine

Create a file SpeechToText.tsx:
SpeechToText.tsx

Step 3: Transcribe from Samples

You can also transcribe audio samples directly:
Audio format requirements: The audio must be 16-bit PCM WAV format. For samples, provide normalized float values between -1.0 and 1.0.

Text-to-Speech Example

Generate natural-sounding speech from text.

Step 1: Download a TTS Model

1

Download the model

Download a VITS model (e.g., vits-piper-en_US-lessac-medium):
2

Add to your project

Copy the model folder to your assets:

Step 2: Create the TTS Engine

Create a file TextToSpeech.tsx:
TextToSpeech.tsx

Step 3: Generate with Timestamps

For subtitle generation or precise timing control:

Streaming Speech-to-Text

For real-time transcription from a microphone:
StreamingSTT.tsx
For streaming STT, use models with streaming support: transducer, paraformer, nemo_ctc, zipformer2_ctc, or tone_ctc.

Key API Patterns

Initialization

All engines use an instance-based API:

Model Path Types

Detecting Model Types

Auto-detect model architecture without initialization:

What’s Next?

STT Deep Dive

Learn about offline and streaming STT

TTS Deep Dive

Explore TTS features and streaming

Model Setup

Bundle models and use Play Asset Delivery

Execution Providers

Accelerate with NNAPI, QNN, Core ML
Check out the Example App for more complete examples including model selection, streaming, and UI patterns.