Skip to main content

Installation

Install the React Native Sherpa-ONNX SDK and configure it for your platform.

Install Package

npm install react-native-sherpa-onnx

Peer Dependencies

The SDK requires @dr.pogodin/react-native-fs for file system operations:
npm install @dr.pogodin/react-native-fs
Yarn v3+ / Plug’n’Play Users: If you use Yarn with PnP, configure the Node Modules linker to avoid postinstall issues:
.yarnrc.yml
nodeLinker: node-modules
Or set the environment variable during install:
YARN_NODE_LINKER=node-modules yarn install

Platform Setup

Android Configuration

No additional setup required! The library automatically handles native dependencies via Gradle.The SDK includes:
  • sherpa-onnx native libraries - Automatically downloaded during build
  • ONNX Runtime - Bundled with execution provider support
  • Hardware acceleration - CPU, NNAPI, XNNPACK, and QNN support

Optional: QNN (Qualcomm Neural Network) Setup

For Qualcomm Snapdragon devices with AI accelerator support:
1

Check device support

QNN provides hardware acceleration on Qualcomm Snapdragon chipsets with AI Engine (Hexagon DSP).
import { getQnnSupport } from 'react-native-sherpa-onnx';

const support = await getQnnSupport();
console.log('QNN available:', support.providerCompiled);
console.log('QNN accelerator:', support.hasAccelerator);
console.log('Can initialize:', support.canInit);
2

Configure execution provider

Pass provider: 'qnn' when initializing STT or TTS:
const stt = await createSTT({
  modelPath: { type: 'asset', path: 'models/whisper-tiny' },
  provider: 'qnn', // Use QNN acceleration
});
See Execution Provider Support for details on NNAPI, XNNPACK, and QNN configuration.

Build from Source (Advanced)

To build Android native libraries yourself:
cd node_modules/react-native-sherpa-onnx
# See third_party/sherpa-onnx-prebuilt/README.md for build instructions
Release versions are pinned in third_party/sherpa-onnx-prebuilt/ANDROID_RELEASE_TAG.

Verify Installation

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

export default function App() {
  useEffect(() => {
    testSherpaInit()
      .then((result) => console.log('Sherpa-ONNX initialized:', result))
      .catch((err) => console.error('Initialization failed:', err));
  }, []);

  return <Text>Testing Sherpa-ONNX...</Text>;
}
Expected output:
Sherpa-ONNX initialized: sherpa-onnx native library loaded successfully

Check Execution Providers

Verify available hardware acceleration:
import { getAvailableProviders } from 'react-native-sherpa-onnx';

const providers = await getAvailableProviders();
console.log('Available providers:', providers);
// Example output: ['CPU', 'CoreML', 'XNNPACK'] on iOS
// Example output: ['CPU', 'NNAPI', 'XNNPACK', 'QNN'] on Android
Next Step: Follow the Quick Start Guide to transcribe your first audio file or generate speech.

Troubleshooting

If pod install fails to download the XCFramework:
  1. Check internet connection: The framework is ~80MB and requires a stable connection.
  2. Manual download: Download from GitHub Releases and place in node_modules/react-native-sherpa-onnx/ios/Frameworks/.
  3. Check version: Ensure the release tag matches third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG.
Common issues:
  • Gradle sync: Run cd android && ./gradlew clean then rebuild.
  • NDK version: Ensure you have NDK 21 or later installed.
  • Memory: Gradle may need more memory. Add to android/gradle.properties:
    org.gradle.jvmargs=-Xmx4096m
    
If using Yarn v3+ with Plug’n’Play:
.yarnrc.yml
nodeLinker: node-modules
Or use the environment variable:
YARN_NODE_LINKER=node-modules yarn install
Install the required peer dependency:
npm install @dr.pogodin/react-native-fs
Then rebuild:
cd ios && pod install
cd android && ./gradlew clean

Next Steps

Quick Start

Build your first speech recognition app

Download Models

Learn how to download and bundle models

STT API Reference

Explore speech-to-text features

TTS API Reference

Explore text-to-speech features

Build docs developers (and LLMs) love