mirror of
https://github.com/csukuangfj/kaldifeat.git
synced 2025-08-11 19:12:28 +00:00
Init pitch test
This commit is contained in:
parent
b75abef4c0
commit
7ae06d78eb
@ -23,6 +23,7 @@ set(py_test_files
|
|||||||
test_mel_bank_options.py
|
test_mel_bank_options.py
|
||||||
test_mfcc.py
|
test_mfcc.py
|
||||||
test_mfcc_options.py
|
test_mfcc_options.py
|
||||||
|
test_pitch.py
|
||||||
test_plp.py
|
test_plp.py
|
||||||
test_plp_options.py
|
test_plp_options.py
|
||||||
test_spectrogram.py
|
test_spectrogram.py
|
||||||
|
41
kaldifeat/python/tests/test_pitch.py
Executable file
41
kaldifeat/python/tests/test_pitch.py
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright 2021-2022 Xiaomi Corporation (authors: Fangjun Kuang)
|
||||||
|
|
||||||
|
import pickle
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import torch
|
||||||
|
from utils import get_devices, read_ark_txt, read_wave
|
||||||
|
|
||||||
|
import kaldifeat
|
||||||
|
|
||||||
|
cur_dir = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
|
||||||
|
def test_pitch_default():
|
||||||
|
print("=====test_pitch_default=====")
|
||||||
|
filename = cur_dir / "test_data/test.wav"
|
||||||
|
wave = read_wave(filename)
|
||||||
|
gt = read_ark_txt(cur_dir / "test_data/test-pitch.txt")
|
||||||
|
|
||||||
|
cpu_features = None
|
||||||
|
for device in get_devices():
|
||||||
|
print("device", device)
|
||||||
|
opts = kaldifeat.PitchOptions()
|
||||||
|
opts.device = device
|
||||||
|
opts.frame_opts.dither = 0
|
||||||
|
pitch = kaldifeat.Pitch(opts)
|
||||||
|
|
||||||
|
features = pitch(wave)
|
||||||
|
assert features.device.type == "cpu"
|
||||||
|
assert torch.allclose(features, gt, rtol=1e-4)
|
||||||
|
if cpu_features is None:
|
||||||
|
cpu_features = features
|
||||||
|
|
||||||
|
features = pitch(wave.to(device))
|
||||||
|
assert features.device == device
|
||||||
|
assert torch.allclose(features.cpu(), gt, rtol=1e-4)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_pitch_default()
|
Loading…
x
Reference in New Issue
Block a user