Overview
This guide explains how to set up and discover STT/TTS models in react-native-sherpa-onnx. Models can be:- Bundled in your app assets (main APK/IPA)
- Play Asset Delivery (PAD) on Android for large models
- Downloaded at runtime to filesystem
- Auto-detected based on files present in directories
Auto-detection is file-based. Folder names do not need to follow any specific pattern. The SDK detects model types by examining the files present in each directory.
Quick Start: Bundled Assets
File Structure
Usage
Quick Start: Play Asset Delivery (PAD)
For large models (>100 MB), use Android’s Play Asset Delivery to keep the base APK small.File Structure
Usage
When to use PAD:
- Models are larger than 50-100 MB
- You want to keep the base APK small
- Users can download models on WiFi after install
- Models are small (less than 50 MB total)
- You want offline-first functionality
- Simpler setup and deployment
Model Discovery APIs
listAssetModels()
List models bundled in the main app assets.Array<{ folder: string, hint: 'stt' | 'tts' | 'unknown' }>
Use when: Models are bundled in the main app assets (Android: assets/models/, iOS: folder references).
listModelsAtPath(path, recursive?)
List models at a filesystem path (PAD, downloads, custom directory).path: Absolute filesystem path to scanrecursive: Scan subdirectories (default:false)
Array<{ folder: string, hint: 'stt' | 'tts' | 'unknown' }>
Use when: Models are on the filesystem (PAD unpack path, DocumentDirectoryPath, downloads).
getAssetPackPath(packName)
Get the path to an Android Play Asset Delivery pack.Promise<string | null>
- Android with PAD: Path to pack’s assets
- Android without PAD or iOS:
null
Model Path Configuration
Allcreate* functions accept a ModelPathConfig:
Asset Path
For models bundled in app assets:File Path
For models on the filesystem:Auto Path
Try asset first, then filesystem:Resolving Paths
Convert aModelPathConfig to an absolute path:
Model Type Detection
Detect model type without loading the model.STT Model Detection
TTS Model Detection
- Show model-specific options in UI before initialization
- Validate model compatibility
- Display model info to users
Combining Bundled and PAD Models
Show both bundled and PAD models in one list:Int8 Quantization
Some models have both full-precision and int8 quantized versions:model.onnx(full precision)model.int8.onnx(quantized)
preferInt8 to control which is loaded:
true: Prefer int8 (faster, smaller)false: Prefer full precision (higher accuracy)undefined: Try int8 first, fallback to full precision (default)
Hardware-Specific Models (Unsupported)
Models built for specific hardware (RK35xx, Ascend, CANN, 910B, 310P3) are not supported on mobile:rk3588, ascend, cann, 910b, 310p3) and returns a clear error without crashing.
Example: Model Picker UI
Troubleshooting
Error: Model directory does not exist
Error: Model directory does not exist
Bundled assets:
- Verify folder is in
assets/models/(Android) or added as folder reference in Xcode (iOS) - Rebuild the app after adding models
- Check the path:
models/folder-name(no leading slash)
- Ensure app was installed with asset pack (not plain
installDebug) - Check
getAssetPackPath()returns non-null - Verify asset pack name matches in
build.gradle
- Ensure path is absolute
- Verify directory exists on device
getAssetPackPath() returns null
getAssetPackPath() returns null
The app was not installed with the asset pack:
- Use
bundleDebug+bundletoolto build with PAD - Plain
installDebugdoes not include asset packs - On iOS, PAD is not available (always returns null)
Cannot auto-detect model type
Cannot auto-detect model type
The folder doesn’t contain recognizable model files:
- Ensure all required files are present (e.g., encoder.onnx, decoder.onnx, tokens.txt)
- File names are case-sensitive
- Try passing explicit
modelTypeinstead of'auto'
List is empty (no models found)
List is empty (no models found)
Bundled:
- Verify models are in the right location (
assets/models/or Xcode folder reference) - Rebuild the app
- Check
getAssetPackPath()returns a path - Verify you’re passing that path to
listModelsAtPath()
- Ensure path exists and contains model folders
- Try
recursive: trueif models are nested
Model works in one mode but not another (asset vs file)
Model works in one mode but not another (asset vs file)
- Asset paths are relative:
models/whisper-tiny - File paths must be absolute:
/data/user/0/.../models/whisper-tiny - Use
resolveModelPath()to debug path resolution
Next Steps
Speech-to-Text
Use STT models for transcription
Text-to-Speech
Use TTS models for speech generation
Execution Providers
Hardware acceleration options
Streaming STT
Real-time speech recognition