Example #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)
Example #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
from termcolor import colored
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)
Example #5
0
from libs.reader_file import FileReader
from libs.db_sqlite import SqliteDatabase
from libs.config import get_config
from libs import fingerprint
import argparse
from functools import partial

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-s', '--seconds', default = 5)
    parser.add_argument('-f', '--file_name')
    args = parser.parse_args()

    file_name, seconds = args.file_name, args.seconds
    reader = FileReader(filename = file_name)
    audio = reader.parse_audio()
    data = audio['channels']
    Fs = fingerprint.DEFAULT_FS
    channel_amount = len(data)

    config = get_config()
    db = SqliteDatabase()
    find_matches_with_db = partial(fingerprint.find_matches, db = db)
    #try:
    matches = []
    for channeln, channel in enumerate(data):
        # TODO: Remove prints or change them into optional logging.
        matches.extend(find_matches_with_db(samples = channel))

        #msg = '   finished channel %d/%d, got %d hashes'
        #print(colored(msg, attrs=['dark']) % (
Example #6
0
import libs.fingerprint as fingerprint
import argparse
from libs.reader_file import FileReader
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)
Example #7
0
  db = SqliteDatabase()

  parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
  parser.add_argument('-f', '--file', nargs='?')
  args = parser.parse_args()

  if not args.file:
    parser.print_help()
    sys.exit(0)

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

  r = FileReader(args.file)
  song = r.recognize()

  print(song)
  data = song["channels"]

  msg = ' * recorded %d samples'
  print colored(msg, attrs=['dark']) % len(data[0])

  # reader.save_recorded('test.wav')


  Fs = fingerprint.DEFAULT_FS
  channel_amount = len(data)

  result = set()
Example #8
0
from libs.reader_file import FileReader

song = None
seconds = 5

r = FileReader(123)
r.recognize(seconds=seconds)

print(song)
Example #9
0
from libs.reader_file import FileReader

song = None
seconds = 5

r = FileReader("Ed Sheeran - Shape of You [Official Video].mp3")

print(r.filename)
Example #10
0
    config = get_config()

    db = SqliteDatabase()

    parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
    parser.add_argument('-f', '--file', nargs='?')
    args = parser.parse_args()

    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()
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())