tryAGI.OpusSharp 1.0.2

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package tryAGI.OpusSharp --version 1.0.2
                    
NuGet\Install-Package tryAGI.OpusSharp -Version 1.0.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="tryAGI.OpusSharp" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="tryAGI.OpusSharp" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="tryAGI.OpusSharp" />
                    
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 tryAGI.OpusSharp --version 1.0.2
                    
#r "nuget: tryAGI.OpusSharp, 1.0.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 tryAGI.OpusSharp@1.0.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=tryAGI.OpusSharp&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=tryAGI.OpusSharp&version=1.0.2
                    
Install as a Cake Tool

OpusSharp

High-performance C# bindings for the Opus audio codec with bundled native runtime libraries.

The NuGet package id is tryAGI.OpusSharp. The public namespace remains OpusSharp.

Features

  • Complete encoder and decoder API over libopus.
  • PCM16 encode/decode with configurable sample rate, channel count, frame duration, application mode, bitrate, VBR, FEC, DTX, bandwidth, and complexity.
  • Packet loss concealment, forward error correction, packet inspection, and repacketization helpers.
  • Bundled native binaries for Windows x64, macOS universal x64/arm64, Linux x64, and Linux arm64.
  • A small opus_sharp native shim for non-variadic encoder/decoder CTL calls.
  • net10.0 target with nullable reference types enabled.

Installation

dotnet add package tryAGI.OpusSharp

Basic Encoding

using OpusSharp;

var config = OpusConfig.VoiceMediumQualityMono(SampleRate.Hz16k);
using var encoder = new OpusEncoder(config);

var sampleRate = 16000;
var frameSize = config.SampleRate.FrameSize(config.FrameDuration);
var pcm = new short[frameSize];

for (var i = 0; i < frameSize; i++)
{
    var t = (float)i / sampleRate;
    pcm[i] = (short)(Math.Sin(2 * Math.PI * 440 * t) * short.MaxValue * 0.5f);
}

var encodedData = encoder.Encode(pcm, frameSize);
Console.WriteLine($"Encoded {frameSize} samples to {encodedData.Length} bytes");

Basic Decoding

using OpusSharp;

var config = OpusConfig.VoiceMediumQualityMono(SampleRate.Hz16k);
using var decoder = new OpusDecoder(config);

var decodedPcm = decoder.Decode(encodedData, config.FrameDuration);
Console.WriteLine($"Decoded {encodedData.Length} bytes to {decodedPcm.Length} samples");

Custom Configuration

var config = new OpusConfig
{
    SampleRate = SampleRate.Hz48k,
    Channels = Channels.Stereo,
    FrameDuration = FrameDuration.Ms10,
    Application = Application.Audio,
    Complexity = 8,
    Bitrate = 128000,
    Fec = true,
};

using var encoder = new OpusEncoder(config);
using var decoder = new OpusDecoder(config);

Encoder Presets

using var voiceEncoder = new OpusEncoder(OpusConfig.VoiceMediumQualityMono(SampleRate.Hz16k));
using var musicEncoder = new OpusEncoder(OpusConfig.MusicStereo(SampleRate.Hz48k));
using var lowBandwidthEncoder = new OpusEncoder(OpusConfig.VoiceLowQualityMono(SampleRate.Hz16k));

Advanced Features

Forward Error Correction

var config = OpusConfig.VoiceMediumQualityMono(SampleRate.Hz48k);
config.Fec = true;

using var encoder = new OpusEncoder(config);
using var decoder = new OpusDecoder(config);

var decodedWithFEC = decoder.DecodeWithFEC(currentPacket, useFEC: true, config.FrameDuration);

Packet Loss Concealment

var concealedAudio = decoder.GeneratePLC(FrameDuration.Ms20);

Runtime Encoder Controls

using var encoder = new OpusEncoder(OpusConfig.VoiceMediumQualityMono(SampleRate.Hz48k));

encoder.SetBitrate(24000);
encoder.SetComplexity(8);
encoder.SetVbr(enabled: true, constrained: false);
encoder.SetFec(enabled: true);

Native Libraries

The package contains native runtime assets under NuGet runtimes/<rid>/native/:

  • runtimes/win-x64/native/opus.dll
  • runtimes/win-x64/native/libopus-0.dll
  • runtimes/win-x64/native/opus_sharp.dll
  • runtimes/osx-x64/native/libopus.dylib
  • runtimes/osx-x64/native/libopus_sharp.dylib
  • runtimes/osx-arm64/native/libopus.dylib
  • runtimes/osx-arm64/native/libopus_sharp.dylib
  • runtimes/linux-x64/native/libopus.so
  • runtimes/linux-x64/native/libopus.so.0
  • runtimes/linux-x64/native/libopus_sharp.so
  • runtimes/linux-arm64/native/libopus.so
  • runtimes/linux-arm64/native/libopus.so.0
  • runtimes/linux-arm64/native/libopus_sharp.so

The native binaries are committed in natives/ so consumers do not need a system libopus installation.

Rebuilding Native Binaries

Vendored Opus 1.5.2 source lives in third_party/opus/opus-1.5.2/, with the .NET CTL shim in third_party/opus/shim/opus_shim.c.

Run the rebuild script from the repository root:

third_party/opus/build-opussharp.sh

The script writes refreshed binaries into natives/. macOS builds require Xcode command line tools. Linux builds use Docker. Windows x64 builds require x86_64-w64-mingw32-gcc.

Build And Test

dotnet build OpusSharp.slnx
dotnet test src/tests/OpusSharp.Tests/OpusSharp.Tests.csproj
dotnet pack src/libs/OpusSharp/OpusSharp.csproj -c Release

License

OpusSharp is licensed under MIT. Vendored Opus source and derived native binaries retain the Opus license; see THIRD-PARTY-NOTICES.md.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.
  • net10.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.0.3-dev.7 23 9/25/2026
1.0.3-dev.6 37 9/25/2026
1.0.3-dev.5 59 9/17/2026
1.0.3-dev.4 53 9/11/2026
1.0.3-dev.3 65 9/11/2026
1.0.3-dev.2 65 8/30/2026
1.0.3-dev.1 61 8/30/2026
1.0.2 986 6/26/2026
1.0.2-dev.1 79 6/26/2026
1.0.1 124 6/26/2026
1.0.1-dev.1 74 6/26/2026
1.0.0 134 6/25/2026