()
| 5 | |
| 6 | |
| 7 | def main(): |
| 8 | from funasr import AutoModel |
| 9 | |
| 10 | url_zh = "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav" |
| 11 | url_en = "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_en.wav" |
| 12 | |
| 13 | # Standard FunASR usage |
| 14 | # Default hub="ms" (ModelScope), use hub="hf" for HuggingFace |
| 15 | print("[GLM-ASR] Loading model...") |
| 16 | t0 = time.time() |
| 17 | model = AutoModel( |
| 18 | model="zai-org/GLM-ASR-Nano-2512", |
| 19 | hub="hf", |
| 20 | device="cuda:0", |
| 21 | disable_update=True, |
| 22 | ) |
| 23 | print("[GLM-ASR] Model loaded in %.1fs" % (time.time() - t0)) |
| 24 | |
| 25 | # Test 1: Chinese audio |
| 26 | print("[GLM-ASR] Test 1: Chinese inference...") |
| 27 | t0 = time.time() |
| 28 | res = model.generate(input=url_zh) |
| 29 | print("[GLM-ASR] Inference done in %.1fs" % (time.time() - t0)) |
| 30 | |
| 31 | if res and len(res) > 0 and "text" in res[0]: |
| 32 | print("[GLM-ASR] Result (zh): %s" % res[0]["text"]) |
| 33 | print("[GLM-ASR] Test 1 PASSED") |
| 34 | else: |
| 35 | print("[GLM-ASR] Test 1 FAILED - no text in result") |
| 36 | return 1 |
| 37 | |
| 38 | # Test 2: English audio |
| 39 | print("[GLM-ASR] Test 2: English inference...") |
| 40 | t0 = time.time() |
| 41 | res = model.generate(input=url_en) |
| 42 | print("[GLM-ASR] Inference done in %.1fs" % (time.time() - t0)) |
| 43 | |
| 44 | if res and len(res) > 0 and "text" in res[0]: |
| 45 | print("[GLM-ASR] Result (en): %s" % res[0]["text"]) |
| 46 | print("[GLM-ASR] Test 2 PASSED") |
| 47 | else: |
| 48 | print("[GLM-ASR] Test 2 FAILED - no text in result") |
| 49 | return 1 |
| 50 | |
| 51 | print("[GLM-ASR] All tests PASSED") |
| 52 | return 0 |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…