当前位置: 首页>>代码示例>>Python>>正文


Python dejavu.Dejavu类代码示例

本文整理汇总了Python中dejavu.Dejavu的典型用法代码示例。如果您正苦于以下问题:Python Dejavu类的具体用法?Python Dejavu怎么用?Python Dejavu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Dejavu类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: msearch

    def msearch(self):
        types=('audio/wav','audio/mp3')
        for aud in self.request.files:
            print aud
            aud=self.request.files[aud]
            if len(aud)<1:
                return u'上传失败'
            _t=aud[0]['content_type']
            if _t not in types:
                return u'上传文件有误,请回去重新上传'
            print 
            fname=md5(aud[0]['filename']+str(time.time())).hexdigest()
            fname+='.wav'
            fname = os.path.join('temp', fname)
            # print type()
            with open(fname, 'wb') as f:
                f.write(aud[0]['body'])

        try:
            djv = Dejavu(config)
            print 'begint recognize...'
            song = djv.recognize(FileRecognizer, fname)
        except Exception as e:
            song = str(e)
        finally:
            # os.remove(fname)
            pass
        print 'recognize: ', song
        return song
开发者ID:Zephor5,项目名称:lovemic,代码行数:29,代码来源:m_server.py

示例2: 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
开发者ID:projectjamjar,项目名称:lilo,代码行数:35,代码来源:__init__.py

示例3: recognise_microphone

def recognise_microphone():
    djv = Dejavu(config)
    secs = 10
    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)
开发者ID:JONAS402,项目名称:Pibot,代码行数:8,代码来源:audio_fingerprinting.py

示例4: main

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": "root",
            "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()
开发者ID:markkohdev,项目名称:AudioStitch,代码行数:58,代码来源:Align_Folder.py

示例5: dejavu

 def dejavu(self, select_song):
     # config = {"database": {"host": "127.0.0.1", "user": "root", "passwd": "", "db": "dejavu"}}
     config = {"database": {"host": "10.66.31.157", "user": "root", "passwd": "662813", "db": "dejavu"}}
     djv = Dejavu(config)
     # djv.fingerprint_directory("mp3/Piano/", [".mp3"])
     # djv.fingerprint_directory("mp3/Violin/", [".mp3"])
     song = djv.recognize(FileRecognizer, select_song)
     # print(song)
     return song
开发者ID:andyli8500,项目名称:MICA,代码行数:9,代码来源:search.py

示例6: DejavuPlainDBTestCases

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")
开发者ID:pguridi,项目名称:dejavu,代码行数:34,代码来源:tests_dejavu.py

示例7: __main1

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()
开发者ID:heraldia,项目名称:ADLR-Python,代码行数:49,代码来源:example.py

示例8: __init__

    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
开发者ID:projectjamjar,项目名称:lilo,代码行数:11,代码来源:__init__.py

示例9: recognize

    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())
开发者ID:STwilight,项目名称:DRM-Audio,代码行数:23,代码来源:URLSpider.py

示例10: __main

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()
开发者ID:heraldia,项目名称:ADLR-Python,代码行数:36,代码来源:example.py

示例11: scan_directory

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)
开发者ID:JONAS402,项目名称:Pibot,代码行数:15,代码来源:audio_fingerprinting.py

示例12: __init__

 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 = []
开发者ID:EvanWeiner,项目名称:CommercialDetection,代码行数:19,代码来源:generate.py

示例13: __init__

 def __init__(self, video_name):
     
     """
        Takes the video name. Creates a Dejavu object.
        Also obtains the duration and number of frames in the video.
     """
     
     file_type = mimetypes.guess_type(video_name)[0]
     
     if file_type[:3] != "vid":#The file is not a video file
         print "No video file found"
         raise Exception(INCORRECT_VIDEO_FILE_ERROR)
     
     self.video_name = video_name
     self.djv = Dejavu(CONFIG)
     
     #We create the audio of the video given to us
     ffmpeg.create_audio(self.video_name, TEMP_AUDIO)
     self.frames, self.Fs, hash_val = decoder.read(TEMP_AUDIO)
     self.frames = self.frames[0] #Since we always create single channel audio
     self.duration = int(self.frames.shape[0] / (self.Fs*1.0)) #Duration of the entire video in seconds
开发者ID:EvanWeiner,项目名称:CommercialDetection,代码行数:21,代码来源:recognize.py

示例14: Dejavu

__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()
开发者ID:markkohdev,项目名称:AudioStitch,代码行数:19,代码来源:Make_Print_Database.py

示例15: file

        "-s",
        "--secs",
        help="how many seconds to fingerprint for recognition",
        type=int)

args = parser.parse_args()

# load config from a JSON file (or anything outputting a python dictionary)
config = {
    "database": {
        "host": "127.0.0.1",
        "user": "root",
        "passwd": "", 
        "db": "dejavu"
    }
}

if args.secs:
    config["fingerprint_limit"] = args.secs

if __name__ == '__main__':

        # create a Dejavu instance
        djv = Dejavu(config)

        # Recognize audio from a file
        print("start recognizing")
        with Timer("djv.recognize") as t:
            song = djv.recognize(FileRecognizer, args.file)
        print("From file we recognized: %s\n" % song)
开发者ID:snd,项目名称:dejavu,代码行数:30,代码来源:recognize.py


注:本文中的dejavu.Dejavu类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。