コード例 #1
0
def fingerprint(args):
    print args
    (surahDirectory, surahFile) = args
    surahFile = surahDirectory.rstrip('/') + "/" + surahFile

    databaseName = "dejavu" + os.path.basename(surahFile)[:3]
    # MySQL database config
    # Dejavu stores fingerprints in MySQL using the config provided below.
    config = {
        "database": {
            "host": DATABASE_HOST,
            "user": DATABASE_USER,
            "passwd": DATABASE_PASSWORD,
            "db": databaseName,
        }
    }

    print surahFile.split("/")[-1]

    # Create a database for the current surah
    db1 = mysql.connect(host=config["database"]["host"],
                        user=config["database"]["user"],
                        passwd=config["database"]["passwd"])
    cursor = db1.cursor()
    sql = 'CREATE DATABASE IF NOT EXISTS ' + config["database"]["db"]
    cursor.execute(sql)

    # Pass the MySQL config to dejavu to fingerprint the surah
    djv = Dejavu(config)
    djv.fingerprint_file(surahFile)
コード例 #2
0
def main():
    # Set up our commang line arguments
    parser = argparse.ArgumentParser(description="Take in a folder of video and/or audio files and find the alignment"
                                                 "of them all.")
    parser.add_argument("folder",type=str,help="The folder containing your audio and video files, relative to the current directory.")
    args = parser.parse_args()

    # Our DB settings
    config = {
        "database": {
            "host": "127.0.0.1",
            "user": "******",
            "passwd": "root",
            "db": "dejavu"
        }
    }


    # Get the files in our folder
    dir = os.path.expanduser(args.folder)
    files = os.listdir(dir)


    # Set up our dejavu instance
    djv = Dejavu(config)


    # Generate our corpus name - we'll add this functionality later.
    corpus = dir.replace(" ","")
    corpus = corpus.lower()

    # For now, let's just empty the DB before the experiment
    djv.db.empty()

    # Iterate through the files
    for filename in files:
        full_path = os.path.join(dir,filename)

        # For now we'll assume all the files are valid audio or video
        if (os.path.isfile(full_path)):

            print "Attempting to match {0}...".format(filename)

            # Try to match the song to the existing database
            songs = djv.recognize(FileRecognizer, full_path)

            if songs:
                for song in songs:
                    print song
            else:
                print "No matches found."

            print "Adding {0} to database...".format(filename)

            # Now let's add this song to the DB
            djv.fingerprint_file(full_path)

            print djv.db.get_num_fingerprints()
コード例 #3
0
ファイル: febreze.py プロジェクト: moorthi07/HappyDay
def start_febreze():
    djv = Dejavu(config)
    for ele in learn_music:
        djv.fingerprint_file('mp3/' + str(ele) + '.mp3')
    print('Sleeping for 5 seconds')
    time.sleep(5)
    print('Listening for sounds')
    song = djv.recognize(MicrophoneRecognizer, seconds=10)
    print(song)
    if song['song_name'] in learn_music and song['confidence'] > 500:
        response = requests.request("PUT", url, data=payload, headers=headers)
        temp = json.loads(response.text)
        if str(temp['status']) == 'OK':
            print('Dispensed Febreze')
コード例 #4
0
def fingerprintFile(fileName):
    config = {
        "database": {
            "host": "127.0.0.1",
            "user": MYSQL_USER,
            "passwd": MYSQL_PASS,
            "db": "dejavu",
        },
        "database_type": "mysql",
        "fingerprint_limit": -1
    }

    djv = Dejavu(config)

    djv.fingerprint_file(fileName + ".wav", fileName)
コード例 #5
0
ファイル: __init__.py プロジェクト: projectjamjar/lilo
class Lilo():
    """
    The class for JamJar which will be used to identify video matches and add fingerprints to the database
    """

    def __init__(self, config, filename, video_id):
        """
        usage:
            fingerprinter = Lilo('/path/to/video/file','unique_video_id')
        """
        self.djv = Dejavu(config)
        self.filename = filename
        self.video_id = video_id

        # cache these after first fingerprint
        self.hashes = None

    def recognize_track(self):
        # Try to match the song to the existing database
        hashes, songs = self.djv.recognize(FileRecognizer, self.filename)

        self.hashes = hashes

        return songs

    def fingerprint_song(self):
        # Now let's add this song to the DB
        data = self.djv.fingerprint_file(self.filename, self.video_id, cached_hashes=self.hashes)
        return data

    def check_if_fingerprinted(self):
        video_hash = unique_hash(self.filename)
        # Set self.djv.songhashes_set
        fingerprinted_video_hashes = self.djv.get_fingerprinted_songs()
        return video_hash in self.djv.songhashes_set
コード例 #6
0
class RecognizerService:
    def __init__(self, database_path):
        self.database_path = database_path
        self.dburl = os.getenv('DATABASE_URL',
                               'sqlite:///' + self.database_path)
        self.djv = Dejavu(dburl=self.dburl)

    def recognize(self, filename, dir='uploads/'):
        str_path = dir + filename
        return self.recognize_file_path(str_path)

    def finger_print(self, filename_path):
        self.djv.fingerprint_file(filename_path)
        return self.recognize_file_path(filename_path)

    def recognize_file_path(self, file_path):
        match_list = self.djv.recognize(FileRecognizer, file_path)
        result = list(match_list)
        return result

    def recognize_stream(self, filename, dir='uploads/'):
        str_path = dir + filename
        return self.stream_recognize_file_path(str_path)

    def stream_recognize_file_path(self, file_path):
        match_list = self.djv.recognize(FileRecognizer, file_path)
        return match_list
        # for match in match_list:
        #     yield match

    def nonblocking_recognize_file_path(self, file_path, ws):
        r = FileRecognizer(self.djv)
        frames, r.Fs = decoder.read_chunks(file_path, r.dejavu.limit)
        for i, val in enumerate(frames):
            match = r._recognize(*val)
            if match is not None:
                match['segment_id'] = i
                match['start_time'] = i * ChunksTime / 1000
                ws.write_message(json.dumps(match))
            else:
                ws.write_message(json.dumps({}))
コード例 #7
0
ファイル: tests_dejavu.py プロジェクト: pguridi/dejavu
class DejavuPlainDBTestCases(unittest.TestCase):
    def setUp(self):
        self.djv = Dejavu(config_plain)

    def tearDown(self):
        self.djv.db.empty()
        del self.djv

    def test_fingerprint_1_file(self):
        self.djv.fingerprint_file("tests/test1.mp3")
        # should be the only fingerprinted file
        self.assertEqual(1, self.djv.db.get_num_songs())

        self.assertEqual(5279, self.djv.db.get_num_fingerprints())

    def test_fingerprint_directory(self):
        list_dir = [f for f in os.listdir("tests") if f[-4:] == ".mp3"]
        self.djv.fingerprint_directory("tests", [".mp3"])
        self.assertEqual(len(list_dir), self.djv.db.get_num_songs())

    def test_fingerprint_1_file_10secs(self):
        self.djv.limit = 10
        self.djv.fingerprint_file("tests/test1.mp3")
        # should be the only fingerprinted file
        self.assertEqual(1, self.djv.db.get_num_songs())
        # fingerprinting the first 10 secs of this test file,
        # shouldn't get more than 3000 hashes.
        self.assertEqual(2554, self.djv.db.get_num_fingerprints())

    def test_recognize_1_file(self):
        self.djv.fingerprint_file("tests/test1.mp3")
        self.djv.fingerprint_file("tests/test2.mp3")
        song = self.djv.recognize(FileRecognizer, "tests/test2.mp3")
        self.assertEqual(song["song_name"], "tests/test2.mp3")
コード例 #8
0
def upload_file():
    if request.method == 'POST':
        file = request.files['file']
        brand = request.form['brand']
        offertitle = request.form['offertitle']
        offercontent = request.form['offercontent']
        image = request.files['offerimage']
        offerlink = request.form['offerlink']

        if file and allowed_file(file.filename) and image and allowed_file(
                image.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            # Can also rename the uploaded file if you want
            #os.rename(UPLOAD_FOLDER + filename, UPLOAD_FOLDER+'niloofar.jpg')
            FILEPATH = UPLOAD_FOLDER + filename

            imagename = secure_filename(image.filename)
            image.save(
                os.path.join(app.config['UPLOAD_FOLDER'] + "images/",
                             imagename))

            imagepath = UPLOAD_FOLDER + "images/" + imagename

            #Initializing Dejavu object with config
            djv = Dejavu(config)

            #Insert clip and its fingerprint in DB
            sid = djv.fingerprint_file(FILEPATH)

            #Insert related AdContent to DB
            # Create db connection to add data
            db = mysql.connect()
            cursor = db.cursor()
            cursor.execute(
                "INSERT INTO adcontent (sid, brand, offertitle, offercontent, imagepath, offerlink) VALUES (%s,%s,%s,%s,%s,%s)",
                (sid, brand, offertitle, offercontent, imagepath, offerlink))
            db.commit()
            db.close()

            #Data object for html template
            data = {"sid": sid}

            print(
                "\nSuccessfully added clip and adcontent to DB and recorded Fingerprint!"
            )
            return render_template('upload.html', data=data)

    return render_template('upload.html')
コード例 #9
0
ファイル: app.py プロジェクト: visionarylab/Justice-Music
def fingerprint_audio():
    # check if the post request has the audio part
    if ('audio') not in request.files:
        data = {'message': 'Audio to fingerprint is missing.'}
        return jsonify(data), 400
    elif ('info') not in request.form:
        data = {'message': 'Info of file is missing'}
        return jsonify(data), 400
    else:
        print("bat dau xu ly file upload")
        audio = request.files["audio"]
        filename = request.form["info"]
        if audio.filename == "":
            data = {'message': 'Audio to fingerprint is missing.'}
            return jsonify(data), 400
        else:
            # Save file in a temporary location
            try:
                name, ext = os.path.splitext(audio.filename)
                print("Save file...")
                if ext not in ('.mp3'):
                    return {'message': 'File extension not allowed.'}
                audio.save(os.path.join(path2, str(filename) + ext))
            except Exception as ex:
                template = "An 1 exception of type {0} occurred. Arguments:\n{1!r}"
                message = template.format(type(ex).__name__, ex.args)
                data = {'message': message}
                return data

    # Create a Dejavu instance
            print("Create instance")
            djv = Dejavu(config)

            # Fingerprinting audio from a file
            try:
                print("recognize audio is starting")
                song = djv.fingerprint_file(
                    os.path.join(path2,
                                 str(filename) + ext))
                data = {'message': 'completed'}
                print(song)
                os.remove(os.path.join(path2, str(filename) + ext))
                return jsonify(data)
            except Exception as ex:
                template = "An 2 exception of type {0} occurred. Arguments:\n{1!r}"
                message = template.format(type(ex).__name__, ex.args)
                data = {'message': message}
                return data
    return Response(status=200)
コード例 #10
0
class Lilo():
    """
    The class for JamJar which will be used to identify video matches and add fingerprints to the database
    """
    def __init__(self, config, filename, video_id):
        """
        usage:
            fingerprinter = Lilo('/path/to/video/file','unique_video_id')
        """
        self.djv = Dejavu(config)
        self.filename = filename
        self.video_id = video_id

        # cache these after first fingerprint
        self.hashes = None

    def recognize_track(self):
        # Try to match the song to the existing database
        hashes, songs = self.djv.recognize(FileRecognizer, self.filename)

        self.hashes = hashes

        return songs

    def fingerprint_song(self):
        # Now let's add this song to the DB
        data = self.djv.fingerprint_file(self.filename,
                                         self.video_id,
                                         cached_hashes=self.hashes)
        return data

    def check_if_fingerprinted(self):
        video_hash = unique_hash(self.filename)
        # Set self.djv.songhashes_set
        fingerprinted_video_hashes = self.djv.get_fingerprinted_songs()
        return video_hash in self.djv.songhashes_set
コード例 #11
0
def main():
    # Set up our commang line arguments
    parser = argparse.ArgumentParser(
        description=
        "Take in a folder of video and/or audio files and find the alignment"
        "of them all.")
    parser.add_argument(
        "folder",
        type=str,
        help=
        "The folder containing your audio and video files, relative to the current directory."
    )
    args = parser.parse_args()

    # Our DB settings
    config = {
        "database": {
            "host": "127.0.0.1",
            "user": "******",
            "passwd": "root",
            "db": "dejavu"
        }
    }

    # Get the files in our folder
    dir = os.path.expanduser(args.folder)
    files = os.listdir(dir)

    # Set up our dejavu instance
    djv = Dejavu(config)

    # Generate our corpus name - we'll add this functionality later.
    corpus = dir.replace(" ", "")
    corpus = corpus.lower()

    # For now, let's just empty the DB before the experiment
    djv.db.empty()

    # Iterate through the files
    for filename in files:
        full_path = os.path.join(dir, filename)

        # For now we'll assume all the files are valid audio or video
        if (os.path.isfile(full_path)):

            print "Attempting to match {0}...".format(filename)

            # Try to match the song to the existing database
            songs = djv.recognize(FileRecognizer, full_path)

            if songs:
                for song in songs:
                    print song
            else:
                print "No matches found."

            print "Adding {0} to database...".format(filename)

            # Now let's add this song to the DB
            djv.fingerprint_file(full_path)

            print djv.db.get_num_fingerprints()
コード例 #12
0
ファイル: finger.py プロジェクト: enrique26/PS
#with open("dejavu.cnf.SAMPLE") as f:

#Directorio de firmas
audiopath= "/home/nego/Descargas/firma"
extension= ".mp3"
audio_paths = get_files_recursive(audiopath, extension)

#Obtener longitud de pistas
for path in audio_paths:
    print "Path %s" % path
    n = get_length_audio(path, extension)
    print "Length %s "%(n)
    config={
    "database": {
    "host": "127.0.0.1",
    "user": "******",
    "passwd": "ksilva",
    "db": "dejavu3"
    },
    "fingerprint_limit": [n]
    }
    # create a Dejavu instance
    djv = Dejavu(config)
    djv.fingerprint_file(path)

#djv.fingerprint_directory(audiopath, [extension])
#Comandos

#print len(sys.argv)
#print str(sys.arv)
コード例 #13
0
ファイル: fingerprint_file.py プロジェクト: pguridi/dejavu
# Database URI examples:
# mysql: 'mysql+mysqldb://scott:tiger@localhost/foo'
# postgresql: 'postgresql://*****:*****@localhost/mydatabase'
# sqlite: 'sqlite:///foo.db'
# in memory sqlite:  'sqlite://'

config = {
    "database_backend" : "orm",
    "database_uri": "sqlite:///fingerprints.sqlite",
    "fingerprint_limit" : 10,
}

# previous backend can still be used:
# config = {
#     "database_backend" : "plain",
#     "database": {
#         "host": "127.0.0.1",
#         "user": "",
#         "passwd": "",
#         "db": "",
#     },
#     "fingerprint_limit" : 10,
# }

# create a Dejavu instance
djv = Dejavu(config)

# Fingerprint a file
djv.fingerprint_file("tests/test1.mp3")
コード例 #14
0
import warnings
import json
import sys
warnings.filterwarnings("ignore")

from dejavu import Dejavu
from dejavu.recognize import FileRecognizer, MicrophoneRecognizer

# load config from a JSON file (or anything outputting a python dictionary)
with open("/home/sarv/dejavu/dejavu.cnf.SAMPLE") as f:
    config = json.load(f)

print "parametros..."
for arg in sys.argv:
    print arg

archivo_mp3 = sys.argv[1]
archivo_destino = sys.argv[2]
IDVersion = sys.argv[3]
print "Procesaremos " + archivo_mp3 + " y las huellas quedaran en " + archivo_destino

djv = Dejavu(config)
djv.fingerprint_file(archivo_mp3, archivo_destino, IDVersion)
コード例 #15
0
ファイル: firmarDejavu.py プロジェクト: enrique26/PS
for x in original_file:
	limittime=get_length_audio(x,'.mp3')
	print limittime
	config = {
	"database": {
	"host": "127.0.0.1",
	"user": "******",
	"passwd": "ksilva", 
	"db": "dejavu"
	},
	"database_type" : "mysql",
	"fingerprint_limit":limittime
	}
	djv = Dejavu(config)
	print 'x'+x
	djv.fingerprint_file(x)

# 
# if __name__=__main__:
# 	if len(sys.argv)<4:



# if __name__ == '__main__': 
#     if len(sys.argv) != 3: 
#         print "La cantidad de argumentos ingresada no es correcta" 
#     file = sys.argv[1] 
#     action = sys.argv[2] 
#     if action == '-c': 
#         print check(file) 
#     elif action == '-h': 
コード例 #16
0
ファイル: dejavu.py プロジェクト: jaisler718/dejavu
            directory = args.fingerprint[0]
            extension = args.fingerprint[1]
            print(
                "Fingerprinting all .%s files in the %s directory" %
                (extension, directory)
            )
            djv.fingerprint_directory(directory, ["." + extension], 4)

        elif len(args.fingerprint) == 1:
            filepath = args.fingerprint[0]
            if os.path.isdir(filepath):
                print(
                    "Please specify an extension if you'd like to fingerprint a directory!"
                )
                sys.exit(1)
            djv.fingerprint_file(filepath)

    elif args.recognize:
        # Recognize audio source
        song = None
        source = args.recognize[0]
        opt_arg = args.recognize[1]

        if source in ('mic', 'microphone'):
            song = djv.recognize(MicrophoneRecognizer, seconds=opt_arg)
        elif source == 'file':
            song = djv.recognize(FileRecognizer, opt_arg)
        print(song)

    sys.exit(0)
コード例 #17
0
ファイル: testfingerprint.py プロジェクト: mkf/bothplay
            print intchar
        except ValueError:
            return False
        return intchar in range(0, 10)

    bylynum = False
    lista = []
    for char in list(text):
        if czycyfra(char):
            lista.append(char)
            bylynum = True
    assert bylynum
    return ''.join(lista)


q = raw_input('Daj do wyszukiwania:')
import soundcloud
scclient = soundcloud.Client(client_id='7b48f9baee211d4cc93fb489b0834f50')
search = scclient.get('/tracks', q=q, limit=3)
for track in search:
    print "Trying: ", track.title  #," — ",track.artist
    urlstr = str(track.stream_url)
    print urlstr
    urlnum = dajcyfry(urlstr)
    track = urllib2.urlopen(
        scclient.get(track.stream_url, allow_redirects=False).location)
    tf = open('/tmp/temp.music', 'w')
    tf.write(track.read())
    tf.close()
    djv.fingerprint_file('/tmp/temp.music', song_name='soundcloud-' + urlnum)
コード例 #18
0
ファイル: sarv-finger.py プロジェクト: farrocha/sarv-radio
import warnings
import json
import sys
warnings.filterwarnings("ignore")

from dejavu import Dejavu
from dejavu.recognize import FileRecognizer, MicrophoneRecognizer

#load config from a JSON file (or anything outputting a python dictionary)
#with open("/home/sarv/Donwloads/dejavu/dejavu.cnf.SAMPLE") as f:
#   config = json.load(f)

print "parametros..."
for arg in sys.argv:
    print arg

archivo_mp3 = sys.argv[1]
archivo_destino = sys.argv[2]

print "Procesaremos " + archivo_mp3 + " y las huellas quedaran en " + archivo_destino

djv = Dejavu()
djv.fingerprint_file(archivo_mp3, archivo_destino, 1000)
コード例 #19
0
ファイル: TSDownload.py プロジェクト: oencoding/ListenTV
    def downts_thread(url=None,save_dir=None,processInfo=None):

        # 获取频道名称
        channel_name = url.split('/')[-2]
        listfile_name = url.split('/')[-1]

        # 初始化提取信息
        processInfo = {channel_name: {'latest': '-', 'action': 'init process', 'info': 'init process'}}
        showProcessInfo(processInfo)

        # 新建文件夹
        save_dir = os.path.join(save_dir, channel_name)
        if not os.path.exists(save_dir):
            os.makedirs(save_dir)

        # list_file_name
        list_file_name = channel_name + "_" + listfile_name

        # list_file_full_path
        list_file_full_path = os.path.join(save_dir, list_file_name)
        pre_md5 = ""  # 文件校验码
        while 1:
            djv = Dejavu(config)
            # 保存ts流列表文件(cctv15_01.m3u8)
            processInfo[channel_name]['action'] = 'downloading'
            processInfo[channel_name]['info'] = 'downloading file:' + list_file_name
            showProcessInfo(processInfo)
            # save(url,list_file_full_path,True)
            download_to_file(url,list_file_full_path,True)
            #并计算校验码
            current_md5 = getFileMD5(list_file_full_path)  # 当前文件校验码

            # 对比是否有变化
            if current_md5==pre_md5:
                processInfo[channel_name]['action'] = 'thread sleeping'
                processInfo[channel_name]['info'] = 'there is no new media ,'+ channel_name+'-thread is sleeping'
                showProcessInfo(processInfo)
                #休息一下继续开始
                sleep(Config.TS_SLEEP);
                continue
            # 提取文件列表
            m3u8_obj = m3u8.load(url)
            # 间隔时间
            gap_time = m3u8_obj.target_duration

            base_URL = url[:url.rfind('/')+1]
            for index,file in enumerate(m3u8_obj.files):
                # 文件的网络路径
                file_url = base_URL + file
                # 获取开始时间
                ts_start_time = getTS_Format_Time(m3u8_obj.program_date_time, int(index * int(gap_time)))

                # 得到完整文件名
                file_temp_name = channel_name+"_"+ts_start_time+'.ts'
                file_full_path = os.path.join(save_dir,file_temp_name)


                song_name = os.path.splitext(os.path.basename(file_temp_name))[0]
                if not djv.isSongFingerPrinted(song_name):

                    #下载该文件
                    processInfo[channel_name]['action'] = 'downloading'
                    processInfo[channel_name]['info'] = 'downloading file:' + file_temp_name
                    showProcessInfo(processInfo)
                    download_to_file(file_url,file_full_path,False)

                    # 调用指纹提取程序提取指纹
                    processInfo[channel_name]['action'] = 'fingerprinting'
                    processInfo[channel_name]['info'] = 'fingerpinting file:' + file_temp_name
                    showProcessInfo(processInfo)
                    djv.fingerprint_file(file_full_path)
                else:
                    processInfo[channel_name]['action'] = 'skip fingerprinted'
                    processInfo[channel_name]['info'] = file_temp_name + 'has fingerprinted'
                    showProcessInfo(processInfo)

                # 更新信息
                processInfo[channel_name]['action'] = 'update-info'
                processInfo[channel_name]['info'] = channel_name+' has updated to ' + ts_start_time
                processInfo[channel_name]['latest'] = ts_start_time
                showProcessInfo(processInfo)
                # 清理文件
                processInfo[channel_name]['action'] = 'delete ts file'
                processInfo[channel_name]['info'] = 'deleting file:' + file_temp_name
                showProcessInfo(processInfo)
                if os.path.exists(file_full_path):
                    os.remove(file_full_path)

                # 提取完成更新文件校验码
                pre_md5 = current_md5
                # 是否需要清理历史数据

            # 休息一下继续开始
            processInfo[channel_name]['action'] = 'thread sleeping'
            processInfo[channel_name]['info'] = 'playlist has been stored,' + channel_name + '-thread is sleeping'
            showProcessInfo(processInfo)
            if os.path.exists(list_file_full_path):
                os.remove(list_file_full_path)
            sleep(Config.TS_SLEEP)
コード例 #20
0
    def run(self):
        dejavu.shared.UITEXTLOGGER = self.updated
        dejavu.shared.DATABASE_FILE = self.outputFilePath

        lpf = self.spinBox_4.value()
        hpf = self.spinBox_5.value()

        #        self.updated.emit("lpf:" + str(lpf) + ", hpf:" + str(hpf))

        af = ""

        if lpf != 0 or hpf != 0:
            af = "-af "
            if lpf != 0:
                af += ("lowpass="******",lowpass="******",lowpass="******",lowpass="******","
                af += ("highpass="******",highpass="******",highpass="******",highpass="******" "

        cmd48k = shlex.split("./ffmpeg -i " +
                             self.inputFilePath.replace(" ", "\\ ") +
                             " -ar 48000 " + af +
                             "-c:a pcm_s16le temp48k.wav -y")
        cmd44k = shlex.split("./ffmpeg -i " +
                             self.inputFilePath.replace(" ", "\\ ") +
                             " -ar 44100 " + af +
                             "-c:a pcm_s16le temp44k.wav -y")
        cmd16k = shlex.split("./ffmpeg -i " +
                             self.inputFilePath.replace(" ", "\\ ") +
                             " -ar 16000 " + af +
                             "-c:a pcm_s16le temp16k.wav -y")
        cmd8k = shlex.split("./ffmpeg -i " +
                            self.inputFilePath.replace(" ", "\\ ") +
                            " -ar 8000 " + af + "-c:a pcm_s16le temp8k.wav -y")
        #        cmd = shlex.split("./ffmpeg -i " + self.inputFilePath + " -af \"pan=2.1|c0=c0|c1=c1|c2=c2\" temp.wav -y")
        #        command = "-i " + self.inputFilePath + " -af \"pan=2.1c0|c1=c1|c2=c2\" temp.wav"

        #        self.updated.emit("./ffmpeg -i " + self.inputFilePath.replace(" ", "\\ ") + " -ar 8000 " + af + "-c:a pcm_s16le temp8k.wav -y")

        #        # do some functionality
        djv = Dejavu({})
        #        djv.uitextappend = self.updated
        #clear DB
        djv.empty_db()

        totalProcesses = 0
        if self.checkBox.isChecked():
            totalProcesses += 1
        if self.checkBox_2.isChecked():
            totalProcesses += 1
        if self.checkBox_3.isChecked():
            totalProcesses += 1
        if self.checkBox_4.isChecked():
            totalProcesses += 1

        totalProcessedPercentage = 0

        self.updatedWithPercentage.emit(
            "Start converting " + self.inputFilePath, totalProcessedPercentage)

        #48KHz
        if self.checkBox.isChecked():
            self.updated.emit("Converting " + self.inputFilePath +
                              " to 48KHz 16bit PCM")

            try:
                subprocess.check_output(cmd48k)
            except subprocess.CalledProcessError as e:
                self.updated.emit("Error, " + e.output)
                self.pushButton.setEnabled(True)
                return

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished converting 48KHz for " + self.inputFilePath,
                totalProcessedPercentage)

            djv.fingerprint_file("temp48k.wav")

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished finger print generation for 48KHz for " +
                self.inputFilePath, totalProcessedPercentage)

        #44.1KHz
        if self.checkBox_2.isChecked():
            self.updated.emit("Converting " + self.inputFilePath +
                              " to 44.1KHz 16bit PCM")

            try:
                subprocess.check_output(cmd44k)
            except subprocess.CalledProcessError as e:
                self.updated.emit("Error, " + e.output)
                self.pushButton.setEnabled(True)
                return

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished converting 44.1KHz for " + self.inputFilePath,
                totalProcessedPercentage)

            djv.fingerprint_file("temp44k.wav")

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished finger print generation for 44.1KHz for " +
                self.inputFilePath, totalProcessedPercentage)

        #16KHz
        if self.checkBox_3.isChecked():
            self.updated.emit("Converting " + self.inputFilePath +
                              " to 16KHz 16bit PCM")

            try:
                subprocess.check_output(cmd16k)
            except subprocess.CalledProcessError as e:
                self.updated.emit("Error, " + e.output)
                self.pushButton.setEnabled(True)
                return

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished converting 16KHz for " + self.inputFilePath,
                totalProcessedPercentage)

            djv.fingerprint_file("temp16k.wav")

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished finger print generation for 16KHz for " +
                self.inputFilePath, totalProcessedPercentage)

        #8KHz
        if self.checkBox_4.isChecked():
            self.updated.emit("Converting " + self.inputFilePath +
                              " to 8KHz 16bit PCM")

            try:
                subprocess.check_output(cmd8k)
            except subprocess.CalledProcessError as e:
                self.updated.emit("Error, " + e.output)
                self.pushButton.setEnabled(True)
                return

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished converting 8KHz for " + self.inputFilePath,
                totalProcessedPercentage)

            djv.fingerprint_file("temp8k.wav")

            totalProcessedPercentage += (50 / totalProcesses)
            self.updatedWithPercentage.emit(
                "Finished finger print generation for 8KHz for " +
                self.inputFilePath, totalProcessedPercentage)

        totalProcessedPercentage = 100
        self.updatedWithPercentage.emit(
            "Finished finger prints generation for " + self.inputFilePath,
            totalProcessedPercentage)

        self.pushButton.setEnabled(True)
コード例 #21
0
            common_proportion.append(
                sum(common) / (len(fingerprints1) + len(fingerprints2) + 1))

        similarity = np.mean(common_proportion)

        return similarity


if __name__ == '__main__':
    filename1, filename2 = sys.argv[1:]

    extension = filename1.split('.')[-1]

    file1, file2 = list(
        map(lambda s: s.split('/')[-1][:-(len(extension) + 1)],
            [filename1, filename2]))

    djv = Dejavu(config)

    #djv.fingerprint_directory('data', [extension])

    djv.fingerprint_file(f'./data/{file1}.{extension}')
    djv.fingerprint_file(f'./data/{file2}.{extension}')

    rec1, rec2 = Recording(file1), Recording(file2)

    rec1.get_fingerprints(aggregate=True)
    rec2.get_fingerprints(aggregate=True)

    similarity = rec1.compare(rec2)