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:Download the model
Download the sherpa-onnx-whisper-tiny.en model from sherpa-onnx releases:
Step 2: Create the STT Engine
Create a fileSpeechToText.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
Step 2: Create the TTS Engine
Create a fileTextToSpeech.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
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.