mirror of
https://github.com/modelscope/FunASR.git
synced 2026-10-12 02:19:18 +00:00
Add GLMASR wrapper class integrating GLM-ASR-Nano-2512 (1.5B) into
FunASR. Uses HuggingFace transformers AutoModel + AutoProcessor with
trust_remote_code. Supports 17 languages with dialect and low-volume
speech optimization.
Usage:
from funasr import AutoModel
model = AutoModel(model="zai-org/GLM-ASR-Nano-2512", hub="hf", device="cuda:0")
res = model.generate(input="audio.wav")
# ModelScope (Chinese users)
model = AutoModel(model="ZhipuAI/GLM-ASR-Nano-2512", hub="ms", device="cuda:0")
Tested end-to-end on CPU with Chinese and English audio.
New files:
- funasr/models/glm_asr/model.py
- funasr/models/glm_asr/__init__.py
- tests_models/test_glm_asr.py
- examples/industrial_data_pretraining/glm_asr/demo.py
- examples/industrial_data_pretraining/glm_asr/demo_ms.py
Note: requires transformers>=5.0.0 (pip install git+https://github.com/huggingface/transformers)
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Test GLM-ASR: robust multi-language speech recognition"""
|
|
import sys
|
|
import time
|
|
|
|
|
|
def main():
|
|
from funasr import AutoModel
|
|
|
|
url_zh = "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav"
|
|
url_en = "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_en.wav"
|
|
|
|
# Standard FunASR usage
|
|
# Default hub="ms" (ModelScope), use hub="hf" for HuggingFace
|
|
print("[GLM-ASR] Loading model...")
|
|
t0 = time.time()
|
|
model = AutoModel(
|
|
model="zai-org/GLM-ASR-Nano-2512",
|
|
hub="hf",
|
|
device="cuda:0",
|
|
disable_update=True,
|
|
)
|
|
print("[GLM-ASR] Model loaded in %.1fs" % (time.time() - t0))
|
|
|
|
# Test 1: Chinese audio
|
|
print("[GLM-ASR] Test 1: Chinese inference...")
|
|
t0 = time.time()
|
|
res = model.generate(input=url_zh)
|
|
print("[GLM-ASR] Inference done in %.1fs" % (time.time() - t0))
|
|
|
|
if res and len(res) > 0 and "text" in res[0]:
|
|
print("[GLM-ASR] Result (zh): %s" % res[0]["text"])
|
|
print("[GLM-ASR] Test 1 PASSED")
|
|
else:
|
|
print("[GLM-ASR] Test 1 FAILED - no text in result")
|
|
return 1
|
|
|
|
# Test 2: English audio
|
|
print("[GLM-ASR] Test 2: English inference...")
|
|
t0 = time.time()
|
|
res = model.generate(input=url_en)
|
|
print("[GLM-ASR] Inference done in %.1fs" % (time.time() - t0))
|
|
|
|
if res and len(res) > 0 and "text" in res[0]:
|
|
print("[GLM-ASR] Result (en): %s" % res[0]["text"])
|
|
print("[GLM-ASR] Test 2 PASSED")
|
|
else:
|
|
print("[GLM-ASR] Test 2 FAILED - no text in result")
|
|
return 1
|
|
|
|
print("[GLM-ASR] All tests PASSED")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|