Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/sherpa-onnx.git

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **PonyuDev Sherpa-ONNX** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/sherpa-onnx.git
```

[![pkglnk](https://www.pkglnk.dev/badge/sherpa-onnx.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/sherpa-onnx)

Dependencies (2)

README

Unity-Sherpa-ONNX

Unity integration plugin for sherpa-onnx β€” an open-source speech toolkit powered by ONNX Runtime.

πŸ—ΊοΈ Feature Roadmap

Feature Description Status
Text-to-Speech (TTS) Offline speech synthesis β€” VITS, Matcha, Kokoro, Kitten, ZipVoice, Pocket (voice cloning) βœ… Done
Speech Recognition (ASR) Offline and streaming speech-to-text β€” Zipformer, Paraformer, Whisper, SenseVoice, Moonshine βœ… Done
Voice Activity Detection (VAD) Speech/silence segmentation for efficient ASR β€” Silero VAD, TEN-VAD βœ… Done
Keyword Spotting (KWS) Lightweight always-on keyword detection from microphone πŸ“‹ Planned
Speaker ID & Diarization Speaker identification by voice, who-spoke-when segmentation πŸ“‹ Planned
Audio Tools Audio tagging, speech enhancement, punctuation restoration, language identification πŸ“‹ Planned

πŸ–₯️ Supported Platforms

Platform Architectures
πŸͺŸ Windows x64, x86, arm64
🍎 macOS x64, arm64
🐧 Linux x64, arm64
πŸ€– Android arm64-v8a, armeabi-v7a, x86, x86_64
πŸ“± iOS arm64, x86_64-simulator

πŸ’‘ Why This Plugin

Integrating sherpa-onnx into a Unity project normally requires manual native library setup, platform-specific workarounds, and custom C# bindings. This plugin handles all of that out of the box.

⚑ Easy Setup

  • πŸ”Œ One-click library install β€” open Project Settings, pick a version, click Install. Native libraries for Windows, macOS, Linux, Android, and iOS are downloaded and configured automatically.
  • πŸ“₯ One-click model import β€” paste a model URL, the importer downloads, extracts, auto-detects the model type, and creates a ready-to-use profile. No manual config editing.
  • πŸ”„ Update All β€” change the version number and update every installed platform at once.

πŸ”§ Platform Solutions

The plugin solves real-world platform issues that are not addressed by sherpa-onnx itself:

Problem Platform What the plugin does
πŸ”‡ Unity Microphone returns silence Android Detects silence automatically, falls back to native AudioRecord via JNI with audio source cascade (VOICE_RECOGNITION β†’ VOICE_COMMUNICATION β†’ MIC). Disables NoiseSuppressor, AGC, and AEC that can mute the signal. Fires SilenceDetected event with full diagnostics.
πŸ“¦ StreamingAssets locked inside APK Android Extracts model files to persistentDataPath on first launch with version tracking and progress reporting. Skips re-extraction on subsequent launches.
🌍 Non-US locale breaks native code Android Wraps native calls with a locale guard that temporarily sets LC_NUMERIC to "C", preventing comma-as-decimal crashes in sherpa-onnx's float parsing.
🍏 No dynamic library loading iOS Builds a patched sherpa-onnx.dll with DllImport("__Internal") and downloads it automatically during install.
βœ‚οΈ Xcframework architecture bloat iOS Filters xcframeworks to only the target architecture (device or simulator) during install.
πŸŽ™οΈ Microphone not actually recording Unity (all) Plays a silent AudioSource on the mic clip to force the device to start recording β€” a known Unity workaround.
⏳ Microphone readiness delay Unity (all) Polls Microphone.GetPosition() with a configurable timeout before starting capture.
🎡 Sample rate mismatch All Built-in resampler converts any input rate to the model's expected rate (typically 16 kHz).
πŸ” Microphone permission Android / iOS Async permission request with UniTask β€” returns false gracefully if denied.

βš™οΈ All microphone settings (silence threshold, fallback timing, diagnostics) are configurable via a JSON file in StreamingAssets β€” no code changes needed.


πŸ“¦ Installation

Option 1 - Installer

  • ⬇️ Download Installer
  • πŸ“‚ Import installer into Unity project
    • Double-click the file β€” Unity will open it
    • OR: Unity Editor β†’ Assets β†’ Import Package β†’ Custom Package, then choose the file
  • The installer adds OpenUPM scoped registry and resolves the package automatically

Option 2 - OpenUPM (Scoped Registry)

  • πŸ“‚ Open Packages/manifest.json in your project
  • ✏️ Add the scoped registry and dependency:
    {
      "scopedRegistries": [
        {
          "name": "OpenUPM",
          "url": "https://package.openupm.com",
          "scopes": [
            "com.ponyudev.sherpa-onnx",
            "com.cysharp.unitask"
          ]
        }
      ],
      "dependencies": {
        "com.ponyudev.sherpa-onnx": "0.1.0"
      }
    }
    
  • βœ… Unity will resolve and download the package automatically

Option 3 - OpenUPM CLI

  • πŸ“¦ Install openupm-cli
  • ▢️ Run the command in your project folder:
    openupm add com.ponyudev.sherpa-onnx
    
  • βœ… Dependencies are resolved automatically

Option 4 - Git URL

  • ⚠️ Install UniTask first β€” open Window β†’ Package Manager, click + β†’ Add package from git URL... and paste:
    https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask
    
  • πŸ”— Then add Sherpa-ONNX the same way:
    https://github.com/Ponyu-dev/Unity-Sherpa-ONNX.git
    

πŸ”Œ Installing Native Libraries

Library Install

  1. Open Edit β†’ Project Settings β†’ Sherpa ONNX
  2. Set the desired sherpa-onnx version (e.g. 1.12.25)
  3. Click Install for each platform you need
  4. Use Update All when you change the version to update all installed libraries at once

πŸ“₯ Libraries are downloaded from:


πŸ—£οΈ Text-to-Speech (TTS)

Offline speech synthesis with pooling and caching. Supports 6 model architectures.

Setting Up TTS Models

TTS Model Import

  1. Open Project Settings > Sherpa-ONNX > TTS
  2. Click Import from URL and paste a model archive link
  3. The importer downloads, extracts, and auto-configures the profile
  4. Select the Active profile to use at runtime

Key features:

  • 🧠 6 model architectures β€” Vits (Piper), Matcha, Kokoro, Kitten, ZipVoice, Pocket
  • πŸ” Auto-detection β€” model type and paths are configured automatically from the archive
  • ⚑ Int8 quantization β€” one-click switch between normal and int8 models
  • πŸš€ Flexible deployment β€” Local (StreamingAssets), Remote (runtime download), or LocalZip (compressed at build time)
  • πŸŽ›οΈ Matcha vocoder selector β€” choose and download vocoders independently
  • ♻️ Cache pooling β€” configurable pools for audio buffers, AudioClips, and AudioSources

πŸ“– Documentation


πŸ‘‚ Speech Recognition (ASR)

Offline file recognition and real-time streaming with microphone. Supports 15 offline and 5 online model architectures.

Setting Up ASR Models

ASR Model Import

  1. Open Project Settings > Sherpa-ONNX > ASR
  2. Select the Offline or Online tab
  3. Click Import from URL and paste a model archive link
  4. The importer downloads, extracts, and auto-configures the profile
  5. Select the Active profile to use at runtime

Key features:

  • 🧠 15 offline + 5 online architectures β€” Zipformer, Paraformer, Whisper, SenseVoice, Moonshine, and more
  • πŸ” Auto-detection β€” model type and paths are configured automatically from the archive
  • ⚑ Int8 quantization β€” one-click switch between normal and int8 models
  • πŸŽ™οΈ Streaming recognition β€” real-time microphone capture with partial and final results
  • 🏊 Engine pool β€” multiple concurrent recognizer instances for offline ASR
  • ⏹️ Endpoint detection β€” configurable silence rules for automatic utterance segmentation

πŸ“– Documentation


πŸ”Š Voice Activity Detection (VAD)

Speech/silence segmentation for efficient ASR pipelines. Supports Silero VAD and TEN-VAD models.

Setting Up VAD Models

VAD Model Import

  1. Open Project Settings > Sherpa-ONNX > VAD
  2. Click Import from URL and paste a model archive link
  3. The importer downloads, extracts, and auto-configures the profile
  4. Select the Active profile to use at runtime

Key features:

  • 🧠 2 model architectures β€” Silero VAD, TEN-VAD
  • πŸ” Auto-detection β€” model type and paths are configured automatically from the archive
  • πŸŽ›οΈ Configurable parameters β€” threshold, min silence/speech duration, window size
  • πŸ”— VAD + ASR pipeline β€” segment audio by voice activity, then recognize each segment

πŸ“– Documentation


🍏 Why the iOS Managed DLL Is Hosted Here

On desktop and Android, Unity loads native code via dynamic libraries (.dll, .so, .dylib). The managed C# binding (sherpa-onnx.dll) uses DllImport("sherpa-onnx-c-api") to find them at runtime.

iOS does not support dynamic loading. All native code must be statically linked into the app binary. This means the managed DLL must use DllImport("__Internal") instead of "sherpa-onnx-c-api".

The upstream sherpa-onnx NuGet package ships with the standard "sherpa-onnx-c-api" binding, which does not work on iOS. To solve this, the Tools~/ scripts in this repository:

  1. Take the official C# sources from sherpa-onnx/scripts/dotnet/
  2. Patch Dll.cs to replace "sherpa-onnx-c-api" with "__Internal"
  3. Build a custom sherpa-onnx.dll targeting netstandard2.0
  4. Publish it as a GitHub release with tag sherpa-v{version}

The plugin's iOS install pipeline downloads this patched DLL automatically.

🏷️ Scripting Define Symbol

After installing any library, the plugin automatically adds SHERPA_ONNX to Scripting Define Symbols for all build targets. This allows you to guard runtime code that depends on sherpa-onnx:

#if SHERPA_ONNX
    var recognizer = new OnlineRecognizer(config);
#endif

The define is removed automatically when all libraries are uninstalled.

πŸ“‹ Requirements

  • Unity 2022.3 or later
  • com.unity.sharp-zip-lib 1.4.1+ (added automatically as a dependency)

πŸ“„ License

Apache 2.0

Comments

No comments yet. Be the first!