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
---
examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py | 42 +++++++++++++++++++++++++++---------------
1 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py b/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py
index 6761a80..21ce0cb 100644
--- a/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py
+++ b/examples/industrial_data_pretraining/fsmn_vad_streaming/demo.py
@@ -4,16 +4,16 @@
# 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"
-chunk_size = 60000 # ms
-model = AutoModel(model="/Users/zhifu/Downloads/modelscope_models/speech_fsmn_vad_zh-cn-16k-common-streaming", model_revision="v2.0.0")
+model = AutoModel(model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch")
-res = model(input=wav_file,
- chunk_size=chunk_size,
- )
+res = model.generate(input=wav_file)
print(res)
+# [[beg1, end1], [beg2, end2], .., [begN, endN]]
+# beg/end: ms
import soundfile
@@ -22,16 +22,28 @@
wav_file = os.path.join(model.model_path, "example/vad_example.wav")
speech, sample_rate = soundfile.read(wav_file)
-chunk_stride = int(chunk_size * 16000 / 1000)
+chunk_size = 200 # ms
+chunk_stride = int(chunk_size * sample_rate / 1000)
cache = {}
-for i in range(int(len((speech)-1)/chunk_stride+1)):
- speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride]
- is_final = i == int(len((speech)-1)/chunk_stride+1) - 1
- res = model(input=speech_chunk,
- cache=cache,
- is_final=is_final,
- chunk_size=chunk_size,
- )
- print(res)
+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.generate(
+ input=speech_chunk,
+ cache=cache,
+ is_final=is_final,
+ chunk_size=chunk_size,
+ disable_pbar=True,
+ )
+ # print(res)
+ if len(res[0]["value"]):
+ print(res)
+
+
+# 1. [[beg1, end1], [beg2, end2], .., [begN, endN]]; [[beg, end]]; [[beg1, end1], [beg2, end2]]
+# 2. [[beg, -1]]
+# 3. [[-1, end]]
+# beg/end: ms
--
Gitblit v1.9.1