热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Splitfingerprinting

test_fingerprint_by_splitting.pycreateslongfilefromtheexistingfilesinmp3/.

test_fingerprint_by_splitting.py creates long file from the existing files in mp3/.

to fingerprint with a length check you should use
djv.fingerprint_with_duration_check(long_song, song_name="Concatenates_test")
as shown in the split-test file

该提问来源于开源项目:worldveil/dejavu

The solution that worked for me to get the offsets correct is to (A) extract the offset (in seconds) as defined by the split file name (ex. start_sec60_end_sec120.mp3), (B) convert the seconds value to the equivalent sampling offset value, and (C) add the derived sampling offset value to the offset as determined by the fingerprinting process for the given file.



Note: I am using a different fork so some of the smaller details may be different ex. database.py naming.

(A) Extract Offset Data & (B) Extract Offset Data



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# __init__.py



def _fingerprint_worker(filename, limit=None, song_name=None):

   ...

   channel_amount = len(channels)



   # Get Offset from name.

   try:

       first_split = song_name.split("start_sec", 1)

       select_second = first_split[1]

       second_split = select_second.split("_end_sec", 1)



       # Convert second_split[0] to sampling offset

       split_offset = round(

           int(second_split[0]) * fingerprint.DEFAULT_FS /

           fingerprint.DEFAULT_WINDOW_SIZE / fingerprint.DEFAULT_OVERLAP_RATIO,

           5

       )

   except:

       split_offset = 0

    ...

    return song_name, result, file_hash, split_offset

Iterate and Pass the Value

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# __init__.py



while True:

            try:

                song_name, hashes, file_hash, split_offset = next(iterator)

            ...

            else:

                #sid = self.db.insert_song(song_name, file_hash) # REMOVE

                if treat_as_split and song_name_for_the_split:

                    sid = self.db.insert_song(song_name_for_the_split, file_hash)

                if not treat_as_split:

                    sid = self.db.insert_song(song_name, file_hash)              



                self.db.insert_hashes(sid, hashes, split_offset)

                ...

(C) Apply Offset

1
2
3
4
5
6
7
8
9
10
11
12
13
# database.py



    def insert_hashes(self, sid, hashes, split_offset=0):

        ...

        for hash, offset in set(hashes):

            fingerprints.append(

                Fingerprint(

                    hash=binascii.unhexlify(hash),

                    song_id=sid,

                    offset=int(offset+split_offset)

                )

            )

        self.session.bulk_save_objects(fingerprints)



   



推荐阅读
author-avatar
姥姥的妹妹的儿子跟我没关系
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有