mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
Update test_sv_inference_pipeline.py (#635)
add unit tests for sv model
This commit is contained in:
parent
6e9d84e4aa
commit
d74fdb3a74
@ -19,30 +19,20 @@ class TestXVectorInferencePipelines(unittest.TestCase):
|
|||||||
task=Tasks.speaker_verification,
|
task=Tasks.speaker_verification,
|
||||||
model='damo/speech_xvector_sv-zh-cn-cnceleb-16k-spk3465-pytorch'
|
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(
|
# the same speaker
|
||||||
audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_same.wav')
|
rec_result = inference_sv_pipline(audio_in=(
|
||||||
same = rec_result["spk_embedding"]
|
'https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav',
|
||||||
|
'https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_same.wav'))
|
||||||
rec_result = inference_sv_pipline(
|
assert abs(rec_result["scores"][0]-0.85) < 0.1 and abs(rec_result["scores"][1]-0.14) < 0.1
|
||||||
audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_different.wav')
|
logger.info(f"Similarity {rec_result['scores']}")
|
||||||
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))
|
|
||||||
|
|
||||||
|
# different speaker
|
||||||
|
rec_result = inference_sv_pipline(audio_in=(
|
||||||
|
'https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav',
|
||||||
|
'https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_different.wav'))
|
||||||
|
assert abs(rec_result["scores"][0]-0.0) < 0.1 and abs(rec_result["scores"][1]-1.0) < 0.1
|
||||||
|
logger.info(f"Similarity {rec_result['scores']}")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user