def __init__(self, config, recording): self.config = config self.recording = recording self.wav_file = str( Path(self.config["directory"]).joinpath(f"{self.recording}.wav") ) self.speaker = process_annotations.AnnotationReader( self.recording ).get_speaker_info()
def test_annotation_missing_file(self): """ Test get_annotation_data(): Does an invalid file path produce an error? """ annotation_file = "does/not/exist.accents" with self.assertRaises(FileNotFoundError): tester = process_annotations.AnnotationReader(annotation_file) tester.get_annotation_data()
def test_annotation_input_type(self): """ Test get_annotation_data(): Do invalid input types produce an error? """ annotation_file = "tests/test_material/test.phrases" with self.assertRaises(ValueError): tester = process_annotations.AnnotationReader(annotation_file) tester.get_annotation_data()
def test_speaker_info(self): """ Test get_speaker_info(): Does the function return the correct data for a given recording? """ recording_id = "dlf-nachrichten-200703260600" correct_output = ("2", "f") tester = process_annotations.AnnotationReader(recording_id) self.assertTrue(tester.get_speaker_info() == correct_output)
def test_invalid_id(self): """ Test get_speaker_info(): Does an invalid recording ID as input return the correct tuple? """ recording_id = "notarealid2005-08-20-1500" expected_output = ("unknown", "f") tester = process_annotations.AnnotationReader(recording_id) output = tester.get_speaker_info() self.assertTrue(expected_output == output)
def test_annotation_accents_output(self): """ Test get_annotation_data(): Does the function return the correct output for a file containing accent labels? """ annotation_file = "tests/test_material/test.accents" tester = process_annotations.AnnotationReader(annotation_file) output_df = tester.get_annotation_data() self.assertTrue("time" in output_df.columns) self.assertFalse("end" in output_df.columns) self.assertFalse("xwaves" in output_df.columns) self.assertTrue("label" in output_df.columns) self.assertTrue(len(output_df.index) == 2)
def collect_annotations(self, annotation_type): file = Path(self.config["directory"]).joinpath( f"{self.recording}.{annotation_type}" ) return process_annotations.AnnotationReader(file).get_annotation_data()