From 1596f6f414f6f41da66506debb1dff19fffeb3ec Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期一, 24 六月 2024 11:55:17 +0800
Subject: [PATCH] fixbug hotwords
---
runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs | 63 +++++++++++++++++++++----------
1 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs b/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs
index f42bfb1..672eac2 100644
--- a/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs
+++ b/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs
@@ -1,19 +1,16 @@
-锘縰sing System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.ML;
+锘縰sing AliFsmnVadSharp.Model;
+using AliFsmnVadSharp.Utils;
+using Microsoft.Extensions.Logging;
using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
-using Microsoft.Extensions.Logging;
-using AliFsmnVadSharp.Model;
-using AliFsmnVadSharp.Utils;
namespace AliFsmnVadSharp
{
- public class AliFsmnVad
+ public class AliFsmnVad : IDisposable
{
+ private bool _disposed;
private InferenceSession _onnxSession;
- private readonly ILogger<AliFsmnVad> _logger;
+ private readonly ILogger _logger;
private string _frontend;
private WavFrontend _wavFrontend;
private int _batchSize = 1;
@@ -23,7 +20,7 @@
public AliFsmnVad(string modelFilePath, string configFilePath, string mvnFilePath, int batchSize = 1)
{
- Microsoft.ML.OnnxRuntime.SessionOptions options = new Microsoft.ML.OnnxRuntime.SessionOptions();
+ SessionOptions options = new SessionOptions();
options.AppendExecutionProvider_CPU(0);
options.InterOpNumThreads = 1;
_onnxSession = new InferenceSession(modelFilePath, options);
@@ -371,17 +368,41 @@
}
return speech;
}
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ if (_onnxSession != null)
+ {
+ _onnxSession.Dispose();
+ }
+ if (_wavFrontend != null)
+ {
+ _wavFrontend.Dispose();
+ }
+ if (_encoderConfEntity != null)
+ {
+ _encoderConfEntity = null;
+ }
+ if (_vad_post_conf != null)
+ {
+ _vad_post_conf = null;
+ }
+ }
+ _disposed = true;
+ }
+ }
-
-
-
-
-
-
-
-
-
-
-
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+ ~AliFsmnVad()
+ {
+ Dispose(_disposed);
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.1