From 28ccfbfc51068a663a80764e14074df5edf2b5ba Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期五, 13 三月 2026 17:41:41 +0800
Subject: [PATCH] 提交

---
 runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs |   69 +++++++++++++++++++++++-----------
 1 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs b/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs
index f42bfb1..aad8bf5 100644
--- a/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs
+++ b/runtime/csharp/AliFsmnVad/AliFsmnVadSharp/AliFsmnVad.cs
@@ -1,19 +1,18 @@
-锘縰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;
+
+// 妯″瀷鏂囦欢涓嬭浇鍦板潃锛歨ttps://modelscope.cn/models/iic/speech_fsmn_vad_zh-cn-16k-common-onnx/
 
 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 +22,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);
@@ -31,9 +30,9 @@
             VadYamlEntity vadYamlEntity = YamlHelper.ReadYaml<VadYamlEntity>(configFilePath);
             _wavFrontend = new WavFrontend(mvnFilePath, vadYamlEntity.frontend_conf);
             _frontend = vadYamlEntity.frontend;
-            _vad_post_conf = vadYamlEntity.vad_post_conf;
+            _vad_post_conf = vadYamlEntity.model_conf;
             _batchSize = batchSize;
-            _max_end_sil = _max_end_sil != int.MinValue ? _max_end_sil : vadYamlEntity.vad_post_conf.max_end_silence_time;
+            _max_end_sil = _max_end_sil != int.MinValue ? _max_end_sil : vadYamlEntity.model_conf.max_end_silence_time;
             _encoderConfEntity = vadYamlEntity.encoder_conf;
 
             ILoggerFactory loggerFactory = new LoggerFactory();
@@ -371,17 +370,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