Skip to content

Commit

Permalink
Add tts_en_hifigan, upgrade OnnxRuntime with 1.16.0 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiidams authored Sep 27, 2023
1 parent 9c037e1 commit 28b439b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NeMoOnnxSharp.Example/NeMoOnnxSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.15.1" />
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.16.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions NeMoOnnxSharp.Example/PretrainedModelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ private static PretrainedModelInfo[] CreateModelList()
"commandrecognition_en_matchboxnet3x1x64_v2",
"https://github.com/kaiidams/NeMoOnnxSharp/releases/download/v1.1/commandrecognition_en_matchboxnet3x1x64_v2.onnx",
"a0c5e4d14e83d3b6afdaf239265a390c2ca513bcdedf3d295bc1f9f97f19868a"
),
new PretrainedModelInfo(
"tts_en_hifigan",
"https://github.com/kaiidams/NeMoOnnxSharp/releases/download/v1.2/tts_en_hifigan.onnx",
"54501000b9de86b724931478b5bb8911e1b6ca6e293f68e9e10f60351f1949a3"
)
};
}
Expand Down
3 changes: 1 addition & 2 deletions NeMoOnnxSharp/ASRModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ protected float[] TransposeInputSignal(Span<float> inputSignal, int nFeatures)
}
return transposedSignal;
}

}
}
}
2 changes: 1 addition & 1 deletion NeMoOnnxSharp/NeMoOnnxSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.15.1" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.16.0" />
</ItemGroup>

</Project>
58 changes: 58 additions & 0 deletions NeMoOnnxSharp/Vocoder.cs
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();
}
}
}

0 comments on commit 28b439b

Please sign in to comment.