react-native-sherpa-onnx, and when to use which API for listing and selecting models.
Auto-detection: The library detects model types from the files present in each model directory. Folder and file names do not need to follow any fixed convention.
Bundled Assets
Models are shipped inside your app bundle (APK/IPA) under a dedicated assets path.Example File Structure
Typical Code Flow
- List model folders in assets with
listAssetModels() - Resolve the chosen folder to an absolute path with
resolveModelPath() - Initialize STT or TTS with that path (and
modelType: 'auto'to rely on auto-detection)
Use this when models are bundled in the app (main app assets on Android, or folder references in the Xcode project on iOS).
Play Asset Delivery (PAD)
On Android, large models can live in a separate asset pack (e.g.sherpa_models) so the base APK stays small. The pack is installed with the app; at runtime you get its path and list/load models from there.
Example File Structure
assetPacks = [":sherpa_models"] and gets the unpacked path with getAssetPackPath("sherpa_models").
Typical Code Flow
- Get the PAD models directory with
getAssetPackPath("sherpa_models") - List model folders under that path with
listModelsAtPath(padPath) - Build the full path for the chosen folder and use
{ type: 'file', path } - Initialize STT/TTS with that path
Public API for Model Discovery
Returns model folders under the platform asset
models directory. Each item has folder and hint ('stt' | 'tts' | 'unknown').When to use: Models are bundled in the app (main assets).Lists model folders under the given path. Set
recursive: true to scan subdirectories.When to use: Models are on the filesystem: PAD unpack path, DocumentDirectoryPath, or custom dir.Returns the path to the asset pack’s content (Android PAD only), or
null if the pack isn’t available.When to use: Android PAD only. On iOS returns null.Converts
{ type: 'asset', path } or { type: 'file', path } to the absolute path used by native code.When to use: Before initializing STT/TTS when you need the resolved path, or pass the config directly to init functions.Returns
{ type: 'asset', path: assetPath }. Use with paths like models/sherpa-onnx-whisper-tiny-en.When to use: Building config for bundled models.Returns
{ type: 'file', path: filePath }. Use with an absolute path to a model folder.When to use: Building config for filesystem models (PAD, downloads).Returns
{ type: 'auto', path }. Resolution tries asset first, then file system.When to use: Let the SDK try asset then file.Model Type Detection Without Initialization
You can query the model type for a given path without loading the model. This is useful to show model-specific options in the UI before initialization.STT Model Detection
{ success, detectedModels: [{ type, modelDir }], modelType? }
TTS Model Detection
{ success, detectedModels: [{ type, modelDir }], modelType? }
Advanced Topics
Path Resolution and Initialization
- Asset paths are relative to the app’s asset root (e.g.
models/whisper-tiny). Always use a consistent prefix (e.g.models/) solistAssetModels()and your asset path config match. - File paths must be absolute. For PAD, use the string returned by
getAssetPackPath()(plus the chosen folder). For downloads, use e.g.RNFS.DocumentDirectoryPath + '/sherpa-onnx/models/...'. - You can pass
modelPath: { type: 'asset', path }ormodelPath: { type: 'file', path }directly tocreateSTT/createTTS; they resolve internally.
Combining Bundled and PAD/File Models
To show both bundled and PAD (or file-based) models in one list:- Call
listAssetModels()for bundled models - Call
listModelsAtPath(padPath)for PAD/file models - Merge the two lists in your UI (tag the source so you know whether to use
assetModelPathorfileModelPath)
Download API and Local Paths
For models downloaded in-app with the download API:- Use
getLocalModelPathByCategory(category, id)to get the local directory path - Pass that path as
modelPath: { type: 'file', path: localPath }to init functions - To list what’s already downloaded, use
listDownloadedModelsByCategory(category)
Troubleshooting
Model directory does not exist
Model directory does not exist
Bundled: Check the asset path (e.g.
models/your-folder) and that the folder is actually in the app’s assets (Android: assets/models/; iOS: folder reference in the app target, Copy Bundle Resources).PAD: Ensure the app was installed with the asset pack (e.g. via installDebugWithPad or the release AAB). If not, getAssetPackPath() is null and you must use a fallback path.File: Ensure the path is absolute and the folder exists on disk.Cannot auto-detect model type / initialization fails
Cannot auto-detect model type / initialization fails
- Ensure the folder contains the required files for at least one model type (see Supported Models)
- File names are case-sensitive
- Try passing an explicit
modelType(e.g.'whisper','vits') if you know the type - Check that no required file is missing (e.g.
tokens.txt)
getAssetPackPath returns null
getAssetPackPath returns null
The app was not installed from a bundle that includes the asset pack. Install via the AAB (e.g.
yarn android:pad or the release AAB with bundletool). Plain installDebug does not include the pack.List is empty or missing models
List is empty or missing models
Bundled: Verify assets are in the right place and that the app was rebuilt after adding models.PAD: Confirm
getAssetPackPath() returns a non-null path and that you pass that path to listModelsAtPath().File: Ensure the path passed to listModelsAtPath() is the directory that directly contains model folders. Use recursive: true only if your layout has nested model folders.See Also
Supported Models
Tables of supported STT and TTS model types with download links
Download Manager
Download models in-app with progress tracking and caching
Execution Providers
Hardware acceleration with NNAPI, XNNPACK, Core ML, and QNN
Migration Guide
Breaking changes and migration from earlier versions