Supertoys.PocketSphinx 1.2.2

dotnet add package Supertoys.PocketSphinx --version 1.2.2
                    
NuGet\Install-Package Supertoys.PocketSphinx -Version 1.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Supertoys.PocketSphinx" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Supertoys.PocketSphinx" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Supertoys.PocketSphinx" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Supertoys.PocketSphinx --version 1.2.2
                    
#r "nuget: Supertoys.PocketSphinx, 1.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Supertoys.PocketSphinx@1.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Supertoys.PocketSphinx&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Supertoys.PocketSphinx&version=1.2.2
                    
Install as a Cake Tool

Supertoys.PocketSphinx

PocketSphinx 5 integration package for .NET:

  • Parses PocketSphinx output lines (PocketSphinxOutputParser)
  • Locates bundled runtime/model assets (PocketSphinxRuntimePaths)
  • Runs PocketSphinx end-to-end (PocketSphinxRunner)

What Is Bundled

  • Runtime targets shipped now: linux-arm64, linux-x64
  • Bundled executables:
  • runtimes/linux-arm64/native/pocketsphinx
  • runtimes/linux-arm64/native/pocketsphinx_batch
  • runtimes/linux-x64/native/pocketsphinx
  • runtimes/linux-x64/native/pocketsphinx_batch
  • Bundled English model set:
  • models/en-us/en-us (acoustic model directory)
  • models/en-us/cmudict-en-us.dict
  • models/en-us/en-us.lm.bin

Requirements

  • .NET 9 (TargetFramework: net9.0)
  • For end-to-end recognition, run on a supported RID that has bundled runtime assets (linux-arm64 or linux-x64)

Install

dotnet add package Supertoys.PocketSphinx

Quickstart (End-to-End)

using Supertoys.PocketSphinx;

var result = await PocketSphinxRunner.RecognizeFileAsync(new PocketSphinxRunnerOptions
{
    InputPath = "/absolute/path/to/audio.raw", // or .wav supported by PocketSphinx CLI
    RuntimeIdentifier = "linux-x64"
});

Console.WriteLine(result.Hypothesis);
Console.WriteLine(result.Confidence);

Default runner model paths:

  • models/en-us/en-us for -hmm
  • models/en-us/cmudict-en-us.dict for -dict
  • models/en-us/en-us.lm.bin for -lm

Minimal Parser-Only Usage

using Supertoys.PocketSphinx;

var line = "{\"t\":\"hello henry\",\"p\":0.83}";
var text = PocketSphinxOutputParser.ExtractHypothesis(line);
var confidence = PocketSphinxOutputParser.ExtractConfidence(line);

API Reference

  • string PocketSphinxOutputParser.ExtractHypothesis(string line)
  • double PocketSphinxOutputParser.ExtractConfidence(string line)
  • string PocketSphinxRuntimePaths.GetModelsDirectory()
  • string PocketSphinxRuntimePaths.GetNativeRuntimeDirectory()
  • string PocketSphinxRuntimePaths.GetPocketsphinxExecutablePath()
  • string PocketSphinxRuntimePaths.GetDefaultRuntimeIdentifier()
  • Task<PocketSphinxRunnerResult> PocketSphinxRunner.RecognizeFileAsync(PocketSphinxRunnerOptions options, CancellationToken cancellationToken = default)

Runner option highlights:

  • InputPath required
  • RuntimeIdentifier optional but recommended for deterministic behavior
  • ExecutablePath, AcousticModelPath, DictionaryPath, LanguageModelPath optional overrides
  • Mode defaults to single
  • AdditionalArguments appends raw PocketSphinx CLI args

Build/Copy Behavior In Consumer Projects

The package includes buildTransitive/Supertoys.PocketSphinx.targets, which:

  • Copies bundled runtime files into consuming app output under runtimes/<rid>/native
  • Copies bundled models into consuming app output under models/
  • Applies chmod +x on Unix for bundled PocketSphinx executables

Implementation Checklist (Human Or Agent)

  1. Add the package to your app.
  2. Build with -r linux-x64 or -r linux-arm64 (matching your deployment target).
  3. Call PocketSphinxRunner.RecognizeFileAsync(...) with an input audio path.
  4. Read result.Hypothesis and result.Confidence.
  5. If needed, pass custom model/runtime paths in options.

Troubleshooting

  • PocketSphinx executable not found:
  • Ensure app was built/published with RuntimeIdentifier=linux-x64 or RuntimeIdentifier=linux-arm64.
  • Ensure output contains runtimes/<rid>/native/pocketsphinx.
  • Dictionary file not found or Language model file not found:
  • Ensure output contains models/en-us/....
  • Recognition returns empty text:
  • Check result.StandardError and result.StandardOutput for CLI diagnostics.

Publishing

This repo is configured for NuGet Trusted Publishing via GitHub Actions OIDC in .github/workflows/publish.yml.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.2 114 4/20/2026
1.2.1 144 3/16/2026
1.0.3 135 3/13/2026