本文整理汇总了Python中dejavu.Dejavu.fingerprint_directory方法的典型用法代码示例。如果您正苦于以下问题:Python Dejavu.fingerprint_directory方法的具体用法?Python Dejavu.fingerprint_directory怎么用?Python Dejavu.fingerprint_directory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dejavu.Dejavu
的用法示例。
在下文中一共展示了Dejavu.fingerprint_directory方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DejavuPlainDBTestCases
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
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")
示例2: __main1
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
def __main1():
# create a Dejavu instance
djv = Dejavu(config)
# Fingerprint all the mp3's in the directory we give it
djv.fingerprint_directory("seed", [".wav"])
#print djv.db.get_num_fingerprints()
#print "----------------------------17---------"
fp = open('result'+'.dat','w+')
# Recognize audio from a file
prefix ='mp3'
start = time.clock()
totalNumSong = 0
rightNum = 0
missNum = 0
# for root, dirs, files in os.walk(prefix):
# for dirx in dirs:
# fp.write('%s\n'%dirx)
print "-------------------------------------"
fp.write("--Recognizing-----------------------------------\n")
for filename in glob.glob(prefix+'/*.wav'):
#print filename
# filenamex= os.path.basename(filename).replace('.wav','')
song = djv.recognize(FileRecognizer, filename)
totalNumSong += 1
if not song is None:
txtBuffer = "%s; %s"%(filename, filter(str.isalpha, song['song_name']))
if filename[5:7] in filter(str.isalpha, song['song_name']):
rightNum += 1
else:
txtBuffer = "%s; None"%(filename)
missNum +=1
fp.write(txtBuffer+'\n')
print txtBuffer
end=time.clock()
fp.write("--Performance-----------------------------------\n")
fp.write("Prediction time duration: %f seconds\n"%(end-start))
fp.write("Total number of predicted songs: %d \n"%totalNumSong)
fp.write("Prediction duration per song: %f seconds\n"%(float(end-start)/float(totalNumSong)))
fp.write("Correct rate: %f %% \n"%(float(rightNum)/float(totalNumSong)*100))
fp.write("No result rate: %f %%\n"%(float(missNum)/float(totalNumSong)*100))
fp.close()
示例3: scan_directory
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
def scan_directory(directory, extension):
if extension.endswith('.mp3'):
print('scanning directory...'.format(directory))
djv = Dejavu(config)
djv.fingerprint_directory(directory, [extension], 3) # 3 is processes
elif extension.endswith('.m4a'):
print('scanning directory...'.format(directory))
djv = Dejavu(config)
djv.fingerprint_directory(directory, [extension], 3) # 3 is processes
else:
print("file format '{0}' not coded yet".format(extension))
# recognise mp3
song = djv.recognize(FileRecognizer, "/home/jonas/Downloads/dejavu/CC.mp3")
print("found song '%s\n'" % song)
示例4: recognize
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
def recognize(self, samples_patch, downloads_patch, file_format):
self.samples_patch = samples_patch
self.downloads_patch = downloads_patch
self.file_format = file_format
self.var_check()
warnings.filterwarnings('ignore')
with open('dejavu.conf') as f:
config = json.load(f)
djv = Dejavu(config)
# -= updating audio fingerprint base =-
print ('%s > Updating fingerprints...' % datetime.datetime.now())
djv.fingerprint_directory(self.samples_patch, [self.file_format])
# -= recognizing downloaded files =-
print ('%s > Recognizing files...' % datetime.datetime.now())
for i in range(len(names)):
file = self.downloads_patch + '/' + names[i]
print ('%s > Now recognizing: %s' % (datetime.datetime.now(), names[i]))
song = djv.recognize(FileRecognizer, file)
recognized.append(song['song_name'])
print ('%s > From file we recognized: %s' % (datetime.datetime.now(), recognized[i]))
print ('%s > Finished!' % datetime.datetime.now())
示例5: __main
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
def __main(action):
# create a Dejavu instance
djv = Dejavu(config)
# Fingerprint all the mp3's in the directory we give it
djv.fingerprint_directory("mp3", [".wav"])
#print djv.db.get_num_fingerprints()
#print "----------------------------17---------"
fp = open(action+'.dat','w+')
# Recognize audio from a file
#prefix ='..\sdl\%s'%action
prefix ='mp3\%s'%action
files = prefix +'\*.mp3'
totalNumSong = 0
start = time.clock()
for filename in glob.glob(files):
#print filename
filenamex= filename.split('\\')[-1]
filenamex=filenamex[7:-4]
song = djv.recognize(FileRecognizer, filename)
totalNumSong += 1
if not song is None:
txtBuffer = "%s;%s"%(filenamex, song['song_name'])
else:
txtBuffer = "%s;None"%(filenamex)
fp.write(txtBuffer+'\n')
print txtBuffer
end=time.clock()
fp.write("----------------------------60---------\n")
fp.write("Prediction time duration: %f \n"%(end-start))
fp.write("Total number of predicted songs: %d \n"%totalNumSong)
fp.write("Prediction duration for per song: %f \n"%(float(end-start)/float(totalNumSong)))
fp.close()
示例6: file
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
import warnings
import json
import os
import time
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("dejavu.cnf") as f:
config = json.load(f)
if __name__ == '__main__':
# create a Dejavu instance
config["database"]["passwd"] = os.environ.get(config["database"]["passwd"])
config["database"]["db"] = os.environ.get(config["database"]["db"])
djv = ""
for i in range(0, 20):
try:
djv = Dejavu(config)
break
except Exception,e:
print e
time.sleep(1)
# Fingerprint all the mp3's in the directory we give it
djv.fingerprint_directory("scripts", [".wav"])
示例7: Dejavu
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
__author__ = 'Mark'
from dejavu import Dejavu
if __name__ == '__main__':
config = {
"database": {
"host": "127.0.0.1",
"user": "root",
"passwd": "root",
"db": "dejavu"
}
}
djv = Dejavu(config)
djv.fingerprint_directory("../../../Desktop/media/dejavu",[".wav",".mp3",".mov",".MOV"])
print djv.db.get_num_fingerprints()
示例8: file
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
"passwd": "pass",
"db": "dejavu"
}
}
# load config from a JSON file (or anything outputting a python dictionary)
#with open("dejavu.cnf.SAMPLE") as f:
# config = json.load(f)
if __name__ == '__main__':
# create a Dejavu instance
djv = Dejavu(config)
# Fingerprint all the mp3's in the directory we give it
djv.fingerprint_directory("mp3", [".mp3"])
# Recognize audio from a file
song = djv.recognize(FileRecognizer, "mp3/Sean-Fournier--Falling-For-You.mp3")
print "From file we recognized: %s\n" % song
# Or recognize audio from your microphone for `secs` seconds
secs = 5
song = djv.recognize(MicrophoneRecognizer, seconds=secs)
if song is None:
print "Nothing recognized -- did you play the song out loud so your mic could hear it? :)"
else:
print "From mic with %d seconds we recognized: %s\n" % (secs, song)
# Or use a recognizer without the shortcut, in anyway you would like
recognizer = FileRecognizer(djv)
示例9: file
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
import sys
sys.path.insert(0, './dejavu')
from dejavu import Dejavu
import warnings
import json
warnings.filterwarnings("ignore")
# load config from a JSON file (or anything outputting a python dictionary)
with open("dejavu.cnf") as f:
config = json.load(f)
# create a Dejavu instance
djv = Dejavu(config)
# Fingerprint all the mp3's in the directory we give it
djv.fingerprint_directory("assets", [".mp3"])
# Recognize audio from a file
#from dejavu.recognize import FileRecognizer
#song = djv.recognize(FileRecognizer, "mp3/beware.mp3")
# Or recognize audio from your microphone for 10 seconds
#from dejavu.recognize import MicrophoneRecognizer
#song = djv.recognize(MicrophoneRecognizer, seconds=2)
# Or use a recognizer without the shortcut, in anyway you would like
#from dejavu.recognize import FileRecognizer
#recognizer = FileRecognizer(djv)
#song = recognizer.recognize_file("mp3/sail.mp3")
示例10: copy_all_wavs_to_dir
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
import sys, os, shutil
sys.path.insert(1, "../dejavu/")
from dejavu import Dejavu
def copy_all_wavs_to_dir(olddir="./songs", newdir="./fp_wavs"):
for yt_id in filter(lambda x: x[0] != ".", os.listdir(olddir)):
fp = os.path.join(olddir, yt_id, "song.wav")
new_fp = os.path.join(newdir, yt_id + ".wav")
print fp, new_fp
shutil.copy(fp, new_fp)
if "copy" in sys.argv:
copy_all_wavs_to_dir()
if "train" in sys.argv:
config = {"database": {"host": "127.0.0.1", "user": "root", "passwd": "loganlogan", "db": "dejavu"}}
djv = Dejavu(config)
djv.fingerprint_directory("./fp_wavs", [".wav"], 5)
示例11: Generate
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
class Generate(object):
"""
Given a labelled output file and the corresponding video tags, extracts the commercial segments and fingerprints them.
"""
def __init__(self, labels_fname, video_name):
label_file_type = mimetypes.guess_type(labels_fname)[0]
video_file_type = mimetypes.guess_type(video_name)[0]
if label_file_type[:3] != "tex":
#The file is not a labels file
print "Incorrect label file"
raise Exception(INCORRECT_LABEL_FILE_ERROR)
if video_file_type[:3] != "vid":
#The file is not a video file
print "Incorrect video file"
raise Exception(INCORRECT_VIDEO_FILE_ERROR)
self.labels = LabelsFile(labels_fname)
self.video_name = video_name
self.djv = Dejavu(CONFIG)
self.db_content = []
def build_db(self, aud_ext=".wav", vid_ext=".mpg"):
"""
Build a sql db with the commercials
"""
#This returns the entire contents of the file, more about structure of return type in fileHandler.py
labels = self.labels.read_lables()
#Number of files in the directory + 1
filename = len(os.listdir(DB_AUDIO)) + 1
#Try reading contents from csv file, if it already exists
try:
#Already exists
#We open and read the content first
with open(DBNAME) as f:
lines = f.readlines()
self.db_content = [line.split(',')[1] for line in lines[1:]] #Only names of commercials
f = open(DBNAME, "a")
except:
#Creating for the first time
print "File does not exist so creating..."
f = open(DBNAME, "w")
f.write("name, duration, path\n")
for data in labels:
#Extracting based on structure of return type
start = data[0]
end = data[1]
name = data[2]
if self.db_content != [] and (name in self.db_content):
print "Already Fingerprinted"
continue
duration = timeFunc.get_delta_string(start, end)
#Create a file in the db folder, audio and video are stored seperately
ffmpeg.create_video(start, duration, self.video_name, DB_VIDEO + str(filename) + vid_ext)
ffmpeg.create_audio(DB_VIDEO + str(filename) + vid_ext, DB_AUDIO + str(filename) + aud_ext)
#Create a corresponding entry in the csv file
s = ",".join([name, duration])
s = s + "," + DB_VIDEO + str(filename) + vid_ext + "\n" #Check verified to be true since human tagged
f.write(s)
filename += 1
def fingerprint_db(self, aud_ext=".wav", no_proc=1):
#This fingerprints the entire directory
self.djv.fingerprint_directory(DB_AUDIO, [aud_ext])
def clean_db(self, aud_ext=".wav", vid_ext=".mpg"):
choice = raw_input("Are you sure you want to remove all commercials in the database? (yes/no)")
if choice == "yes":
#Clear the mysql db
self.djv.clear_data()
print "Cleaning database.."
#Now we remove files from db/audio and db/video
filename = len(os.listdir(DB_AUDIO)) + 1
for i in range(1, filename):
try:
os.remove(DB_AUDIO + str(i) + aud_ext)
os.remove(DB_VIDEO + str(i) + vid_ext)
except:
print "File already removed, or you don't have permission"
os.remove(DBNAME)
print "Database is empty"
#.........这里部分代码省略.........
示例12: open
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
import sys
import os
import MySQLdb
import MySQLdb.cursors
from dejavu import Dejavu
warnings.filterwarnings("ignore")
db = os.path.abspath("python/database.json")
config = {}
try:
with open(db) as f:
config['database'] = json.load(f)
con = MySQLdb.connect(
config.get('database').get('host'),
config.get('database').get('user'),
config.get('database').get('passwd'),
config.get('database').get('db'),
cursorclass=MySQLdb.cursors.DictCursor
)
cur = con.cursor()
cur.execute("SELECT * FROM `configurations` ORDER BY id DESC")
config['fingerprint'] = cur.fetchone()
if __name__ == '__main__':
djv = Dejavu(config)
djv.fingerprint_directory()
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
示例13: Dejavu
# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import fingerprint_directory [as 别名]
# database uris examples:
# mysql: 'mysql+mysqldb://scott:[email protected]/foo'
# postgresql: 'postgresql://scott:[email protected]/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_directory("tests", [".mp3"])