From 192c952c2da014680a790448f3bfe2a296000039 Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Thu, 29 Aug 2024 09:49:11 +0100 Subject: [PATCH] test: add TestLoudAudioFEFunctional Functional tests for LoudAudioFeatureExtractor Currently uses one manually-generated video with blank audio except between 15-20s where 1-2 sine tones are present --- test/test_feature_extractors_functional.py | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/test_feature_extractors_functional.py b/test/test_feature_extractors_functional.py index b608bf5..706b509 100644 --- a/test/test_feature_extractors_functional.py +++ b/test/test_feature_extractors_functional.py @@ -48,3 +48,45 @@ class TestVideoActivityFEFunctional(FEFunctionalTest): self.assertTrue(testfe.features) # check if the feature interval is within the expected range self.assertTrue(testfe.features[0].interval.start >= START_TIME) + + +class TestLoudAudioFEFunctional(FEFunctionalTest): + """TestAudioLoudnessFEFunctional -- functional tests for audio loudness feature extractor + """ + + def test_audio_loudness_functional_one_feature(self): + """Test audio loudness feature extractor + + use: + - sample_videos/sample-manual-audio.mp4 :: audio at 15-20s -- pass if audio detected anywhere in this range + -- peak at 16s - 18s, verify this is highest scoring + """ + SAMPLE_VIDEO = f"{self.SAMPLE_DIR}/sample-manual-audio.mp4" + + START_TIME = 15 + END_TIME = 20 + PEAK_START = 16 + PEAK_END = 18 + # create mock source with the video + source = mocks.MockSource(path=SAMPLE_VIDEO) + + # create the feature extractor + testfe = extractors.LoudAudioFeatureExtractor(input_files=[source]) + testfe.setup() + testfe.run() + testfe.teardown() + + # check if the feature was extracted: + self.assertTrue(testfe.features) + # check if the feature interval is within the expected range + self.assertTrue(testfe.features[0].interval.start >= START_TIME) + + # get sorted list of features based on feature.score + sorted_features = sorted(testfe.features, key=lambda x: x.score, reverse=True) + # check if the highest scoring feature is within the peak range + self.assertTrue(sorted_features[0].interval.start >= PEAK_START) + + + +if __name__ == "__main__": + unittest.main()