Skip to main content

Installation

Install react-native-sherpa-onnx in your React Native project and configure platform-specific setup.

Package Installation

npm install react-native-sherpa-onnx

Peer Dependencies

The library requires @dr.pogodin/react-native-fs for file operations:
npm install @dr.pogodin/react-native-fs
If your project uses Yarn v3+ or Plug’n’Play, configure Yarn to use the Node Modules linker to avoid postinstall issues.

Yarn PnP Configuration

If using Yarn v3+ with Plug’n’Play, add this to your .yarnrc.yml:
.yarnrc.yml
nodeLinker: node-modules
Alternatively, set the environment variable during install:
YARN_NODE_LINKER=node-modules yarn install

Platform Setup

iOS Setup

The sherpa-onnx XCFramework is not shipped in the npm package (size ~80MB). It is downloaded automatically when you run pod install.
1

Install CocoaPods dependencies

Navigate to the ios directory and install pods:
cd ios
bundle install
bundle exec pod install
The podspec automatically runs scripts/setup-ios-framework.sh, which downloads the XCFramework from GitHub Releases. The version is pinned in third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG.
2

Verify framework download

The script downloads the XCFramework and libarchive sources. Libarchive is compiled from source as part of the Pod.You should see output similar to:
Downloading sherpa-onnx XCFramework v0.x.x...
✓ Framework downloaded successfully
3

Build your project

Return to the root directory and build:
cd ..
npx react-native run-ios

iOS Requirements

  • iOS 13.0+
  • Xcode 12.0+
  • CocoaPods 1.10+

Framework Architecture

The XCFramework includes:
  • libsherpa-onnx-cxx-api.a - C++ API merged into the static library
  • libarchive - Compiled from source for model archive extraction
  • Support for all iOS architectures (arm64, x86_64 for simulator)
The framework is fetched from GitHub Releases and automatically cached by CocoaPods.

Advanced: Building the Framework Locally

If you need a custom sherpa-onnx build (e.g., different version or patches):
  1. Build the XCFramework using the build-sherpa-onnx-ios-framework workflow steps
  2. Place it in ios/Frameworks/ before running pod install
  3. The Pod will use the local framework instead of downloading
See third_party/sherpa-onnx-prebuilt for build details.

Verify Installation

Test that the native library is loaded correctly:
App.tsx
import { testSherpaInit } from 'react-native-sherpa-onnx';

try {
  const result = await testSherpaInit();
  console.log('✓ sherpa-onnx initialized:', result);
} catch (error) {
  console.error('✗ Initialization failed:', error);
}
Expected output:
✓ sherpa-onnx initialized: sherpa-onnx native library loaded successfully

Requirements Summary

React Native

Version 0.70 or higher

Android

API 24+ (Android 7.0+)

iOS

iOS 13.0+, Xcode 12.0+

File System

@dr.pogodin/react-native-fs

Troubleshooting

Symptom: Pod install fails with “Failed to download sherpa-onnx XCFramework”Solution:
  1. Check your internet connection
  2. Verify the release tag exists in GitHub Releases
  3. Try manual download: bash scripts/setup-ios-framework.sh
  4. Check third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG for the expected version
Symptom: Build fails with missing header filesSolution:
  1. Clean build folder: cd ios && rm -rf build && rm -rf ~/Library/Developer/Xcode/DerivedData
  2. Re-install pods: bundle exec pod install --repo-update
  3. Verify ios/Frameworks/sherpa-onnx.xcframework exists
Symptom: Gradle sync fails with dependency resolution errorsSolution:
  1. Clear Gradle cache: cd android && ./gradlew clean
  2. Sync project: ./gradlew --refresh-dependencies
  3. Check android/build.gradle has mavenCentral() repository
Symptom: Runtime errors with Yarn v3+ Plug’n’PlaySolution: Add to .yarnrc.yml:
nodeLinker: node-modules
Then run:
yarn install
Symptom: testSherpaInit() throws an errorSolution:
  1. iOS: Run cd ios && bundle exec pod install
  2. Android: Run cd android && ./gradlew clean build
  3. Rebuild the app completely
  4. Check that peer dependencies are installed
If you encounter persistent issues, check the GitHub Issues or file a new issue with your error logs.

Next Steps

Quick Start

Build your first STT or TTS example

Model Setup

Learn how to bundle and load models

API Reference

Explore the complete API

Example App

Run the full-featured example app

Build docs developers (and LLMs) love