From 55c09aeaa25b4bb88a50e09ba68fa6ff00a6d676 Mon Sep 17 00:00:00 2001
From: shixian.shi <shixian.shi@alibaba-inc.com>
Date: 星期一, 15 一月 2024 20:10:39 +0800
Subject: [PATCH] update readme, fix seaco bug
---
examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py | 32 +++++++++++++++++++++++++++++---
1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py b/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py
index 2a157ee..459dfff 100644
--- a/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py
+++ b/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py
@@ -4,8 +4,34 @@
# MIT License (https://opensource.org/licenses/MIT)
from funasr import AutoModel
+wav_file = "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example.wav"
-model = AutoModel(model="damo/speech_fsmn_vad_zh-cn-16k-common-pytorch", model_revision="v2.0.0")
+chunk_size = 60000 # ms
+model = AutoModel(model="damo/speech_fsmn_vad_zh-cn-16k-common-pytorch", model_revision="v2.0.2")
-res = model(input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example.wav")
-print(res)
\ No newline at end of file
+res = model(input=wav_file, chunk_size=chunk_size, )
+print(res)
+
+
+
+import soundfile
+import os
+
+wav_file = os.path.join(model.model_path, "example/vad_example.wav")
+speech, sample_rate = soundfile.read(wav_file)
+
+chunk_stride = int(chunk_size * sample_rate / 1000)
+
+cache = {}
+
+total_chunk_num = int(len((speech)-1)/chunk_stride+1)
+for i in range(total_chunk_num):
+ speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride]
+ is_final = i == total_chunk_num - 1
+ res = model(input=speech_chunk,
+ cache=cache,
+ is_final=is_final,
+ chunk_size=chunk_size,
+ )
+ if len(res[0]["value"]):
+ print(res)
--
Gitblit v1.9.1