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

Function main

tests_models/test_fun_asr_nano_spk.py:6–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import time
5
6def main():
7 from funasr import AutoModel
8
9 print("[Fun-ASR-Nano-SPK] Loading model...")
10 t0 = time.time()
11 model = AutoModel(
12 model="FunAudioLLM/Fun-ASR-Nano-2512",
13 trust_remote_code=True,
14 remote_code="./model.py",
15 vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",
16 vad_kwargs={"max_single_segment_time": 30000},
17 spk_model="iic/speech_campplus_sv_zh-cn_16k-common",
18 device="cpu",
19 disable_update=True,
20 hub="hf",
21 )
22 print("[Fun-ASR-Nano-SPK] Model loaded in %.1fs" % (time.time() - t0))
23
24 wav_path = model.model_path + "/example/zh.mp3"
25
26 print("[Fun-ASR-Nano-SPK] Running inference...")
27 t0 = time.time()
28 res = model.generate(input=[wav_path], cache={}, batch_size=1, language="中文")
29 print("[Fun-ASR-Nano-SPK] Inference done in %.1fs" % (time.time() - t0))
30
31 if not res or len(res) == 0:
32 print("[Fun-ASR-Nano-SPK] FAILED - empty result")
33 return 1
34
35 result = res[0]
36 keys = list(result.keys())
37 print("[Fun-ASR-Nano-SPK] Result keys: %s" % keys)
38 print("[Fun-ASR-Nano-SPK] Text: %s" % result.get("text", ""))
39
40 # Verify timestamp
41 ts = result.get("timestamp", None)
42 if ts is None or len(ts) == 0:
43 print("[Fun-ASR-Nano-SPK] FAILED - no timestamp")
44 return 1
45 print("[Fun-ASR-Nano-SPK] Timestamp count: %d, first: %s" % (len(ts), ts[0]))
46
47 # Verify sentence_info with speaker labels
48 si = result.get("sentence_info", None)
49 if si is None or len(si) == 0:
50 print("[Fun-ASR-Nano-SPK] FAILED - no sentence_info")
51 return 1
52
53 print("[Fun-ASR-Nano-SPK] sentence_info:")
54 for s in si:
55 print(" spk=%d | [%d-%d] %s" % (s["spk"], s["start"], s["end"], s.get("text", s.get("sentence", ""))))
56
57 has_spk = all("spk" in s for s in si)
58 if not has_spk:
59 print("[Fun-ASR-Nano-SPK] FAILED - missing spk label in sentence_info")
60 return 1
61
62 print("[Fun-ASR-Nano-SPK] PASSED")
63 return 0

Callers 1

Calls 3

generateMethod · 0.95
AutoModelClass · 0.90
keysMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…