Init pitch test

This commit is contained in:
Feiteng 2024-01-24 15:35:57 +08:00
parent b75abef4c0
commit 7ae06d78eb
2 changed files with 42 additions and 0 deletions

View File

@ -23,6 +23,7 @@ set(py_test_files
test_mel_bank_options.py
test_mfcc.py
test_mfcc_options.py
test_pitch.py
test_plp.py
test_plp_options.py
test_spectrogram.py

View 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()