From 28eed3258851a6baf84f28c6855fd0f9b64db827 Mon Sep 17 00:00:00 2001 From: speech_asr Date: Fri, 10 Mar 2023 18:40:24 +0800 Subject: [PATCH 1/7] update unittest --- tests/test_asr_inference_pipeline.py | 6 ++-- tests/test_asr_vad_punc_inference_pipeline.py | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tests/test_asr_vad_punc_inference_pipeline.py diff --git a/tests/test_asr_inference_pipeline.py b/tests/test_asr_inference_pipeline.py index 6257d114c..70dbe8952 100644 --- a/tests/test_asr_inference_pipeline.py +++ b/tests/test_asr_inference_pipeline.py @@ -65,7 +65,7 @@ class TestMfccaInferencePipelines(unittest.TestCase): model='NPU-ASLP/speech_mfcca_asr-zh-cn-16k-alimeeting-vocab4950', model_revision='v3.0.0') rec_result = inference_pipeline( - audio_in='16:32https://pre.modelscope.cn/api/v1/models/NPU-ASLP/speech_mfcca_asr-zh-cn-16k-alimeeting-vocab4950/repo?Revision=master&FilePath=example/asr_example_mc.wav') + audio_in='https://pre.modelscope.cn/api/v1/models/NPU-ASLP/speech_mfcca_asr-zh-cn-16k-alimeeting-vocab4950/repo?Revision=master&FilePath=example/asr_example_mc.wav') logger.info("asr inference result: {0}".format(rec_result)) @@ -451,8 +451,8 @@ class TestUniasrInferencePipelines(unittest.TestCase): def test_uniasr_2pass_zhcn_16k_common_vocab8358_offline(self): inference_pipeline = pipeline( - task=Tasks.auto_speech_recognition, - model='damo/speech_UniASR_asr_2pass-zh-cn-16k-common-vocab8358-tensorflow1-offline') + task=Tasks., + model='damo/speech_UniASauto_speech_recognitionR_asr_2pass-zh-cn-16k-common-vocab8358-tensorflow1-offline') rec_result = inference_pipeline( audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav', param_dict={"decoding_model": "offline"}) diff --git a/tests/test_asr_vad_punc_inference_pipeline.py b/tests/test_asr_vad_punc_inference_pipeline.py new file mode 100644 index 000000000..bcb57e09f --- /dev/null +++ b/tests/test_asr_vad_punc_inference_pipeline.py @@ -0,0 +1,32 @@ +import unittest + +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks +from modelscope.utils.logger import get_logger + +logger = get_logger() + +class TestParaformerInferencePipelines(unittest.TestCase): + def test_funasr_path(self): + import funasr + import os + logger.info("run_dir:{0} ; funasr_path: {1}".format(os.getcwd(), funasr.__file__)) + + def test_inference_pipeline(self): + inference_pipeline = pipeline( + task=Tasks.auto_speech_recognition, + model='damo/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch', + model_revision="v1.2.1", + vad_model='damo/speech_fsmn_vad_zh-cn-16k-common-pytorch', + vad_model_revision="v1.1.8", + punc_model='damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch', + punc_model_revision="v1.1.6", + ngpu=1, + ) + rec_result = inference_pipeline( + audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav') + logger.info("asr inference result: {0}".format(rec_result)) + + +if __name__ == '__main__': + unittest.main() From 4c8701145472f3ada595064905a704946eb12513 Mon Sep 17 00:00:00 2001 From: speech_asr Date: Fri, 10 Mar 2023 18:43:52 +0800 Subject: [PATCH 2/7] update unittest --- tests/test_lm_pipeline.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_lm_pipeline.py diff --git a/tests/test_lm_pipeline.py b/tests/test_lm_pipeline.py new file mode 100644 index 000000000..205d920b4 --- /dev/null +++ b/tests/test_lm_pipeline.py @@ -0,0 +1,25 @@ +import unittest + +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks +from modelscope.utils.logger import get_logger + +logger = get_logger() + +class TestTransformerInferencePipelines(unittest.TestCase): + def test_funasr_path(self): + import funasr + import os + logger.info("run_dir:{0} ; funasr_path: {1}".format(os.getcwd(), funasr.__file__)) + + def test_inference_pipeline(self): + inference_pipeline = pipeline( + task=Tasks.language_score_prediction, + model='damo/speech_transformer_lm_zh-cn-common-vocab8404-pytorch', + ) + rec_result = inference_pipeline(text_in="hello 大 家 好 呀") + logger.info("asr inference result: {0}".format(rec_result)) + + +if __name__ == '__main__': + unittest.main() From f11f53ec5c7bb09ebe315b2a39ad17ddab339759 Mon Sep 17 00:00:00 2001 From: speech_asr Date: Fri, 10 Mar 2023 18:48:16 +0800 Subject: [PATCH 3/7] update unittest --- .../infer.py | 4 +- tests/test_punctuation_pipeline.py | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/test_punctuation_pipeline.py diff --git a/egs_modelscope/punctuation/punc_ct-transformer_zh-cn-common-vadrealtime-vocab272727/infer.py b/egs_modelscope/punctuation/punc_ct-transformer_zh-cn-common-vadrealtime-vocab272727/infer.py index 02859c2b5..540e3cf64 100644 --- a/egs_modelscope/punctuation/punc_ct-transformer_zh-cn-common-vadrealtime-vocab272727/infer.py +++ b/egs_modelscope/punctuation/punc_ct-transformer_zh-cn-common-vadrealtime-vocab272727/infer.py @@ -5,7 +5,7 @@ inputs = "跨境河流是养育沿岸|人民的生命之源长期以来为帮助 from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks -inference_pipline = pipeline( +inference_pipeline = pipeline( task=Tasks.punctuation, model='damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727', model_revision="v1.0.0", @@ -17,7 +17,7 @@ vads = inputs.split("|") cache_out = [] rec_result_all="outputs:" for vad in vads: - rec_result = inference_pipline(text_in=vad, cache=cache_out) + rec_result = inference_pipeline(text_in=vad, cache=cache_out) #print(rec_result) cache_out = rec_result['cache'] rec_result_all += rec_result['text'] diff --git a/tests/test_punctuation_pipeline.py b/tests/test_punctuation_pipeline.py new file mode 100644 index 000000000..4610f01e6 --- /dev/null +++ b/tests/test_punctuation_pipeline.py @@ -0,0 +1,43 @@ +import unittest + +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks +from modelscope.utils.logger import get_logger + +logger = get_logger() + +class TestTransformerInferencePipelines(unittest.TestCase): + def test_funasr_path(self): + import funasr + import os + logger.info("run_dir:{0} ; funasr_path: {1}".format(os.getcwd(), funasr.__file__)) + + def test_inference_pipeline(self): + inference_pipeline = pipeline( + task=Tasks.punctuation, + model='damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch', + model_revision="v1.1.7", + ) + inputs = "./egs_modelscope/punctuation/punc_ct-transformer_zh-cn-common-vocab272727-pytorch/data/punc_example.txt" + rec_result = inference_pipeline(text_in=inputs) + logger.info("asr inference result: {0}".format(rec_result)) + + def test_vadrealtime_inference_pipeline(self): + inference_pipeline = pipeline( + task=Tasks.punctuation, + model='damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727', + model_revision="v1.0.0", + ) + inputs = "跨境河流是养育沿岸|人民的生命之源长期以来为帮助下游地区防灾减灾中方技术人员|在上游地区极为恶劣的自然条件下克服巨大困难甚至冒着生命危险|向印方提供汛期水文资料处理紧急事件中方重视印方在跨境河流问题上的关切|愿意进一步完善双方联合工作机制|凡是|中方能做的我们|都会去做而且会做得更好我请印度朋友们放心中国在上游的|任何开发利用都会经过科学|规划和论证兼顾上下游的利益" + vads = inputs.split("|") + cache_out = [] + rec_result_all = "outputs:" + for vad in vads: + rec_result = inference_pipeline(text_in=vad, cache=cache_out) + cache_out = rec_result['cache'] + rec_result_all += rec_result['text'] + logger.info("asr inference result: {0}".format(rec_result_all)) + + +if __name__ == '__main__': + unittest.main() From 92c4b128a15fa1a1d775839a0e5951b67f6ec3e1 Mon Sep 17 00:00:00 2001 From: speech_asr Date: Fri, 10 Mar 2023 18:50:05 +0800 Subject: [PATCH 4/7] update unittest --- tests/test_sv_inference_pipeline.py | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test_sv_inference_pipeline.py diff --git a/tests/test_sv_inference_pipeline.py b/tests/test_sv_inference_pipeline.py new file mode 100644 index 000000000..265f8392f --- /dev/null +++ b/tests/test_sv_inference_pipeline.py @@ -0,0 +1,47 @@ +import unittest + +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks +from modelscope.utils.logger import get_logger + +logger = get_logger() + + +class TestXVectorInferencePipelines(unittest.TestCase): + def test_funasr_path(self): + import funasr + import os + logger.info("run_dir:{0} ; funasr_path: {1}".format(os.getcwd(), funasr.__file__)) + + def test_inference_pipeline(self): + inference_sv_pipline = pipeline( + task=Tasks.speaker_verification, + model='damo/speech_xvector_sv-zh-cn-cnceleb-16k-spk3465-pytorch' + ) + # 提取不同句子的说话人嵌入码 + rec_result = inference_sv_pipline( + audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav') + enroll = rec_result["spk_embedding"] + + rec_result = inference_sv_pipline( + audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_same.wav') + same = rec_result["spk_embedding"] + + rec_result = inference_sv_pipline( + audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_different.wav') + different = rec_result["spk_embedding"] + + # 对相同的说话人计算余弦相似度 + sv_threshold = 0.9465 + same_cos = np.sum(enroll * same) / (np.linalg.norm(enroll) * np.linalg.norm(same)) + same_cos = max(same_cos - sv_threshold, 0.0) / (1.0 - sv_threshold) * 100.0 + logger.info("Similarity: {}".format(same_cos)) + + # 对不同的说话人计算余弦相似度 + diff_cos = np.sum(enroll * different) / (np.linalg.norm(enroll) * np.linalg.norm(different)) + diff_cos = max(diff_cos - sv_threshold, 0.0) / (1.0 - sv_threshold) * 100.0 + logger.info("Similarity: {}".format(diff_cos)) + + +if __name__ == '__main__': + unittest.main() From 0b7149931af0464f6536f922c6fccecc41017615 Mon Sep 17 00:00:00 2001 From: speech_asr Date: Fri, 10 Mar 2023 18:52:56 +0800 Subject: [PATCH 5/7] update unittest --- tests/test_vad_inference_pipeline.py | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_vad_inference_pipeline.py diff --git a/tests/test_vad_inference_pipeline.py b/tests/test_vad_inference_pipeline.py new file mode 100644 index 000000000..d22f46178 --- /dev/null +++ b/tests/test_vad_inference_pipeline.py @@ -0,0 +1,35 @@ +import unittest + +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks +from modelscope.utils.logger import get_logger + +logger = get_logger() + +class TestFSMNInferencePipelines(unittest.TestCase): + def test_funasr_path(self): + import funasr + import os + logger.info("run_dir:{0} ; funasr_path: {1}".format(os.getcwd(), funasr.__file__)) + + def test_8k(self): + inference_pipeline = pipeline( + task=Tasks.voice_activity_detection, + model="damo/speech_fsmn_vad_zh-cn-8k-common", + ) + rec_result = inference_pipeline( + audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example_8k.wav') + logger.info("vad inference result: {0}".format(rec_result)) + + def test_16k(self): + inference_pipeline = pipeline( + task=Tasks.voice_activity_detection, + model="damo/speech_fsmn_vad_zh-cn-16k-common-pytorch", + ) + rec_result = inference_pipeline( + audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example.wav') + logger.info("vad inference result: {0}".format(rec_result)) + + +if __name__ == '__main__': + unittest.main() From 2e5318a176ad325a298582c2708d1533557cc412 Mon Sep 17 00:00:00 2001 From: speech_asr Date: Fri, 10 Mar 2023 18:55:22 +0800 Subject: [PATCH 6/7] update unittest --- tests/test_punctuation_pipeline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_punctuation_pipeline.py b/tests/test_punctuation_pipeline.py index 4610f01e6..52be9bbac 100644 --- a/tests/test_punctuation_pipeline.py +++ b/tests/test_punctuation_pipeline.py @@ -20,7 +20,7 @@ class TestTransformerInferencePipelines(unittest.TestCase): ) inputs = "./egs_modelscope/punctuation/punc_ct-transformer_zh-cn-common-vocab272727-pytorch/data/punc_example.txt" rec_result = inference_pipeline(text_in=inputs) - logger.info("asr inference result: {0}".format(rec_result)) + logger.info("punctuation inference result: {0}".format(rec_result)) def test_vadrealtime_inference_pipeline(self): inference_pipeline = pipeline( @@ -36,7 +36,7 @@ class TestTransformerInferencePipelines(unittest.TestCase): rec_result = inference_pipeline(text_in=vad, cache=cache_out) cache_out = rec_result['cache'] rec_result_all += rec_result['text'] - logger.info("asr inference result: {0}".format(rec_result_all)) + logger.info("punctuation inference result: {0}".format(rec_result_all)) if __name__ == '__main__': From 437d950f3119583ca4fb620fe6fb68755fcb80f1 Mon Sep 17 00:00:00 2001 From: speech_asr Date: Fri, 10 Mar 2023 18:56:10 +0800 Subject: [PATCH 7/7] update unittest --- tests/test_asr_vad_punc_inference_pipeline.py | 2 +- tests/test_lm_pipeline.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_asr_vad_punc_inference_pipeline.py b/tests/test_asr_vad_punc_inference_pipeline.py index bcb57e09f..628b256c0 100644 --- a/tests/test_asr_vad_punc_inference_pipeline.py +++ b/tests/test_asr_vad_punc_inference_pipeline.py @@ -25,7 +25,7 @@ class TestParaformerInferencePipelines(unittest.TestCase): ) rec_result = inference_pipeline( audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav') - logger.info("asr inference result: {0}".format(rec_result)) + logger.info("asr_vad_punc inference result: {0}".format(rec_result)) if __name__ == '__main__': diff --git a/tests/test_lm_pipeline.py b/tests/test_lm_pipeline.py index 205d920b4..3a5ec57a3 100644 --- a/tests/test_lm_pipeline.py +++ b/tests/test_lm_pipeline.py @@ -18,7 +18,7 @@ class TestTransformerInferencePipelines(unittest.TestCase): model='damo/speech_transformer_lm_zh-cn-common-vocab8404-pytorch', ) rec_result = inference_pipeline(text_in="hello 大 家 好 呀") - logger.info("asr inference result: {0}".format(rec_result)) + logger.info("lm inference result: {0}".format(rec_result)) if __name__ == '__main__':