All Projects → igece → SoxSharp

igece / SoxSharp

Licence: Apache-2.0 license
.NET wrapper for SoX.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to SoxSharp

java-xml-to-json
👾 convert XML to a structure-preserving JSON representation
Stars: ✭ 15 (-63.41%)
Mutual labels:  converter
bank2ynab
Easily convert and import your bank's statements into YNAB. This project consolidates other conversion efforts into one universal tool.
Stars: ✭ 197 (+380.49%)
Mutual labels:  converter
System.Configuration.Abstractions
Injectable, mockable, extensible, configuration for .NET
Stars: ✭ 42 (+2.44%)
Mutual labels:  converter
Audiblex
Audible audio book converter which actually works!
Stars: ✭ 26 (-36.59%)
Mutual labels:  converter
readable-web-to-node-stream
Converts a Web-API readable-stream into a Node readable-stream.
Stars: ✭ 33 (-19.51%)
Mutual labels:  converter
converter-go
Convert AsyncAPI documents from older to newer versions with Golang
Stars: ✭ 17 (-58.54%)
Mutual labels:  converter
guepard
flash to html5 converter, as3 to javascript translator
Stars: ✭ 58 (+41.46%)
Mutual labels:  converter
vectorexpress-api
Vector Express is a free service and API for converting, analyzing and processing vector files.
Stars: ✭ 66 (+60.98%)
Mutual labels:  converter
my-notes
工程师的自我修养
Stars: ✭ 28 (-31.71%)
Mutual labels:  effects
ZPL-Printer-Emulator-SDK
Convert, Preview & Render raw ZPL commands to PNG, JPG & PDF from .NET
Stars: ✭ 29 (-29.27%)
Mutual labels:  converter
slackdown
A simple Slack message text formatting to HTML code converter.
Stars: ✭ 27 (-34.15%)
Mutual labels:  converter
json2table
Converts JSON to an HTML table
Stars: ✭ 52 (+26.83%)
Mutual labels:  converter
UnityGUI
UGUI Panel Systems for navigation, animation and more
Stars: ✭ 80 (+95.12%)
Mutual labels:  effects
freedsl
Practical effect composition library based on abstract wrapping type and the free monad
Stars: ✭ 37 (-9.76%)
Mutual labels:  effects
ics-to-json
📅 Convert ICS calendars (eg. Google Calendar) to an opinionated JSON format.
Stars: ✭ 36 (-12.2%)
Mutual labels:  converter
csv2vcf
🔧 Simple script in python to convert CSV files to VCF
Stars: ✭ 66 (+60.98%)
Mutual labels:  converter
caffe weight converter
Caffe-to-Keras weight converter. Can also export weights as Numpy arrays for further processing.
Stars: ✭ 68 (+65.85%)
Mutual labels:  converter
gpx-converter
python package for manipulating gpx files and easily converting gpx to other different formats
Stars: ✭ 54 (+31.71%)
Mutual labels:  converter
xamarin-forms-statusbar
Xamarin.Forms Effect to manage the StatusBar BackgroundColor.
Stars: ✭ 16 (-60.98%)
Mutual labels:  effects
dnglab
Camera RAW to DNG file format converter
Stars: ✭ 103 (+151.22%)
Mutual labels:  converter

nuget nuget Build

SoxSharp

SoxSharp is a C# library that serves as a wrapper to SoX - the Sound eXchange tool. SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files and play and record audio files on most platforms.

How It Works

Initial Setup

When instantiating the Sox class, we pass to the constructor the location of the SoX executable to be used. Please note that, when SoX is executed, the directory of the application using the library will be used as the working directory, so any relative path included in both input and output files shall be relative to this directory.

Get File Information

Usage is pretty straightforward:

using (var sox = new Sox("sox.exe"))
{
  AudioInfo wavInfo = sox.GetInfo("test.wav");
  Console.WriteLine(wavInfo);
}

This is the same as executing sox --info test.wav. SoxSharp parses the SoX output and fills an AudioInfo instance with the retrieved information.

File Conversion

The simplest way to perform an audio conversion is to just call the Sox.Process method with both input and output files:

using (var sox = new Sox("sox.exe"))
{
  sox.Process("test.wav", "test.mp3");
}

The previous code will launch SoX with 'test.wav' as input file and 'test.mp3' as output file (the equivalent of executing SoX with the following parameters: sox test.wav test.mp3).

To force the output to be encoded with MP3 format (instead of letting SoX to guess it from the output file extension) and use a sample rate of 32 KHz:

using (var sox = new Sox("sox.exe"))
{
  sox.Output.Type = FileType.MP3;
  sox.Output.SampleRate = 32000;

  sox.Process("test.wav", "test.mp3");
}

This is equivalent to call SoX with the following parameters: sox test.wav --type mp3 --rate 32000 test.mp3.

SoX global options can be set through their respective properties in the Sox class. Format options to be applied to the output can be stablished through its respective properties in Sox.Output.

Format options to be applied to the input are specified passing an InputFile instance to the Sox.Process method (instead of an input file string):

using (var sox = new Sox("sox.exe"))
{
  sox.Output.Type = FileType.MP3;
  sox.Output.SampleRate = 32000;

  InputFile testInput = new InputFile("test.wav");
  testInput.Volume = 0.8;

  sox.Process(testInput, "test.mp3");
}

This is equivalent to call SoX with the following parameters: sox --volume 0.8 test.wav --type mp3 --rate 32000 test.mp3.

Applying Effects

One or multiple effects can be added so they will applied to the output file:

using (var sox = new Sox("sox.exe"))
{
  sox.Output.Type = FileType.MP3;
  sox.Effects.Add(new VolumeEffect(10, GainType.Db));
  sox.Effects.Add(new HighPassFilterEffect(500));

  sox.Process("test.wav", "test.mp3");
}

Currently not all SoX effects have been implemented into SoxSharp. To see which effects are supported, please read this issue.

Playing and Recording

To record audio from the default audio device, use the Sox.Record method specifying the output file name:

sox.Record("test_record.mp3");

Analogously, Sox.Play allows to send an input file to the default audio device. In this case, the input file can be expressed as an file name string or a InputFile instance.

The same results can be obtained if calling Sox.Process using --default-device as output (for playing) or input (for recording) file.

Error Handling

If any requested SoX operation is unable to be processed, either because SoX process can't be launched or beacuse it generates an error, a SoxException with details about the error will be thrown.

Events

You can subscribe to receive any log message generated by SoX through the OnLogMessage event. Please note that log messages of type FAIL will not be reported through this event but as exceptions, as stated in Error Handling.

// Subscribe to OnLogMessage.
sox.OnLogMessage += sox_OnLogMessage;

void sox_OnLogMessage(object sender, LogMessageEventArgs e)
{
  Console.WriteLine(e.LogLevel + ": " + e.Message);
}

Also, while executing a Process call you can obtain updated progress information about the operation subscribing to the OnProgress event:

// Subscribe to OnProgress event before calling Process method.
sox.OnProgress += sox_OnProgress;

void sox_OnProgress(object sender, ProgressEventArgs e)
{
  Console.WriteLine("{0} ({1}% completed)", e.Processed.ToString(@"hh\:mm\:ss\.ff"), e.Progress);
}

Concurrency

All the work is done in the calling thread. Each Sox class instance can handle only one process at the same time, and will block the calling thread until finished. You are responsible for creating any worker thread if needed.

The library provides two different methods to cancel any work that is in progress:

  • Calling the Abort() method of the Sox class.

  • Inside the OnProgress event handler. ProgressEventArgs provides a boolean Abort member that can be set to true to end the current work.

Library Reference

A detailed description of all components of the library is available at the repository wiki.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].