Example #1
0
    def test_read_annotation_files_count(self):
        files = main.read_annotation_files(ANNOTATION_FILES_DIRECTORY,
                                           AUDIO_FILES_DIRECTORY, 0)
        self.assertEqual(0, len(files))

        files = main.read_annotation_files(ANNOTATION_FILES_DIRECTORY,
                                           AUDIO_FILES_DIRECTORY, 7)
        self.assertEqual(7, len(files))

        files = main.read_annotation_files(ANNOTATION_FILES_DIRECTORY,
                                           AUDIO_FILES_DIRECTORY, 100)
        self.assertEqual(10, len(files))
Example #2
0
    def test_load_and_save_files(self):
        all_files = main.read_annotation_files(ANNOTATION_FILES_DIRECTORY,
                                               AUDIO_FILES_DIRECTORY, 10)
        main.calculate_cosine_similarity_matrix(all_files)
        main.calculate_dtw_cost_matrix(all_files)

        main.save_files_to_dump_file(all_files, ALL_FILES_DUMP_FILE)
        all_files_from_dump = main.load_files_from_dump_file(
            ALL_FILES_DUMP_FILE)

        for file, dump_file in zip(all_files, all_files_from_dump):
            self.assertEqual(file.directory, dump_file.directory)
            self.assertEqual(file.filename, dump_file.filename)
            self.assertEqual(file.scene, dump_file.scene)
            self.assertEqual(file.city, dump_file.city)
            self.assertSetEqual(file.classes, dump_file.classes)

            self.assertTrue(np.array_equal(file.mfcc, dump_file.mfcc))
            self.assertTrue(
                np.array_equal(file.mfcc_coefficients,
                               dump_file.mfcc_coefficients))

            self.assertListEqual(
                [f.filename for f in file.cosine_similarities.keys()],
                [f.filename for f in dump_file.cosine_similarities.keys()])
            self.assertListEqual(list(file.cosine_similarities.values()),
                                 list(dump_file.cosine_similarities.values()))

            self.assertListEqual(
                [f.filename for f in file.dtw_costs.keys()],
                [f.filename for f in dump_file.dtw_costs.keys()])
            self.assertListEqual(list(file.dtw_costs.values()),
                                 list(dump_file.dtw_costs.values()))
Example #3
0
    def test_dtw_cost(self):
        file1, file2 = main.read_annotation_files(ANNOTATION_FILES_DIRECTORY,
                                                  AUDIO_FILES_DIRECTORY, 2)

        dtw_cost = file1.calculate_dtw_cost(file2)
        self.assertEqual(dtw_cost, file1.dtw_costs[file2])
        self.assertEqual(dtw_cost, file2.dtw_costs[file1])

        self.assertEqual(0, file1.calculate_dtw_cost(file1))
Example #4
0
    def test_group_files_by_scene(self):
        file1, file2, file3, file4, file5 = main.read_annotation_files(
            ANNOTATION_FILES_DIRECTORY, AUDIO_FILES_DIRECTORY, 5)

        collection = AudioFileCollection([file1, file2, file3, file4, file5],
                                         lambda file: file.scene)
        self.assertListEqual([file1], collection["Public square"])
        self.assertListEqual([file2, file4, file5], collection["Park"])
        self.assertListEqual([file3], collection["Airport"])
Example #5
0
    def test_get_all_classes(self):
        files = main.read_annotation_files(ANNOTATION_FILES_DIRECTORY,
                                           AUDIO_FILES_DIRECTORY, 5)
        classes = main.get_all_classes(files)

        self.assertListEqual(
            sorted([
                "Siren", "Traffic noise", "Birds singing", "Footsteps",
                "Adults talking", "Children voices"
            ]), classes)
Example #6
0
    def test_group_files_by_city(self):
        file1, file2, file3, file4, file5 = main.read_annotation_files(
            ANNOTATION_FILES_DIRECTORY, AUDIO_FILES_DIRECTORY, 5)

        collection = AudioFileCollection([file1, file2, file3, file4, file5],
                                         lambda file: file.city)
        self.assertListEqual([file1], collection["Paris"])
        self.assertListEqual([file2, file4], collection["Helsinki"])
        self.assertListEqual([file3], collection["Stockholm"])
        self.assertListEqual([file5], collection["London"])
Example #7
0
    def test_audio_file_collection_all_files_category(self):
        file1, file2, file3, file4, file5 = main.read_annotation_files(
            ANNOTATION_FILES_DIRECTORY, AUDIO_FILES_DIRECTORY, 5)

        collection = AudioFileCollection([file1, file2, file3, file4, file5])
        self.assertTrue("All" not in collection)

        collection.add_all_files_category()
        self.assertListEqual([file1, file2, file3, file4, file5],
                             collection["All"])

        collection.remove_all_files_category()
        self.assertTrue("All" not in collection)
Example #8
0
    def test_group_files_by_class(self):
        file1, file2, file3, file4, file5 = main.read_annotation_files(
            ANNOTATION_FILES_DIRECTORY, AUDIO_FILES_DIRECTORY, 5)

        collection = AudioFileCollection([file1, file2, file3, file4, file5])
        self.assertListEqual([file1], collection["Siren"])
        self.assertListEqual([file1], collection["Traffic noise"])
        self.assertListEqual([file1, file4, file5],
                             collection["Birds singing"])
        self.assertListEqual([file2, file4], collection["Footsteps"])
        self.assertListEqual([file2, file3, file4],
                             collection["Adults talking"])
        self.assertListEqual([file5], collection["Children voices"])
Example #9
0
    def test_read_annotation_files(self):
        file1, file2 = main.read_annotation_files(ANNOTATION_FILES_DIRECTORY,
                                                  AUDIO_FILES_DIRECTORY, 2)

        self.assertEqual(file1.directory, AUDIO_FILES_DIRECTORY)
        self.assertEqual(file1.filename, "public_square-paris-117-3426-a.wav")
        self.assertEqual(file1.scene, "Public square")
        self.assertEqual(file1.city, "Paris")
        self.assertEqual(file1.place, "Public square, Paris")
        self.assertSetEqual(file1.classes,
                            {"Siren", "Traffic noise", "Birds singing"})

        self.assertEqual(file2.directory, AUDIO_FILES_DIRECTORY)
        self.assertEqual(file2.filename, "park-helsinki-242-7205-a.wav")
        self.assertEqual(file2.scene, "Park")
        self.assertEqual(file2.city, "Helsinki")
        self.assertEqual(file2.place, "Park, Helsinki")
        self.assertSetEqual(file2.classes, {"Footsteps", "Adults talking"})