Ejemplo n.º 1
0
def calc_accuracy(path1, path2):
    dur, fig = acoustid.fingerprint_file(path1)
    fp1 = chromaprint.decode_fingerprint(fig)[0]

    dur, fig2 = acoustid.fingerprint_file(path2)
    fp2 = chromaprint.decode_fingerprint(fig2)[0]

    return accuracy(fp1, fp2)
def match_audio(song1, song2):
    duration1, fp_encoded1 = acoustid.fingerprint_file(song1)
    duration2, fp_encoded2 = acoustid.fingerprint_file(song2)
    fingerprint1, version1 = chromaprint.decode_fingerprint(fp_encoded1)
    fingerprint2, version2 = chromaprint.decode_fingerprint(fp_encoded2)

    similarity = fuzz.ratio(fingerprint1, fingerprint2)
    print(similarity)

    if similarity >= 80:
        return similarity

    return 0
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-length', metavar='SECS', type=int, default=120,
                        help='length of the audio data used for fingerprint '
                             'calculation (default 120)')
    parser.add_argument('-raw', action='store_true',
                        help='output the raw uncompressed fingerprint')
    parser.add_argument('paths', metavar='FILE', nargs='+',
                        help='audio file to be fingerprinted')

    args = parser.parse_args()
    del sys.argv[1:] # to make gst not try to parse the args

    first = True
    for i, path in enumerate(args.paths):
        try:
            duration, fp = acoustid.fingerprint_file(path, args.length)
        except Exception:
            print >>sys.stderr, "ERROR: unable to calculate fingerprint " \
                                "for file %s, skipping" % path
            continue
        if args.raw:
            raw_fp = chromaprint.decode_fingerprint(fp)[0]
            fp = ','.join(map(str, raw_fp))
        if not first:
            print
        first = False
        print 'FILE=%s' % path
        print 'DURATION=%d' % duration
        print 'FINGERPRINT=%s' % fp
Ejemplo n.º 4
0
def _fingerprint(path, force_fpcalc=False):
    "Get the AcoustID fingerprint for an audio track"

    duration, fp = fingerprint_file(path, force_fpcalc=force_fpcalc)
    duration = timedelta(seconds=duration)
    fingerprint, version = decode_fingerprint(fp)
    assert version == settings.FINGERPRINT_VERSION, 'Version mismatch: %s' % version
    return duration, fingerprint
Ejemplo n.º 5
0
    def test_fingerprinting_methods(self):
        "Verify that fpcalc and acoustid produce identical fingerprints"

        duration, fp = fingerprint_file(self.AUDIO_TRACK1, force_fpcalc=True)
        fp, version = decode_fingerprint(fp)
        self.assertEqual(version, settings.FINGERPRINT_VERSION)

        self.assertEqual(int(self.fp1.duration.total_seconds()), duration)
        self.assertSequenceEqual(self.fp1.fingerprint, fp)
Ejemplo n.º 6
0
def generate_fingerprint(fname: str) -> List[int]:
    """return an audio fingerprint for a video file.
    """
    audioclip = AudioFileClip(fname)
    audioclip.write_audiofile("temp.wav")

    duration, fp_encoded = acoustid.fingerprint_file("temp.wav")
    fingerprint, version = decode_fingerprint(fp_encoded)

    os.remove("temp.wav")
    return fingerprint
Ejemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-length',
                        metavar='SECS',
                        type=int,
                        default=120,
                        help='length of the audio data used for fingerprint '
                        'calculation (default 120)')
    parser.add_argument('-raw',
                        action='store_true',
                        help='output the raw uncompressed fingerprint')
    parser.add_argument('paths',
                        metavar='FILE',
                        nargs='+',
                        help='audio file to be fingerprinted')

    args = parser.parse_args()
    # make gst not try to parse the args
    del sys.argv[1:]

    first = True
    for i, path in enumerate(args.paths):
        try:
            duration, fp = acoustid.fingerprint_file(path, args.length)
        except Exception:
            print("ERROR: unable to calculate fingerprint "
                  "for file %s, skipping" % path,
                  file=sys.stderr)
            continue
        if args.raw:
            raw_fp = chromaprint.decode_fingerprint(fp)[0]
            fp = ','.join(map(str, raw_fp))
        if not first:
            print
        first = False
        print('FILE=%s' % path)
        print('DURATION=%d' % duration)
        print('FINGERPRINT=%s' % fp.decode('utf8'))
Ejemplo n.º 8
0
def get_fingpr(filename):
    duration, fp_encoded = acoustid.fingerprint_file(filename)
    fingerprint, version = chromaprint.decode_fingerprint(fp_encoded)
    return (fingerprint)
Ejemplo n.º 9
0
(options, args) = parser.parse_args()

if not args:
    parser.error("missing filename")

wav = wave.open(args[0], 'r')

fpgen = chromaprint.Fingerprinter()
fpgen.start(wav.getframerate(), wav.getnchannels())
length = 0
while length < options.length:
    frames = wav.readframes(1024 * 4)
    if not frames:
        break
    fpgen.feed(frames)
    length += float(len(frames)) / wav.getsampwidth() / wav.getnchannels() / wav.getframerate()
fp = fpgen.finish()

total_length = wav.getnframes() / wav.getframerate()
print "FILE:", args[0]
print "CHANNELS:", wav.getnchannels()
print "SAMPLE RATE:", wav.getframerate()
print "LENGTH:", total_length
print "FINGERPRINT:", ', '.join(map(str, chromaprint.decode_fingerprint(fp)[0]))
print "ENCODED FINGERPRINT:", fp

url = "http://api.acoustid.org/lookup?client=8XaBELgH&meta=1&length=%s&fingerprint=%s" % (total_length, fp)
print
print url

Ejemplo n.º 10
0
def decode_fingerprint(fingerprint_string):
    """Decode a compressed and base64-encoded fingerprint"""
    fingerprint, version = chromaprint.decode_fingerprint(fingerprint_string)
    if version == FINGERPRINT_VERSION:
        return fingerprint
def calculate_fingerprints(filename):
   print('calculate fingerprints of audio file') 
   duration, fp_encoded = acoustid.fingerprint_file(filename)
   fingerprint, version = chromaprint.decode_fingerprint(fp_encoded)
   return fingerprint
Ejemplo n.º 12
0
def decode_fingerprint(fingerprint_string):
    """Decode a compressed and base64-encoded fingerprint"""
    fingerprint, version = chromaprint.decode_fingerprint(fingerprint_string)
    if version == FINGERPRINT_VERSION:
        return fingerprint
Ejemplo n.º 13
0
#!/usr/bin/env python

import re
import sys
import os
from chromaprint import Fingerprinter, decode_fingerprint
from audiodecoder import AudioDecoder

#print libchromaprint.chromaprint_get_version()
print "=> Decoding audio data"
decoder = AudioDecoder(sys.argv[1])
length, sample_rate, num_channels, data = decoder.decode()
print "=> Length:", length
print "=> Sample rate:", sample_rate
print "=> Number of channels:", num_channels

print "=> Calculating fingerprint"
fpcal = Fingerprinter()
fpcal.start(sample_rate, num_channels)
fpcal.feed(data)
fingerprint = fpcal.finish()

print fingerprint
print decode_fingerprint(fingerprint)
Ejemplo n.º 14
0
def FingerPrintAudio(filename):
    duration, fp_encoded = acoustid.fingerprint_file(filename)
    fingerprint, version = chromaprint.decode_fingerprint(fp_encoded)
    #print(fingerprint)
    return fingerprint
Ejemplo n.º 15
0
#print libchromaprint.chromaprint_get_version()
print "=> Decoding audio data"
decoder = AudioDecoder(sys.argv[1])
length, sample_rate, num_channels, data = decoder.decode(duration=60)
print "=> Length:", length
print "=> Sample rate:", sample_rate
print "=> Number of channels:", num_channels

print "=> Calculating fingerprint"
fpcal = Fingerprinter()
fpcal.start(sample_rate, num_channels)
fpcal.feed(data)
fingerprint = fpcal.finish()

#print fingerprint
fp = decode_fingerprint(fingerprint)[0]

#fp = map(s24tou, fp)
print "FP length", len(fp)
print "FP uniq length", len(set(fp))

image = QtGui.QImage(32, len(fp), QtGui.QImage.Format_Mono)

for y, bits in enumerate([s32tou(x) for x in fp]):
    for x in range(32):
        index = 0
        if bits & (1 << x):
            index = 1
        image.setPixel(x, y, index)
image.save('fp.png')
Ejemplo n.º 16
0
def fingerprint(path: str, length: int = 120, raw: bool = False) -> str:
    duration, fp = acoustid.fingerprint_file(path, length)
    if raw:
        raw_fp = chromaprint.decode_fingerprint(fp)[0]
        fp = ','.join(map(str, raw_fp))
    return fp
Ejemplo n.º 17
0
import acoustid, chromaprint, sys, difflib

for k in range(1, 10):
    for j in range(k, 10):
        id1 = str(k)
        id2 = str(j)
        (duration,
         bytestring) = acoustid.fingerprint_file("mp3/" + id1 + ".mp3")
        (duration2,
         bytestring2) = acoustid.fingerprint_file("mp3/" + id2 + ".mp3")
        fingerprint = chromaprint.decode_fingerprint(bytestring)[0]
        fingerprint2 = chromaprint.decode_fingerprint(bytestring2)[0]

        diff = 0
        lenght = len(min(fingerprint, fingerprint2))
        for i in range(lenght):
            #print('{0:b}'.format(fingerprint[i] ^ fingerprint2[i]))
            diff += ('{0:b}'.format(fingerprint[i]
                                    ^ fingerprint2[i])).count("1")
        str_prnt = id1 + " vs " + id2 + " diff " + str(diff)
        print(str_prnt)

        if fingerprint[0] == fingerprint2[0]:
            print("Equal")
        else:
            print("Not")
Ejemplo n.º 18
0
Created on Sat May 19 12:38:10 2018

I pulled basic examples from on-line somewhere... but I implemented them here comparing a file (on local device) with a "live" recording
"""

import acoustid
import chromaprint
import sounddevice as sd
import soundfile as sf
import pygame
from fuzzywuzzy import fuzz


#example of fingerprint w chromaprint
duration, fp_encoded = acoustid.fingerprint_file('dove-Mike_Koenig-1208819046.wav')
fingerprint, version = chromaprint.decode_fingerprint(fp_encoded)
print(fingerprint)

#plotting the fingerprint
import numpy as np
import matplotlib.pyplot as plt
plt.figure()
bitmap = np.transpose(np.array([[b=='1' for b in list('{:32b}'.format(i & 0xffffffff))]for i in fingerprint]))
plt.imshow(bitmap)

pygame.quit()


#check similarity with another file

#first create new wave file (user mimics the sound)
    7,
    7,
    8,
]


def popcnt(x):
    """
    Count the number of set bits in the given 32-bit integer.
    """
    return (popcnt_table_8bit[(x >> 0) & 0xFF] +
            popcnt_table_8bit[(x >> 8) & 0xFF] +
            popcnt_table_8bit[(x >> 16) & 0xFF] +
            popcnt_table_8bit[(x >> 24) & 0xFF])


fps = []
for line in open('fp.log').readlines():
    if line.startswith('FINGERPRINT='):
        encoded = line.split('=', 1)[1].strip()
        fps.append(chromaprint.decode_fingerprint(encoded)[0])

for i, fp1 in enumerate(fps):
    for j, fp2 in enumerate(fps):
        if i >= j:
            continue
        error = 0
        for x, y in zip(fp1, fp2):
            error += popcnt(x ^ y)
        print i, j, 1.0 - error / 32.0 / min(len(fp1), len(fp1))
Ejemplo n.º 20
0
# -*- coding: utf-8 -*-
__author__ = 'Glebov Boris'

import acoustid
import chromaprint

if __name__ == '__main__':
    duration, fp = acoustid.fingerprint_file('/home/warlock/Music/л1.mp3', 120)

    raw_fp = chromaprint.decode_fingerprint('')[0]
    fp = ','.join(map(str, raw_fp))

    print 'DURATION=%d' % duration
    print 'FINGERPRINT=%s' % fp
Ejemplo n.º 21
0
#print libchromaprint.chromaprint_get_version()
print "=> Decoding audio data"
decoder = AudioDecoder(sys.argv[1])
length, sample_rate, num_channels, data = decoder.decode(duration=60)
print "=> Length:", length
print "=> Sample rate:", sample_rate
print "=> Number of channels:", num_channels

print "=> Calculating fingerprint"
fpcal = Fingerprinter()
fpcal.start(sample_rate, num_channels)
fpcal.feed(data)
fingerprint = fpcal.finish()

#print fingerprint
fp = decode_fingerprint(fingerprint)[0]

#fp = map(s24tou, fp)
print "FP length", len(fp)
print "FP uniq length", len(set(fp))

image = QtGui.QImage(32, len(fp), QtGui.QImage.Format_Mono)

for y, bits in enumerate([s32tou(x) for x in fp]):
    for x in range(32):
        index = 0
        if bits & (1 << x):
            index = 1
        image.setPixel(x, y, index)
image.save('fp.png')
!pip install fuzzywuzzy[speedup]

import acoustid
import chromaprint
from fuzzywuzzy import fuzz
import librosa

from google.colab import drive
drive.mount("/content/gdrive", force_remount=True)

basepath = "/content/gdrive/My Drive/PAS"

audio1_source_name = "/LowPassed/Maryam/"
audio_clip_s = "SF-17.wav"
audio_s = basepath + audio1_source_name + audio_clip_s

audio1_source_name = "/LowPassed/results/MS-17_Maryam_10000_0.002/"
audio_clip_m = "(10000).wav"
audio_m = basepath + audio1_source_name + audio_clip_m

duration, fp_encoded = acoustid.fingerprint_file(audio_s)
fingerprint_s, version = chromaprint.decode_fingerprint(fp_encoded)

duration, fp_encoded = acoustid.fingerprint_file(audio_m)
fingerprint_m, version = chromaprint.decode_fingerprint(fp_encoded)

print(audio_s)
print(audio_m)

similarity = fuzz.ratio(fingerprint_s, fingerprint_m)
print(similarity)
Ejemplo n.º 23
0
import acoustid
import numpy as np
import chromaprint

path = './heaven.mp3'
path2 = './heaven_small.mp3'
path3 = './undertheice.mp3'

dur, fig = acoustid.fingerprint_file(path)
# fig = np.fromstring(fig, uint8);
raw_fp = chromaprint.decode_fingerprint(fig)[0]
fp = ','.join(map(str, raw_fp))
fig = fp.decode('utf8')


dur, fig2 = acoustid.fingerprint_file(path2)
raw_fp2 = chromaprint.decode_fingerprint(fig2)[0]

dur, fig3 = acoustid.fingerprint_file(path3)
raw_fp3 = chromaprint.decode_fingerprint(fig3)[0]

popcnt_table_8bit = [
    0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
    1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
    1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
    2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
    1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
    2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
    2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
    3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
]
Ejemplo n.º 24
0
            popcnt_table_8bit[(x >> 24) & 0xFF])


if len(sys.argv) != 3:
    print >> sys.stderr, "fingerdist.py <fingerprints.txt> <track.ogg>"
    print >> sys.stderr, "  Requires exactly two arguments"
    sys.exit(1)

in_file = sys.argv[1]

fps = []
for line in open(in_file).readlines():
    if not line.startswith('FAILED:'):
        encoded, filename = line.split(' ', 1)
        fps.append((filename.strip(),
                    chromaprint.decode_fingerprint(encoded.strip())[0]))
try:
    data = chromaprint.decode_fingerprint(
        acoustid.fingerprint_file(sys.argv[2])[1].decode("utf-8"))[0]
except:
    print >> sys.stderr, "FAILED to generate fingerprint:", sys.argv[2]
    sys.exit(1)
if len(data) == 0:
    print >> sys.stderr, "FAILED to generate fingerprint:", sys.argv[2]
    sys.exit(1)

for j, fp in enumerate(fps):
    filename, array = fp
    if len(array) == 0:
        continue
    error = 0