From d80ac2fd2df4e7fb8a28acfa512bb11472b5cc99 Mon Sep 17 00:00:00 2001
From: liugz18 <57401541+liugz18@users.noreply.github.com>
Date: 星期四, 18 七月 2024 21:34:55 +0800
Subject: [PATCH] Rename 'res' in line 514 to avoid with naming conflict with line 365

---
 examples/industrial_data_pretraining/paraformer_streaming/demo.py |   60 ++++++++++++++++++++++++++++++++----------------------------
 1 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/examples/industrial_data_pretraining/paraformer_streaming/demo.py b/examples/industrial_data_pretraining/paraformer_streaming/demo.py
index 601a531..a1e9882 100644
--- a/examples/industrial_data_pretraining/paraformer_streaming/demo.py
+++ b/examples/industrial_data_pretraining/paraformer_streaming/demo.py
@@ -3,40 +3,44 @@
 # Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
 #  MIT License  (https://opensource.org/licenses/MIT)
 
-from funasr import AutoModel
-
-chunk_size = [5, 10, 5] #[0, 10, 5] 600ms, [0, 8, 4] 480ms
-encoder_chunk_look_back = 0 #number of chunks to lookback for encoder self-attention
-decoder_chunk_look_back = 0 #number of encoder chunks to lookback for decoder cross-attention
-wav_file="/Users/zhifu/Downloads/NCYzUhAtZNI_0015.wav"
-model = AutoModel(model="iic/speech_paraformer_asr_nat-zh-cn-16k-common-vocab8404-online", model_revision="v2.0.4")
-res = model.generate(input=wav_file,
-            chunk_size=chunk_size,
-            encoder_chunk_look_back=encoder_chunk_look_back,
-            decoder_chunk_look_back=decoder_chunk_look_back,
-            )
-print(res)
-
-# exit()
-
-import soundfile
 import os
 
-# wav_file = os.path.join(model.model_path, "example/asr_example.wav")
+from funasr import AutoModel
+
+chunk_size = [0, 10, 5]  # [0, 10, 5] 600ms, [0, 8, 4] 480ms
+encoder_chunk_look_back = 4  # number of chunks to lookback for encoder self-attention
+decoder_chunk_look_back = 1  # number of encoder chunks to lookback for decoder cross-attention
+model = AutoModel(model="iic/speech_paraformer_asr_nat-zh-cn-16k-common-vocab8404-online")
+
+wav_file = os.path.join(model.model_path, "example/asr_example.wav")
+res = model.generate(
+    input=wav_file,
+    chunk_size=chunk_size,
+    encoder_chunk_look_back=encoder_chunk_look_back,
+    decoder_chunk_look_back=decoder_chunk_look_back,
+)
+print(res)
+
+
+import soundfile
+
+
+wav_file = os.path.join(model.model_path, "example/asr_example.wav")
 speech, sample_rate = soundfile.read(wav_file)
 
-chunk_stride = chunk_size[1] * 960 # 600ms銆�480ms
+chunk_stride = chunk_size[1] * 960  # 600ms銆�480ms
 
 cache = {}
-total_chunk_num = int(len((speech)-1)/chunk_stride+1)
+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]
+    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,
-                         encoder_chunk_look_back=encoder_chunk_look_back,
-                         decoder_chunk_look_back=decoder_chunk_look_back,
-                         )
+    res = model.generate(
+        input=speech_chunk,
+        cache=cache,
+        is_final=is_final,
+        chunk_size=chunk_size,
+        encoder_chunk_look_back=encoder_chunk_look_back,
+        decoder_chunk_look_back=decoder_chunk_look_back,
+    )
     print(res)

--
Gitblit v1.9.1