
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
react-native-sherpa-onnx-offline-tts
Advanced tools
A lightweight React Native wrapper around Sherpa‑ONNX that lets you run 100 % offline Text‑to‑Speech on iOS and Android.
🔊 Offline – all synthesis happens on‑device, no network needed | ⚡ Fast – real‑time (or faster) generation on modern phones |
🎙️ Natural voices – drop‑in support for Piper / VITS ONNX models | 🛠️ Simple API – a handful of async methods you already know |
# Add the library
npm install react-native-sherpa-onnx-offline-tts
# or
yarn add react-native-sherpa-onnx-offline-tts
# iOS only\ npx pod-install
Minimum versions | Android 5.0 (API 21) • iOS 11
vits-piper-en_US-ryan-medium.zip
) and host it yourself or bundle it with the app.*.onnx
, tokens.txt
, and the espeak-ng-data
folder.import TTSManager from 'react-native-sherpa-onnx-offline-tts';
import RNFS from 'react-native-fs';
import { unzip } from 'react-native-zip-archive';
const MODEL_URL =
'https://example.com/vits-piper-en_US-ryan-medium.zip';
async function setupTTS() {
const archive = `${RNFS.DocumentDirectoryPath}/vits.zip`;
const extractRoot = `${RNFS.DocumentDirectoryPath}/extracted`;
// 1️⃣ Download if missing
if (!(await RNFS.exists(archive))) {
await RNFS.downloadFile({ fromUrl: MODEL_URL, toFile: archive }).promise;
}
// 2️⃣ Unpack if first run
if (!(await RNFS.exists(`${extractRoot}/vits-piper-en_US-ryan-medium`))) {
await unzip(archive, extractRoot);
}
// 3️⃣ Point the engine to the files
const base = `${extractRoot}/vits-piper-en_US-ryan-medium`;
const cfg = {
modelPath: `${base}/en_US-ryan-medium.onnx`,
tokensPath: `${base}/tokens.txt`,
dataDirPath: `${base}/espeak-ng-data`,
};
// 4️⃣ Initialise (only once per session)
await TTSManager.initialize(JSON.stringify(cfg));
}
async function sayHello() {
const text = 'Hello world – spoken entirely offline!';
const speakerId = 0; // Piper uses 0 for single‑speaker models
const speed = 1.0; // 1 == default, < 1 slower, > 1 faster
await TTSManager.generateAndPlay(text, speakerId, speed);
}
Method | Signature | Description |
---|---|---|
initialize | (modelConfigJson: string): Promise<void> | Must be called once before any synthesis. Pass a JSON string with modelPath , tokensPath , dataDirPath . |
generate | (text: string, speakerId: number, speed: number): Promise<string> | Generates speech and returns the path of the WAV file. |
generateAndPlay | (text: string, speakerId: number, speed: number): Promise<void> | Generates speech and streams it to the device speaker. |
stopPlaying | (): void | Immediately stops playback. |
addVolumeListener | (cb: (volume: number) => void): EmitterSubscription | Subscribes to real‑time RMS volume callbacks during playback. Call subscription.remove() to unsubscribe. |
deinitialize | (): void | Frees native resources – call this when your app unmounts or goes to background for a long time. |
*.onnx
) with matching tokens.txt
and espeak-ng-data
directory.speakerId
.Need other formats? Feel free to open an issue or pull request.
A minimal, production‑ready example (downloads the model on first launch, shows a progress spinner, animates to mic volume, etc.) lives in example/App.tsx
– the snippet below is an abridged version:
const App = () => {
/* full source lives in the repo */
return (
<View style={styles.container}>
{isDownloading ? (
<ProgressBar progress={downloadProgress} />
) : (
<>
<AnimatedCircle scale={volume} />
<Button title="Play" onPress={handlePlay} disabled={isPlaying} />
<Button title="Stop" onPress={handleStop} disabled={!isPlaying} />
</>
)}
</View>
);
};
Bug reports and PRs are welcome! Please see CONTRIBUTING.md for the full development workflow.
Made with ❤️ & create‑react‑native‑library
FAQs
This module is wrapper over sherpa onnx for tts
The npm package react-native-sherpa-onnx-offline-tts receives a total of 3 weekly downloads. As such, react-native-sherpa-onnx-offline-tts popularity was classified as not popular.
We found that react-native-sherpa-onnx-offline-tts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.