NeuralCodecs 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NeuralCodecs --version 0.1.0                
NuGet\Install-Package NeuralCodecs -Version 0.1.0                
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="NeuralCodecs" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NeuralCodecs --version 0.1.0                
#r "nuget: NeuralCodecs, 0.1.0"                
#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.
// Install NeuralCodecs as a Cake Addin
#addin nuget:?package=NeuralCodecs&version=0.1.0

// Install NeuralCodecs as a Cake Tool
#tool nuget:?package=NeuralCodecs&version=0.1.0                

NeuralCodecs

NeuralCodecs is a .NET library for neural audio codec implementations, designed for efficient audio compression and reconstruction.

Features

Work In Progress

Requirements

  • Torchsharp or libTorch targeting your desired platform

Usage

Creating/loading the model

There are several ways to load a model:

  1. Using static factory method:
// Load SNAC model with static method provided for built-in models
var model = await NeuralCodecs.CreateSNACAsync("model.pt");
  1. Using premade config:
    SnacConfig provides premade configurations for 24kHz, 32kHz, and 44kHz sampling rates.
var model = await NeuralCodecs.CreateSNACAsync(modelPath, SNACConfig.SNAC24Khz);
  1. Using IModelLoader instance with default config
    Allows the use of custom loader implementations
// Load model with default config from IModelLoader instance
var torchLoader = NeuralCodecs.CreateTorchLoader();
var model = await torchLoader.LoadModelAsync<SNAC, SNACConfig>("model.pt");
  1. Using IModelLoader instance with custom config:
var config = new SNACConfig { /* ... */ };
var model = await torchLoader.LoadModelAsync<SNAC, SNACConfig>("model.pt", config);
  1. Using factory method for custom models:
    Allows the use of custom model implementations with built-in loaders
// Load custom model with factory method
var model = await torchLoader.LoadModelAsync<CustomModel, CustomConfig>(
    "model.pt",
    config => new CustomModel(config, ...),
    config);

Encoding and Decoding Audio

There are two main ways to process audio:

  1. Using the simplified ProcessAudio method:
// Compress audio in one step
var processedAudio = model.ProcessAudio(audioData, sampleRate);
  1. Using separate encode and decode steps:
// Encode audio to compressed format
var codes = model.Encode(buffer);

// Decode back to audio
var processedAudio = model.Decode(codes);
  1. Saving the processed audio

    Use your preferred method to save WAV files

// using NAudio
await using var writer = new WaveFileWriter(
    outputPath,
    new WaveFormat(model.Config.SamplingRate, 1)
);
writer.WriteSamples(processedAudio, 0, processedAudio.Length);

Acknowledgments

Contributing

Suggestions and contributions are welcome! Feel free to submit a pull request.

License

This project is licensed under the MIT License.

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

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
0.1.3 48 11/27/2024
0.1.1 76 11/23/2024
0.1.0 64 11/21/2024