Files
modelscope/tests/pipelines/test_speech_signal_process.py
mulin.lyh cba4e40bc1 fix numpy pandas compatible issue
明确受影响的模型(damo):  
ONE-PEACE-4B	ModuleNotFoundError: MyCustomPipeline: MyCustomModel: No module named 'one_peace',缺少依赖。
cv_resnet50_face-reconstruction	 不兼容tf2  
nlp_automatic_post_editing_for_translation_en2de	tf2.0兼容性问题,tf1.x需要  
cv_resnet18_ocr-detection-word-level_damo	tf2.x兼容性问题  
cv_resnet18_ocr-detection-line-level_damo	tf兼容性问题  
cv_resnet101_detection_fewshot-defrcn	模型限制必须detection0.3+torch1.11.0"  
speech_dfsmn_ans_psm_48k_causal	"librosa, numpy兼容性问题  
cv_mdm_motion-generation	"依赖numpy版本兼容性问题:   File ""/opt/conda/lib/python3.8/site-packages/smplx/body_models.py"",  
cv_resnet50_ocr-detection-vlpt	numpy兼容性问题  
cv_clip-it_video-summarization_language-guided_en	tf兼容性问题

Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/13744636
* numpy and pandas no version

* modify compatible issue

* fix numpy compatible issue

* modify ci

* fix lint issue

* replace Image.ANTIALIAS to Image.Resampling.LANCZOS pillow compatible

* skip uncompatible cases

* fix numpy compatible issue, skip cases that can not compatbile numpy or tensorflow2.x

* skip compatible cases

* fix clip model issue

* fix body 3d keypoints compatible issue
2023-08-22 23:04:31 +08:00

156 lines
6.7 KiB
Python

# Copyright (c) Alibaba, Inc. and its affiliates.
import os.path
import unittest
from modelscope.metainfo import Pipelines
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.utils.test_utils import test_level
NEAREND_MIC_FILE = 'data/test/audios/nearend_mic.wav'
FAREND_SPEECH_FILE = 'data/test/audios/farend_speech.wav'
NEAREND_MIC_URL = 'https://modelscope.oss-cn-beijing.aliyuncs.com/' \
'test/audios/nearend_mic.wav'
FAREND_SPEECH_URL = 'https://modelscope.oss-cn-beijing.aliyuncs.com/' \
'test/audios/farend_speech.wav'
NOISE_SPEECH_FILE = 'data/test/audios/speech_with_noise.wav'
NOISE_SPEECH_FILE_48K = 'data/test/audios/speech_with_noise_48k.wav'
NOISE_SPEECH_FILE_48K_PCM = 'data/test/audios/speech_with_noise_48k.PCM'
NOISE_SPEECH_URL = 'https://modelscope.oss-cn-beijing.aliyuncs.com/' \
'test/audios/speech_with_noise.wav'
@unittest.skip('For librosa numpy compatible')
class SpeechSignalProcessTest(unittest.TestCase):
def setUp(self) -> None:
pass
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_aec(self):
model_id = 'damo/speech_dfsmn_aec_psm_16k'
input = {
'nearend_mic': os.path.join(os.getcwd(), NEAREND_MIC_FILE),
'farend_speech': os.path.join(os.getcwd(), FAREND_SPEECH_FILE)
}
aec = pipeline(Tasks.acoustic_echo_cancellation, model=model_id)
output_path = os.path.abspath('output.wav')
aec(input, output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_aec_url(self):
model_id = 'damo/speech_dfsmn_aec_psm_16k'
input = {
'nearend_mic': NEAREND_MIC_URL,
'farend_speech': FAREND_SPEECH_URL
}
aec = pipeline(Tasks.acoustic_echo_cancellation, model=model_id)
output_path = os.path.abspath('output.wav')
aec(input, output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_aec_bytes(self):
model_id = 'damo/speech_dfsmn_aec_psm_16k'
input = {}
with open(os.path.join(os.getcwd(), NEAREND_MIC_FILE), 'rb') as f:
input['nearend_mic'] = f.read()
with open(os.path.join(os.getcwd(), FAREND_SPEECH_FILE), 'rb') as f:
input['farend_speech'] = f.read()
aec = pipeline(
Tasks.acoustic_echo_cancellation,
model=model_id,
pipeline_name=Pipelines.speech_dfsmn_aec_psm_16k)
output_path = os.path.abspath('output.wav')
aec(input, output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_aec_tuple_bytes(self):
model_id = 'damo/speech_dfsmn_aec_psm_16k'
with open(os.path.join(os.getcwd(), NEAREND_MIC_FILE), 'rb') as f:
nearend_bytes = f.read()
with open(os.path.join(os.getcwd(), FAREND_SPEECH_FILE), 'rb') as f:
farend_bytes = f.read()
inputs = (nearend_bytes, farend_bytes)
aec = pipeline(
Tasks.acoustic_echo_cancellation,
model=model_id,
pipeline_name=Pipelines.speech_dfsmn_aec_psm_16k)
output_path = os.path.abspath('output.wav')
aec(inputs, output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_frcrn_ans(self):
model_id = 'damo/speech_frcrn_ans_cirm_16k'
ans = pipeline(Tasks.acoustic_noise_suppression, model=model_id)
output_path = os.path.abspath('output.wav')
ans(os.path.join(os.getcwd(), NOISE_SPEECH_FILE),
output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_ans_url(self):
model_id = 'damo/speech_frcrn_ans_cirm_16k'
ans = pipeline(Tasks.acoustic_noise_suppression, model=model_id)
output_path = os.path.abspath('output.wav')
ans(NOISE_SPEECH_URL, output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_ans_bytes(self):
model_id = 'damo/speech_frcrn_ans_cirm_16k'
ans = pipeline(
Tasks.acoustic_noise_suppression,
model=model_id,
pipeline_name=Pipelines.speech_frcrn_ans_cirm_16k)
output_path = os.path.abspath('output.wav')
with open(os.path.join(os.getcwd(), NOISE_SPEECH_FILE), 'rb') as f:
data = f.read()
ans(data, output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_dfsmn_ans(self):
model_id = 'damo/speech_dfsmn_ans_psm_48k_causal'
ans = pipeline(Tasks.acoustic_noise_suppression, model=model_id)
output_path = os.path.abspath('output.wav')
ans(os.path.join(os.getcwd(), NOISE_SPEECH_FILE_48K),
output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_dfsmn_ans_bytes(self):
model_id = 'damo/speech_dfsmn_ans_psm_48k_causal'
ans = pipeline(Tasks.acoustic_noise_suppression, model=model_id)
output_path = os.path.abspath('output.wav')
with open(os.path.join(os.getcwd(), NOISE_SPEECH_FILE_48K), 'rb') as f:
data = f.read()
ans(data, output_path=output_path)
print(f'Processed audio saved to {output_path}')
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_dfsmn_ans_stream(self):
model_id = 'damo/speech_dfsmn_ans_psm_48k_causal'
ans = pipeline(
Tasks.acoustic_noise_suppression, model=model_id, stream_mode=True)
with open(os.path.join(os.getcwd(), NOISE_SPEECH_FILE_48K_PCM),
'rb') as f:
block_size = 3840
audio = f.read(block_size)
with open('output.pcm', 'wb') as w:
while len(audio) >= block_size:
result = ans(audio)
pcm = result[OutputKeys.OUTPUT_PCM]
w.write(pcm)
audio = f.read(block_size)
if __name__ == '__main__':
unittest.main()