|
| 1 | +import unittest |
| 2 | +from argparse import Namespace |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +from coqui_stt_training.util import audio |
| 6 | + |
| 7 | + |
| 8 | +def from_here(path): |
| 9 | + here = Path(__file__) |
| 10 | + return here.parent / path |
| 11 | + |
| 12 | + |
| 13 | +class TestValidateReadAudio(unittest.TestCase): |
| 14 | + def test_flac(self): |
| 15 | + audio_path = from_here("../data/smoke_test/LDC93S1.flac") |
| 16 | + audio_type = audio.get_loadable_audio_type_from_extension(audio_path.suffix) |
| 17 | + result = audio.read_audio(audio_type, str(audio_path)) |
| 18 | + self.assertIsInstance(result[0], audio.AudioFormat) |
| 19 | + |
| 20 | + def test_wav(self): |
| 21 | + audio_path = from_here("../data/smoke_test/LDC93S1.wav") |
| 22 | + audio_type = audio.get_loadable_audio_type_from_extension(audio_path.suffix) |
| 23 | + result = audio.read_audio(audio_type, str(audio_path)) |
| 24 | + self.assertIsInstance(result[0], audio.AudioFormat) |
| 25 | + |
| 26 | + def test_ogg_opus(self): |
| 27 | + audio_path = from_here("../data/smoke_test/LDC93S1.opus") |
| 28 | + audio_type = audio.get_loadable_audio_type_from_extension(audio_path.suffix) |
| 29 | + result = audio.read_audio(audio_type, str(audio_path)) |
| 30 | + self.assertIsInstance(result[0], audio.AudioFormat) |
| 31 | + |
| 32 | + |
| 33 | +class TestValidateReadDuration(unittest.TestCase): |
| 34 | + def test_flac(self): |
| 35 | + audio_path = from_here("../data/smoke_test/LDC93S1.flac") |
| 36 | + audio_type = audio.get_loadable_audio_type_from_extension(audio_path.suffix) |
| 37 | + result = audio.read_duration(audio_type, str(audio_path)) |
| 38 | + self.assertIsInstance(result, float) |
| 39 | + |
| 40 | + def test_wav(self): |
| 41 | + audio_path = from_here("../data/smoke_test/LDC93S1.wav") |
| 42 | + audio_type = audio.get_loadable_audio_type_from_extension(audio_path.suffix) |
| 43 | + result = audio.read_duration(audio_type, str(audio_path)) |
| 44 | + self.assertIsInstance(result, float) |
| 45 | + |
| 46 | + def test_ogg_opus(self): |
| 47 | + audio_path = from_here("../data/smoke_test/LDC93S1.opus") |
| 48 | + audio_type = audio.get_loadable_audio_type_from_extension(audio_path.suffix) |
| 49 | + result = audio.read_duration(audio_type, str(audio_path)) |
| 50 | + self.assertIsInstance(result, float) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + unittest.main() |
0 commit comments