Install
dotnet add package WorldNet
Use
This program reads a monaural WAV file, estimates the F0 contour with Harvest, the spectral envelope with CheapTrick and the aperiodicity with D4C, and synthesizes a waveform from the three results.
using WorldNet;
int length = WaveFile.GetLength("input.wav");
double[] x = new double[length];
WaveFile.Read("input.wav", x, out int fs, out _);
using WorldArena arena = new();
HarvestOption harvestOption = HarvestOption.Default;
int f0Length = Harvest.GetSamplesForHarvest(fs, x.Length, harvestOption.FramePeriod);
double[] temporalPositions = new double[f0Length];
double[] f0 = new double[f0Length];
Harvest.Estimate(x, fs, harvestOption, temporalPositions, f0, arena);
CheapTrickOption cheapTrickOption = CheapTrickOption.Create(fs);
int fftSize = cheapTrickOption.FftSize;
int spectrumLength = (fftSize / 2) + 1;
double[] spectrogram = new double[f0Length * spectrumLength];
CheapTrick.Estimate(x, fs, cheapTrickOption, temporalPositions, f0, spectrogram, arena);
double[] aperiodicity = new double[f0Length * spectrumLength];
D4C.Estimate(x, fs, D4COption.Default, temporalPositions, f0, fftSize, aperiodicity, arena);
int yLength = Synthesis.GetSamplesForSynthesis(fs, f0Length, harvestOption.FramePeriod);
double[] y = new double[yLength];
Synthesis.Synthesize(f0, spectrogram, aperiodicity, fftSize, harvestOption.FramePeriod, fs, y, arena);
WaveFile.Write("output.wav", y, fs);
What it does
- Fundamental frequency estimation: Dio, Harvest and StoneMask.
- Spectral envelope estimation: CheapTrick.
- Aperiodicity estimation: D4C.
- Waveform synthesis: batch synthesis and a sequential real-time synthesizer.
- Coding of the spectral envelope and the aperiodicity.
- WAV input and output, and the analysis parameter file format.
Why WorldNet
- Faster than the original C++ in every stage measured. The tables are in the performance section of the README.
- No managed allocation. The garbage collector never observes the analysis or the synthesis path.
- Verified against the original built with MSVC and with GCC. The output is bit-exact in most stages and within a few units in the last place in the rest.
- .NET 8 and later, on x64 and ARM64, Windows and Linux. Native AOT ready. No native library to ship.
Links
- README: requirements, API reference, limitations.
- NuGet package
- Releases
- WORLD, the original by M. Morise.