test_infer.py 1.09 KB
Newer Older
SWHL's avatar
SWHL committed
1
2
3
4
5
6
# -*- encoding: utf-8 -*-
# @Author: SWHL
# @Contact: liekkaskono@163.com
import os
from pathlib import Path

SWHL's avatar
SWHL committed
7
8
9
10
11
import pytest
import librosa

project_dir = Path(__file__).resolve().parent.parent
os.sys.path.append(str(project_dir))
SWHL's avatar
SWHL committed
12
13
14

from rapid_paraformer import RapidParaformer

SWHL's avatar
SWHL committed
15
16
17

cfg_path = project_dir / 'resources' / 'config.yaml'
paraformer = RapidParaformer(cfg_path)
SWHL's avatar
SWHL committed
18
19


SWHL's avatar
SWHL committed
20
def test_input_by_path():
SWHL's avatar
SWHL committed
21
22
    wav_file = 'test_wavs/0478_00017.wav'
    result = paraformer(wav_file)
SWHL's avatar
SWHL committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    assert result[0][:5] == '呃说不配合'


def test_input_by_ndarray():
    wav_file = 'test_wavs/0478_00017.wav'
    waveform, _ = librosa.load(wav_file)
    result = paraformer(waveform[None, ...])
    assert result[0][:5] == '呃说不配合'


def test_input_by_str_list():
    wave_list = [
        'test_wavs/0478_00017.wav',
        'test_wavs/asr_example_zh.wav',
    ]
    result = paraformer(wave_list)
    assert result[0][:5] == '呃说不配合'


def test_empty():
    wav_file = None
    with pytest.raises(TypeError) as exc_info:
        paraformer(wav_file)
        raise TypeError()
    assert exc_info.type is TypeError