コード例 #1
0
def run_recognition(filename, print_output=False):
    db = SqliteDatabase()

    abs_filename = os.path.abspath(filename)
    filename = abs_filename.rsplit(os.sep)[-1]

    r = FileReader(abs_filename)
    data = r.parse_audio()

    Fs = data["Fs"]
    channel_amount = len(data["channels"])
    matches = []

    for channeln, channel in enumerate(data["channels"]):
        # TODO: Remove prints or change them into optional logging.
        #if print_output:
        #    msg = "   fingerprinting channel %d/%d"
        #    print(
        #        logmsg(msg, attrs=["dark"], prefix=filename)
        #        % (channeln + 1, channel_amount)
        #    )

        matches.extend(find_matches(db, channel, Fs, filename, print_output))

        #if print_output:
        #    msg = "   finished channel %d/%d, got %d hashes"
        #    print(
        #        logmsg(msg, attrs=["dark"], prefix=filename)
        #        % (channeln + 1, channel_amount, len(matches))
        #    )

    #print_match_results(db, matches, filename)
    return matches
def run_recognition(filename, logger):
    db = SqliteDatabase()

    abs_filename = os.path.abspath(filename)
    filename = abs_filename.rsplit(os.sep)[-1]

    r = FileReader(abs_filename)
    data = r.parse_audio()

    Fs = data["Fs"]
    channel_amount = len(data["channels"])
    matches = []

    for channeln, channel in enumerate(data["channels"]):
        msg = "   fingerprinting channel %d/%d"
        logger.info(
            logmsg(msg, attrs=["dark"], prefix=filename),
            channeln + 1,
            channel_amount,
        )

        matches.extend(find_matches(db, channel, logger, Fs, filename))

        msg = "   finished channel %d/%d, got %d hashes"
        logger.info(
            logmsg(msg, attrs=["dark"], prefix=filename),
            channeln + 1,
            channel_amount,
            len(matches),
        )

    print_match_results(db, matches, logger, filename)
コード例 #3
0
def get_dict_for_file(file_name):
    reader = FileReader(filename=file_name)
    audio = reader.parse_audio()
    data = audio['channels']

    hashes = set()
    for channel in data:
        channel_hashes = fingerprint(channel)
        hashes |= set(channel_hashes)
    dict_song = {hash: offset for hash, offset in hashes}
    return dict_song
コード例 #4
0
from libs.reader_file import FileReader
from libs.db_sqlite import SqliteDatabase
from libs.config import get_config

if __name__ == '__main__':
    config = get_config()

    db = SqliteDatabase()
    path = "mp3/"

    # fingerprint all files in a directory

    for filename in os.listdir(path):
        if filename.endswith(".mp3"):
            reader = FileReader(path + filename)
            audio = reader.parse_audio()

            song = db.get_song_by_filehash(audio['file_hash'])
            song_id = db.add_song(filename, audio['file_hash'])

            msg = ' * %s %s: %s' % (
                colored('id=%s', 'white', attrs=['dark']),  # id
                colored('channels=%d', 'white', attrs=['dark']),  # channels
                colored('%s', 'white', attrs=['bold'])  # filename
            )
            print(msg % (song_id, len(audio['channels']), filename))

            if song:
                hash_count = db.get_song_hashes_count(song_id)

                if hash_count > 0:
コード例 #5
0
from argparse import RawTextHelpFormatter
from itertools import izip_longest
from termcolor import colored
from libs.config import get_config
from libs.reader_microphone import MicrophoneReader
from libs.visualiser_console import VisualiserConsole as visual_peak
from libs.visualiser_plot import VisualiserPlot as visual_plot
from libs.db_sqlite import SqliteDatabase

song = '/home/blacksec21/hello.mp3'
#seconds = 5

r = FileReader(song)  # only get filename

# get data,fs,file_hash,extension,songname,num_channels
data = r.parse_audio()
Fs = data['Fs']
num_channel = len(data['channels'])

result = set()
matches = []
db = SqliteDatabase()
#channel_amount = len(data)


def grouper(iterable, n, fillvalue=None):
    args = [iter(iterable)] * n
    return (filter(None, values)
            for values in izip_longest(fillvalue=fillvalue, *args))

コード例 #6
0
    if not args.file:
        parser.print_help()
        sys.exit(0)

    visualise_console = bool(config['mic.visualise_console'])
    visualise_plot = bool(config['mic.visualise_plot'])

    reader = FileReader(args.file)

    def grouper(iterable, n, fillvalue=None):
        args = [iter(iterable)] * n
        return (filter(None, values)
                for values in izip_longest(fillvalue=fillvalue, *args))

    data = reader.parse_audio()

    channel_amount = len(data['channels'])
    print colored(' * found %d samples in %d channels', attrs=['dark']) % (len(
        data['channels'][0]), channel_amount)

    Fs = data['Fs']

    result = set()
    matches = []

    def find_matches(samples, Fs=fingerprint.DEFAULT_FS):
        hashes = fingerprint.fingerprint(samples, Fs=Fs, plots=False)
        return return_matches(hashes)

    def return_matches(hashes):
from libs.reader_file import FileReader

song = None
seconds = 5

r = FileReader(
    '/home/kwok/projects/audio-fingerprint-identifying-python/mp3/beatles.mp3')

print(r.parse_audio())