Ejemplo n.º 1
0
def findpeaks(filename, music, limit=None, song_name=None):
    # Pool.imap sends arguments as tuples so we have to unpack
    # them ourself.
    try:
        filename, limit = filename
    except ValueError:
        pass

    songname, extension = os.path.splitext(os.path.basename(filename))

    song_name = song_name or songname

    channels, Fs = decoder.read(filename, limit)

    result = set()

    channel_amount = len(channels)
    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" % (channeln + 1,
                                                       channel_amount,
                                                       filename))
        music.append( fingerprint.fingerprint(channel, Fs=Fs) )
        print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount,
                                                 filename))
Ejemplo n.º 2
0
def findpeaks(filename, music, limit=None, song_name=None):
	# Calculates peaks for given music file.

    try:
        filename, limit = filename
    except ValueError:
        pass

    songname, extension = os.path.splitext(os.path.basename(filename))

    song_name = song_name or songname

    channels, Fs, duration = decoder.read(filename, limit)

    result = set()

    channel_amount = len(channels)
    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" % (channeln + 1,
                                                       channel_amount,
                                                       filename))
        music.append( fingerprint(channel, Fs=Fs) )
        print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount,
                                                 filename))

    return duration
Ejemplo n.º 3
0
def _fingerprint_worker(filename, limit=None, channel_id=None):
    # Pool.imap sends arguments as tuples so we have to unpack
    # them ourself.
    try:
        filename, limit = filename
    except ValueError:
        pass

    recordname, extension = os.path.splitext(os.path.basename(filename))
    channel_id = channel_id or recordname
    channels, Fs, file_hash = decoder.read(filename, limit)
    result = set()
    channel_amount = len(channels)

    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" %
              (channeln + 1, channel_amount, filename))
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        print("Finished channel %d/%d for %s" %
              (channeln + 1, channel_amount, filename))
        result |= set(hashes)

        # delete file after fingerprinting
        os.unlink(filename)

    return channel_id, result, file_hash
Ejemplo n.º 4
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t
Ejemplo n.º 5
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)
        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t
        if match:
            match['match_time'] = t

        return match
Ejemplo n.º 6
0
def _fingerprint_worker(arg):
    try:
        song, limit = arg
    except ValueError:
        pass
    channels, frameRate, fileHash = decoder.read(song['songPath'], limit)
    result = set()
    for channeln, channel in enumerate(channels):
        hashes = fingerprint.fingerprint(channel, Fs=frameRate)
        result |= set(hashes)
    return song, fileHash, result
Ejemplo n.º 7
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t
        else:
            match = json.loads('{"result":"failed"}')

        return match
Ejemplo n.º 8
0
 def run(self):
     db = SQLDatabase()
     channels, fs = decoder.read(self.filename)
     result = set()
     for i in range(len(channels)):
         print("Fingerprinting channel %d/%d for %s" % (i + 1, len(channels), self.filename))
         hashes = fingerprint.fingerprint(channels[i], fs=fs)
         print("Finished channel %d/%d for %s" % (i + 1, len(channels), self.filename))
         result |= set(hashes)
     # check
     matches = db.return_matches(result)
     song = db.align_matches(matches)
     print song
     self.signal.emit(song)
Ejemplo n.º 9
0
 def addto_db_click(self):
     db = SQLDatabase()
     filename = self.show_file.text()
     song_name, extension = os.path.splitext(os.path.basename(filename))
     channels, fs = decoder.read(filename)
     result = set()
     for i in range(len(channels)):
         print("Fingerprinting channel %d/%d for %s" % (i + 1, len(channels), filename))
         hashes = fingerprint.fingerprint(channels[i], fs=fs)
         print("Finished channel %d/%d for %s" % (i + 1, len(channels), filename))
         result |= set(hashes)
     # add to db table songs and fingerprints
     sid = db.insert_song(song_name)
     db.insert_fingerprints(sid, result)
     self.show_db_message.setText('添加完成')
Ejemplo n.º 10
0
def _fingerprint_worker(filename, limit=None, song_name=None):
    songname, extension = os.path.splitext(os.path.basename(filename))
    song_name = song_name or songname

    channels, Fs = decoder.read(filename, limit)

    result = set()

    channel_amount = len(channels)
    for i in range(channel_amount):
        print("Fingerprinting channel %d/%d for %s" % (i + 1,channel_amount,filename))
        hashes = fingerprint.fingerprint(channels[i], Fs=Fs)
        print("Finished channel %d/%d for %s" % (i + 1, channel_amount,filename))
        result |= set(hashes)

    return song_name, result
Ejemplo n.º 11
0
 def run(self):
     db = SQLDatabase()
     channels, fs = decoder.read(self.filename)
     result = set()
     for i in range(len(channels)):
         print("Fingerprinting channel %d/%d for %s" %
               (i + 1, len(channels), self.filename))
         hashes = fingerprint.fingerprint(channels[i], fs=fs)
         print("Finished channel %d/%d for %s" %
               (i + 1, len(channels), self.filename))
         result |= set(hashes)
     # check
     matches = db.return_matches(result)
     song = db.align_matches(matches)
     print song
     self.signal.emit(song)
Ejemplo n.º 12
0
 def addto_db_click(self):
     db = SQLDatabase()
     filename = self.show_file.text()
     song_name, extension = os.path.splitext(os.path.basename(filename))
     channels, fs = decoder.read(filename)
     result = set()
     for i in range(len(channels)):
         print("Fingerprinting channel %d/%d for %s" %
               (i + 1, len(channels), filename))
         hashes = fingerprint.fingerprint(channels[i], fs=fs)
         print("Finished channel %d/%d for %s" %
               (i + 1, len(channels), filename))
         result |= set(hashes)
     # add to db table songs and fingerprints
     sid = db.insert_song(song_name)
     db.insert_fingerprints(sid, result)
     self.show_db_message.setText('添加完成')
Ejemplo n.º 13
0
def _fingerprint_worker(filename, limit=None, song_name=None):
    songname, extension = os.path.splitext(os.path.basename(filename))
    song_name = song_name or songname

    channels, Fs = decoder.read(filename, limit)

    result = set()

    channel_amount = len(channels)
    for i in range(channel_amount):
        print("Fingerprinting channel %d/%d for %s" %
              (i + 1, channel_amount, filename))
        hashes = fingerprint.fingerprint(channels[i], Fs=Fs)
        print("Finished channel %d/%d for %s" %
              (i + 1, channel_amount, filename))
        result |= set(hashes)

    return song_name, result
Ejemplo n.º 14
0
    def _fingerprint_worker(self, filename, limit=None, song_name=None):
        # Pool.imap sends arguments as tuples so we have to unpack
        # them ourself.

        songname, extension = os.path.splitext(os.path.basename(filename))
        song_name = song_name or songname
        channels, Fs, file_hash = decoder.read(filename, limit)
        result = set()
        channel_amount = len(channels)

        for channeln, channel in enumerate(channels):
            # TODO: Remove prints or change them into optional logging.
            print("Fingerprinting channel %d/%d for %s" %
                  (channeln + 1, channel_amount, filename))
            hashes = fingerprint.fingerprint(channel, Fs=Fs)
            print("Finished channel %d/%d for %s" % (channeln + 1, \
                     channel_amount, filename))
            result |= set(hashes)
        sid = self.insert_song(song_name, file_hash)
        # add song data to songs dataframe
        self.insert_hashes(sid, list(result))
        # add fingerprints of the song to fingerprints dataframe
        self.get_fingerprinted_songs()
        print('Song added to database')
Ejemplo n.º 15
0
PATH = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(PATH, '../db'))
import mysql_intercom

# 対象wavファイルを設定
TARGET_FILES = [
    '../master/intercom_1.wav', '../master/intercom_2.wav',
    '../master/intercom_3.wav'
]

if __name__ == '__main__':
    # masterの追加
    for filename in TARGET_FILES:
        print(filename, end=': ')
        wavefile = decoder.read(os.path.join(PATH, filename))
        if wavefile == None:
            print('cannot extract wav')
            continue

        with mysql_intercom.Database_intercom(CONFIG.DB_CONFIG) as db:
            master_id = db.insert_master(filename.split('/')[-1])
        if master_id > 0:
            print()
            print('sampling_rate =', wavefile.sampling_rate)
            target_hashes = fingerprint.fingerprint(wavefile.sounds)  # hashの計算
            fingerprint.add_masters_hashes(master_id, target_hashes)  # hashの追加
        else:
            print('cannot insert to masters')
            continue
Ejemplo n.º 16
0
 def recognize_file(self, filename):
     frames, self.Fs, file_hash = decoder.read(filename)
     t = time.time()
     match = self._recognize(frames)
     t = time.time() - t
     return t