-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tts_en_hifigan, upgrade OnnxRuntime with 1.16.0 (#14)
- Loading branch information
Showing
5 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Katsuya Iida. All Rights Reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
using Microsoft.ML.OnnxRuntime; | ||
using Microsoft.ML.OnnxRuntime.Tensors; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NeMoOnnxSharp | ||
{ | ||
public class Vocoder : IDisposable | ||
{ | ||
private readonly InferenceSession _inferSess; | ||
private readonly int _nfilt; | ||
private readonly int _sampleRate; | ||
private Vocoder(InferenceSession inferSess) | ||
{ | ||
_inferSess = inferSess; | ||
_nfilt = 80; | ||
_sampleRate = 22050; | ||
} | ||
|
||
public Vocoder(string modelPath) | ||
: this(new InferenceSession(modelPath)) | ||
{ | ||
} | ||
|
||
public Vocoder(byte[] model) | ||
: this(new InferenceSession(model)) | ||
{ | ||
} | ||
|
||
public int SampleRate { get { return _sampleRate; } } | ||
|
||
public void Dispose() | ||
{ | ||
_inferSess.Dispose(); | ||
} | ||
|
||
public short[] ConvertSpectrogramToAudio(float[] spec) | ||
{ | ||
var container = new List<NamedOnnxValue>(); | ||
var specData = new DenseTensor<float>( | ||
spec, | ||
new int[3] { 1, _nfilt, spec.Length / _nfilt }); | ||
container.Add(NamedOnnxValue.CreateFromTensor("spec", specData)); | ||
float[] audio; | ||
using (var res = _inferSess.Run(container, new string[] { "audio" })) | ||
{ | ||
var audioTensor = res.First().AsTensor<float>(); | ||
audio = audioTensor.ToArray(); | ||
} | ||
return audio.Select(x => (short)(x * short.MaxValue)).ToArray(); | ||
} | ||
} | ||
} |