Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SilkCodec.NET

Build NuGet packages NuGet

Pure .NET Silk v3 speech codec. It encodes 16-bit little-endian PCM and decodes #!SILK_V3 streams, including the Tencent/WeChat leading 0x02 marker.

This library is written in C#. It does not load native silkcodec binaries and is not a conversion of the Skype SILK C sources.

Install

dotnet add package DrAbc.SilkCodec

Target frameworks: net10.0, net8.0, net472.

Encode

var encoder = new SilkEncoder(new SilkEncoderOptions
{
    SampleRate = 24000,
    BitRate = 25000,
    Tencent = true
});

byte[] silk = encoder.Encode(File.ReadAllBytes("voice.pcm"));
encoder.Encode("voice.pcm", "voice.silk");

Decode

var decoder = new SilkDecoder(new SilkDecoderOptions
{
    SampleRate = 24000
});

byte[] pcm = decoder.Decode(File.ReadAllBytes("voice.silk"));
decoder.Decode("voice.silk", "voice.pcm");

Extensions

The core package encodes and decodes raw 16-bit little-endian PCM. Companion packages convert other audio formats through popular C# audio libraries. Each extension is a separate NuGet package.

Package Formats Target
DrAbc.SilkCodec.NAudio Any format NAudio can read; write WAV, PCM, MP3, AAC/M4A, WMA, FLAC net10.0-windows
DrAbc.SilkCodec.CSCore Any format CSCore can read; write WAV, PCM, MP3, AAC/M4A, WMA net10.0-windows, net8.0-windows, net472
DrAbc.SilkCodec.FFMpegCore Any format FFmpeg can read or write net10.0, net8.0, net472 (FFmpeg required)
dotnet add package DrAbc.SilkCodec.NAudio
dotnet add package DrAbc.SilkCodec.CSCore
dotnet add package DrAbc.SilkCodec.FFMpegCore
using SilkCodec.NET;
using SilkCodec.NET.NAudio;

var encoder = new SilkEncoder(new SilkEncoderOptions
{
    SampleRate = 24000,
    BitRate = 25000,
    Tencent = true
});

byte[] silk = encoder.EncodeFile("voice.mp3");
encoder.EncodeFile("voice.wav", "voice.silk");

var decoder = new SilkDecoder(new SilkDecoderOptions { SampleRate = 24000 });
decoder.DecodeFile("voice.silk", "voice.wav");
byte[] wav = decoder.DecodeToWav(silk);

.pcm, .raw and .s16le files are treated as signed 16-bit little-endian mono at the encoder or decoder sample rate.

CLI

The repository includes a small command-line tool. It is a separate executable and is not included in the NuGet package.

dotnet run --project src/SilkCodec.NET.Cli -- encode voice.pcm voice.silk --tencent
dotnet run --project src/SilkCodec.NET.Cli -- decode voice.silk voice.pcm

Useful options:

silkcodec encode <input.pcm> [output.silk] [-r 24000] [-b 25000] [-t]
silkcodec decode <input.silk> [output.pcm] [-r 24000]

If the output path is omitted, the input extension is changed to .silk or .pcm.

Encode and decode print elapsed time. To compare throughput against the test clips:

dotnet run --project src/SilkCodec.NET.Cli -c Release -- bench tests/SilkCodec.NET.Tests/assets

Compatibility

  • Container: #!SILK_V3, optional Tencent 0x02 prefix, little-endian frame lengths, optional -1 terminator when not Tencent
  • Payload: Silk SDK 1.0.9 / WeChat-QQ Silk v3 range-coded frames
  • PCM: packed signed 16-bit little-endian, mono

The decoder reads existing Silk v3 files. The encoder emits a valid Silk v3 bitstream that this decoder (and other Silk v3 decoders) can play. Encoder output is not bit-identical to the Skype SDK.

License

MIT (Expat), see LICENSE.

About

SILK V3 Codec in pure C#

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages