Skip to main content

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

Use modelType: 'auto' to let the SDK automatically detect the model type based on files. This is the recommended approach.

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
When to use bundled assets:
  • 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.
Returns: 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).
Parameters:
  • path: Absolute filesystem path to scan
  • recursive: Scan subdirectories (default: false)
Returns: 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.
Returns: Promise<string | null>
  • Android with PAD: Path to pack’s assets
  • Android without PAD or iOS: null
getAssetPackPath() returns null if:
  • On iOS (PAD is Android-only)
  • App was not installed with the asset pack (e.g., plain installDebug)
  • Asset pack name doesn’t match
Install with asset pack:

Model Path Configuration

All create* functions accept a ModelPathConfig:

Asset Path

For models bundled in app assets:
Helper:

File Path

For models on the filesystem:
Helper:

Auto Path

Try asset first, then filesystem:

Resolving Paths

Convert a ModelPathConfig to an absolute path:

Model Type Detection

Detect model type without loading the model.

STT Model Detection

Returns:

TTS Model Detection

Use cases:
  • 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)
Use preferInt8 to control which is loaded:
Options:
  • 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:
The SDK detects these by path tokens (rk3588, ascend, cann, 910b, 310p3) and returns a clear error without crashing.

Example: Model Picker UI

Troubleshooting

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)
PAD:
  • Ensure app was installed with asset pack (not plain installDebug)
  • Check getAssetPackPath() returns non-null
  • Verify asset pack name matches in build.gradle
File:
  • Ensure path is absolute
  • Verify directory exists on device
The app was not installed with the asset pack:
  • Use bundleDebug + bundletool to build with PAD
  • Plain installDebug does not include asset packs
  • On iOS, PAD is not available (always returns null)
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 modelType instead of 'auto'
Bundled:
  • Verify models are in the right location (assets/models/ or Xcode folder reference)
  • Rebuild the app
PAD:
  • Check getAssetPackPath() returns a path
  • Verify you’re passing that path to listModelsAtPath()
File:
  • Ensure path exists and contains model folders
  • Try recursive: true if models are nested
  • 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