Spaces:
Running
Running
File size: 1,875 Bytes
9d61c9b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 48 49 50 51 52 53 54 |
import unittest
import torch
from training.loss.metrics import Metrics
class TestMetrics(unittest.TestCase):
def setUp(self):
self.metrics = Metrics()
# Set the frequency of the pitch (in Hz)
self.pitch_freq = 440.0
self.duration = 1.0
self.sr = 22050
# Generate a time vector for the audio signal
self.t = torch.linspace(0, self.duration, int(self.sr * self.duration))
# Generate a sinusoidal waveform with the specified pitch frequency
self.audio = torch.sin(2 * torch.pi * self.pitch_freq * self.t).unsqueeze(0)
def test_calculate_mcd(self):
wav_targets = torch.randn(1, 22050)
wav_predictions = torch.randn(1, 22050)
mcd = self.metrics.calculate_mcd(wav_targets, wav_predictions)
self.assertIsInstance(mcd, torch.Tensor)
def test_calculate_spectrogram_distance(self):
wav_targets = torch.randn(1, 22050)
wav_predictions = torch.randn(1, 22050)
dist = self.metrics.calculate_spectrogram_distance(wav_targets, wav_predictions)
self.assertIsInstance(dist, torch.Tensor)
def test_calculate_f0_rmse(self):
wav_targets = torch.randn(1, 22050)
wav_predictions = torch.randn(1, 22050)
rmse = self.metrics.calculate_f0_rmse(wav_targets, wav_predictions)
self.assertIsInstance(rmse, float)
def test_calculate_jitter_shimmer(self):
jitter, shimmer = self.metrics.calculate_jitter_shimmer(self.audio)
self.assertIsInstance(jitter, float)
self.assertIsInstance(shimmer, float)
def test_wav_metrics(self):
ermr, jitter, shimmer = self.metrics.wav_metrics(self.audio)
self.assertIsInstance(ermr, float)
self.assertIsInstance(jitter, float)
self.assertIsInstance(shimmer, float)
if __name__ == "__main__":
unittest.main()
|