MCPcopy Create free account
hub / github.com/modelscope/FunASR / record_from_scp

Function record_from_scp

runtime/python/websocket/funasr_wss_client.py:188–314  ·  view source on GitHub ↗

从 wav/scp 文件读取音频分片发送,用于压测和延迟测试

(chunk_begin, chunk_size)

Source from the content-addressed store, hash-verified

186
187
188async def record_from_scp(chunk_begin, chunk_size):
189 """从 wav/scp 文件读取音频分片发送,用于压测和延迟测试"""
190 global voices, latency_first_audio_time, latency_last_audio_time
191 if args.audio_in.endswith(".scp"):
192 f_scp = open(args.audio_in)
193 wavs = f_scp.readlines()
194 else:
195 wavs = [args.audio_in]
196
197 # hotwords
198 hotword_msg = ""
199 if args.hotword.strip() != "":
200 if os.path.exists(args.hotword):
201 with open(args.hotword, encoding="utf-8") as f_scp:
202 hot_lines = f_scp.readlines()
203
204 hot_list = []
205 for line in hot_lines:
206 words = line.strip().split()
207 if not words:
208 continue
209 # Python AutoModel: 用逗号分隔多个热词
210 hot_list.append(words[0])
211
212 hotword_msg = ",".join(hot_list)
213 else:
214 hotword_msg = args.hotword
215
216 print("hotword", hotword_msg)
217
218 sample_rate = args.audio_fs
219 wav_format = "pcm"
220 use_itn = True
221 if args.use_itn == 0:
222 use_itn = False
223
224 if chunk_size > 0:
225 wavs = wavs[chunk_begin: chunk_begin + chunk_size]
226
227 for wav in wavs:
228 wav_splits = wav.strip().split()
229
230 wav_name = wav_splits[0] if len(wav_splits) > 1 else "demo"
231 wav_path = wav_splits[1] if len(wav_splits) > 1 else wav_splits[0]
232 if not len(wav_path.strip()) > 0:
233 continue
234
235 if wav_path.endswith(".pcm"):
236 with open(wav_path, "rb") as f:
237 audio_bytes = f.read()
238 elif wav_path.endswith(".wav"):
239 import wave
240 with wave.open(wav_path, "rb") as wav_file:
241 sample_rate = wav_file.getframerate()
242 frames = wav_file.readframes(wav_file.getnframes())
243 audio_bytes = bytes(frames)
244 else:
245 wav_format = "others"

Callers 1

ws_clientFunction · 0.85

Calls 2

readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…