Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
Add model integration tests for major models (VAD, Paraformer, SenseVoice, CAM++, CT-Transformer, Streaming)
zhifu.gzf266b8a24aee8
diff --git a/tests_models/run_all_tests.py b/tests_models/run_all_tests.pynew file mode 100644index 000000000..3b7ebe753--- /dev/null+++ b/tests_models/run_all_tests.py@@ -0,0 +1,81 @@+#!/usr/bin/env python3+# -*- coding: utf-8 -*-+"""Run all model tests and report results"""+import subprocess+import sys+import os+import time++TEST_DIR = os.path.dirname(os.path.abspath(__file__))+PROJECT_DIR = os.path.dirname(TEST_DIR)++tests = [+ "test_fsmn_vad.py",+ "test_ct_transformer.py",+ "test_paraformer.py",+ "test_sensevoice.py",+ "test_campplus.py",+ "test_paraformer_streaming.py",+]++SEP = "-" * 60+DSEP = "=" * 60++def main():+ results = {}+ total_start = time.time()++ env = os.environ.copy()+ env["PYTHONPATH"] = PROJECT_DIR + ":" + env.get("PYTHONPATH", "")++ print(DSEP)+ print("FunASR Model Tests")+ print(DSEP)++ for test_file in tests:+ test_path = os.path.join(TEST_DIR, test_file)+ print("\n" + SEP)+ print("Running: " + test_file)+ print(SEP)++ t0 = time.time()+ try:+ result = subprocess.run(+ [sys.executable, test_path],+ cwd=PROJECT_DIR,+ env=env,+ timeout=300,+ capture_output=False,+ )+ elapsed = time.time() - t0+ results[test_file] = ("PASSED" if result.returncode == 0 else "FAILED", elapsed)+ except subprocess.TimeoutExpired:+ elapsed = time.time() - t0+ results[test_file] = ("TIMEOUT", elapsed)+ print(" TIMEOUT after %.1fs" % elapsed)+ except Exception as e:+ elapsed = time.time() - t0+ results[test_file] = ("ERROR", elapsed)+ print(" ERROR: %s" % e)++ total_elapsed = time.time() - total_start++ print("\n" + DSEP)+ print("SUMMARY")+ print(DSEP)+ passed = 0+ failed = 0+ for test_file, (status, elapsed) in results.items():+ icon = "+" if status == "PASSED" else "x"+ print(" %s %-35s %-8s (%.1fs)" % (icon, test_file, status, elapsed))+ if status == "PASSED":+ passed += 1+ else:+ failed += 1++ print("\n Total: %d passed, %d failed, %.1fs elapsed" % (passed, failed, total_elapsed))+ print(DSEP)+ return 0 if failed == 0 else 1++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests_models/test_campplus.py b/tests_models/test_campplus.pynew file mode 100644index 000000000..1bf26a2c7--- /dev/null+++ b/tests_models/test_campplus.py@@ -0,0 +1,31 @@+#!/usr/bin/env python3+"""Test CAM++: Speaker Verification"""+import sys+import time++def main():+ from funasr import AutoModel++ print("[CAM++] Loading model...")+ t0 = time.time()+ model = AutoModel(model="iic/speech_campplus_sv_zh-cn_16k-common", device="cpu", disable_update=True)+ print("[CAM++] Model loaded in %.1fs" % (time.time()-t0))++ print("[CAM++] Extracting speaker embedding...")+ t0 = time.time()+ res = model.generate(+ input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",+ )+ print("[CAM++] Inference done in %.1fs" % (time.time()-t0))++ if res and len(res) > 0:+ spk_embedding = res[0].get("spk_embedding", None)+ if spk_embedding is not None:+ print("[CAM++] Embedding shape: %s" % str(spk_embedding.shape))+ print("[CAM++] PASSED")+ return 0+ print("[CAM++] FAILED - no speaker embedding")+ return 1++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests_models/test_ct_transformer.py b/tests_models/test_ct_transformer.pynew file mode 100644index 000000000..40d9ae261--- /dev/null+++ b/tests_models/test_ct_transformer.py@@ -0,0 +1,28 @@+#!/usr/bin/env python3+"""Test CT-Transformer: Punctuation Restoration"""+import sys+import time++def main():+ from funasr import AutoModel++ print("[CT-Transformer] Loading model...")+ t0 = time.time()+ model = AutoModel(model="iic/punc_ct-transformer_zh-cn-common-vocab272727-pytorch", device="cpu", disable_update=True)+ print("[CT-Transformer] Model loaded in %.1fs" % (time.time()-t0))++ print("[CT-Transformer] Running inference...")+ t0 = time.time()+ res = model.generate(input="那今天的天气呢也是蛮好的啊你觉得怎么样呢我觉得还不错")+ print("[CT-Transformer] Inference done in %.1fs" % (time.time()-t0))+ print("[CT-Transformer] Result: %s" % res)++ if res and len(res) > 0 and "text" in res[0]:+ print("[CT-Transformer] PASSED")+ return 0+ else:+ print("[CT-Transformer] FAILED - no punctuation result")+ return 1++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests_models/test_fsmn_vad.py b/tests_models/test_fsmn_vad.pynew file mode 100644index 000000000..28a09553c--- /dev/null+++ b/tests_models/test_fsmn_vad.py@@ -0,0 +1,31 @@+#!/usr/bin/env python3+"""Test FSMN-VAD: Voice Activity Detection"""+import sys+import time++def main():+ from funasr import AutoModel++ print("[FSMN-VAD] Loading model...")+ t0 = time.time()+ model = AutoModel(model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch", device="cpu", disable_update=True)+ print("[FSMN-VAD] Model loaded in %.1fs" % (time.time()-t0))++ print("[FSMN-VAD] Running inference...")+ t0 = time.time()+ res = model.generate(+ input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",+ )+ print("[FSMN-VAD] Inference done in %.1fs" % (time.time()-t0))+ print("[FSMN-VAD] Result: %s" % res)++ if res and len(res) > 0 and "value" in res[0]:+ print("[FSMN-VAD] Detected %d speech segments" % len(res[0]["value"]))+ print("[FSMN-VAD] PASSED")+ return 0+ else:+ print("[FSMN-VAD] FAILED - no VAD segments detected")+ return 1++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests_models/test_paraformer.py b/tests_models/test_paraformer.pynew file mode 100644index 000000000..38afcde37--- /dev/null+++ b/tests_models/test_paraformer.py@@ -0,0 +1,38 @@+#!/usr/bin/env python3+"""Test Paraformer-large: offline ASR (Chinese)"""+import sys+import time++def main():+ from funasr import AutoModel++ print("[Paraformer] Loading model...")+ t0 = time.time()+ model = AutoModel(+ model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch",+ vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",+ vad_kwargs={"max_single_segment_time": 60000},+ punc_model="iic/punc_ct-transformer_zh-cn-common-vocab272727-pytorch",+ device="cpu",+ disable_update=True,+ )+ print("[Paraformer] Model loaded in %.1fs" % (time.time()-t0))++ print("[Paraformer] Running inference...")+ t0 = time.time()+ res = model.generate(+ input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",+ cache={},+ )+ print("[Paraformer] Inference done in %.1fs" % (time.time()-t0))+ print("[Paraformer] Result: %s" % res)++ if res and len(res) > 0 and "text" in res[0]:+ print("[Paraformer] PASSED")+ return 0+ else:+ print("[Paraformer] FAILED - no text in result")+ return 1++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests_models/test_paraformer_streaming.py b/tests_models/test_paraformer_streaming.pynew file mode 100644index 000000000..99aec136e--- /dev/null+++ b/tests_models/test_paraformer_streaming.py@@ -0,0 +1,33 @@+#!/usr/bin/env python3+"""Test Paraformer-Streaming: online/streaming ASR"""+import sys+import time++def main():+ from funasr import AutoModel++ print("[Paraformer-Streaming] Loading model...")+ t0 = time.time()+ model = AutoModel(+ model="iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online",+ device="cpu",+ disable_update=True,+ )+ print("[Paraformer-Streaming] Model loaded in %.1fs" % (time.time()-t0))++ print("[Paraformer-Streaming] Running inference...")+ t0 = time.time()+ test_wav = "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav"+ res = model.generate(input=test_wav, cache={}, is_final=True)+ print("[Paraformer-Streaming] Inference done in %.1fs" % (time.time()-t0))+ print("[Paraformer-Streaming] Result: %s" % res)++ if res and len(res) > 0 and "text" in res[0]:+ print("[Paraformer-Streaming] PASSED")+ return 0+ else:+ print("[Paraformer-Streaming] FAILED - no text in result")+ return 1++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests_models/test_sensevoice.py b/tests_models/test_sensevoice.pynew file mode 100644index 000000000..a9c0df0b4--- /dev/null+++ b/tests_models/test_sensevoice.py@@ -0,0 +1,44 @@+#!/usr/bin/env python3+"""Test SenseVoice: multi-task speech understanding"""+import sys+import time++def main():+ from funasr import AutoModel+ from funasr.utils.postprocess_utils import rich_transcription_postprocess++ print("[SenseVoice] Loading model...")+ t0 = time.time()+ model = AutoModel(+ model="iic/SenseVoiceSmall",+ vad_model="fsmn-vad",+ vad_kwargs={"max_single_segment_time": 30000},+ device="cpu",+ disable_update=True,+ )+ print("[SenseVoice] Model loaded in %.1fs" % (time.time()-t0))++ print("[SenseVoice] Running inference (Chinese)...")+ t0 = time.time()+ res = model.generate(+ input=model.model_path + "/example/zh.mp3",+ cache={},+ language="auto",+ use_itn=True,+ batch_size_s=60,+ merge_vad=True,+ merge_length_s=15,+ )+ print("[SenseVoice] Inference done in %.1fs" % (time.time()-t0))++ if res and len(res) > 0 and "text" in res[0]:+ text = rich_transcription_postprocess(res[0]["text"])+ print("[SenseVoice] Result: %s" % text)+ print("[SenseVoice] PASSED")+ return 0+ else:+ print("[SenseVoice] FAILED - no text in result")+ return 1++if __name__ == "__main__":+ sys.exit(main())