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


Python Dejavu.recognize方法代码示例

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


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

示例1: msearch

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
    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,代码行数:31,代码来源:m_server.py

示例2: DejavuPlainDBTestCases

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [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")
开发者ID:pguridi,项目名称:dejavu,代码行数:36,代码来源:tests_dejavu.py

示例3: Lilo

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
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,代码行数:37,代码来源:__init__.py

示例4: recognise_microphone

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
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,代码行数:10,代码来源:audio_fingerprinting.py

示例5: main

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
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,代码行数:60,代码来源:Align_Folder.py

示例6: dejavu

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
 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,代码行数:11,代码来源:search.py

示例7: __main1

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [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()
开发者ID:heraldia,项目名称:ADLR-Python,代码行数:51,代码来源:example.py

示例8: scan_directory

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [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)
开发者ID:JONAS402,项目名称:Pibot,代码行数:17,代码来源:audio_fingerprinting.py

示例9: recognize

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [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())
开发者ID:STwilight,项目名称:DRM-Audio,代码行数:25,代码来源:URLSpider.py

示例10: __main

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [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()
开发者ID:heraldia,项目名称:ADLR-Python,代码行数:38,代码来源:example.py

示例11: file

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
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("mp3", [".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")
开发者ID:ErikKierstead,项目名称:dejavu,代码行数:28,代码来源:example.py

示例12: Dejavu

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
# create a Dejavu instance
djv = Dejavu(config)

# Recognize audio from a file
from dejavu.recognize import FileRecognizer
#filename = "20141106_204003"
filename = sys.argv[1]
import globP
if globP._XDEBUG == True:
    import pdb
    pdb.set_trace()
#txtFileName = 'songList.txt'
#prefix ='./mp3t/Living_'
prefix ='./mp3t/'
suffix ='.mp3'
fullFilename=prefix+filename+suffix
#print fullFilename
if os.path.exists(fullFilename):
    song = djv.recognize(FileRecognizer, fullFilename)
    if not song is None:
        print "36 --  %s \t %s "%(filename, song['song_name'] )
    else:
        print "38 --  %s \t None "%(filename)

print song

print "----------------------------39-- dbInfor()-------"
from dbRefresh import dbInfor
dbInfor()
开发者ID:heraldia,项目名称:ADLR-Python,代码行数:31,代码来源:singlePrediction.py

示例13: Dejavu

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
# 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)

# Recognize audio from a file
song = djv.recognize(FileRecognizer, "tests/test1.mp3")
print song
开发者ID:pguridi,项目名称:dejavu,代码行数:32,代码来源:recognize_file.py

示例14: songListener

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
class songListener(threading.Thread):
    """This class listens for songs in a background thread using the Dejavu audio 
    fingerprinter. When it hears a song it sets global flags"""

    global chickenDance
    global robotDance
    global discoDance
    global egyptianDance
    global ymcaDance
    global danceStop

    def __init__(self, config):
        threading.Thread.__init__(self)
        #Initialize the dejavu listener
        self.djv = Dejavu(config) 
        self.running = True

    def run(self):
        global chickenDance
        global robotDance
        global discoDance
        global egyptianDance
        global ymcaDance
        global danceStop
        #do the listening
        while(self.running):

            response = self.djv.recognize(MicrophoneRecognizer, seconds=5)
            if(response == None):
                continue

            if(response["confidence"] > 30 and response["song_name"] == "chickenDance") and (not (robotDance or discoDance or egyptianDance or ymcaDance)):
                print "Found " + response["song_name"]
                print "Confidence: " + str(response["confidence"]) + " units"
                chickenDance = True
                danceStop = False
                

            elif(response["confidence"] > 30 and response["song_name"] == "technologic") and (not (chickenDance or discoDance or egyptianDance or ymcaDance)):
                print "Found " + response["song_name"]
                print "Confidence: " + str(response["confidence"]) + " units"
                robotDance = True
                danceStop = False

            elif(response["confidence"] > 30 and response["song_name"] == "stayingAlive") and (not (chickenDance or robotDance or egyptianDance or ymcaDance)):
                print "Found " + response["song_name"]
                print "Confidence: " + str(response["confidence"]) + " units"
                discoDance = True
                danceStop = False

            elif(response["confidence"] > 30 and response["song_name"] == "walkLikeAnEgyptian") and (not (chickenDance or robotDance or discoDance or ymcaDance)):
                print "Found " + response["song_name"]
                print "Confidence: " + str(response["confidence"]) + " units"
                egyptianDance = True
                danceStop = False

            elif(response["confidence"] > 30 and response["song_name"] == "YMCA") and (not (chickenDance or robotDance or discoDance or egyptianDance)):
                print "Found " + response["song_name"]
                print "Confidence: " + str(response["confidence"]) + " units"
                ymcaDance = True
                danceStop = False

            else:
                chickenDance = False
                robotDance = False
                discoDance = False
                egyptianDance = False
                ymcaDance = False

    def stop(self):
        self.running = False
开发者ID:RyanYoung25,项目名称:dancingDemo,代码行数:73,代码来源:sound.py

示例15: Dejavu

# 需要导入模块: from dejavu import Dejavu [as 别名]
# 或者: from dejavu.Dejavu import recognize [as 别名]
__author__ = 'Mark'
from dejavu import Dejavu
from dejavu.recognize import MicrophoneRecognizer

if __name__ == '__main__':
    config = {
        "database": {
            "host": "127.0.0.1",
            "user": "root",
            "passwd": "root",
            "db": "dejavu"
        }
    }

    djv = Dejavu(config)

    song = djv.recognize(MicrophoneRecognizer, seconds=5) # Defaults to 10 seconds.

    print song
开发者ID:markkohdev,项目名称:AudioStitch,代码行数:21,代码来源:DejavuMicTest.py


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