コード例 #1
0
ファイル: testing.py プロジェクト: letti0430/Course-Projects
	def test_shazam(self):
		"""test the shazam with 10 random signatures and one snippet"""

		Shz = Shazam()
		self.assertEqual(Shz.width, 10)
		self.assertEqual(Shz.shift, 1)
		self.assertEqual(Shz.window_type, 'hann')
		self.assertTrue(Shz.verbose)
	
		# test shazam.insert_songs()
		directory = './'

		for f in os.listdir(directory):
			if re.search('snippet.wav', f) or re.search('3.wav', f):
				os.remove(os.path.join(directory, f))

		self.assertTrue(Shz.insert_songs(directory))

		# test shazam.identify() with in-sample snippets
		getSnippet('noise1.wav', 'noise1_snippet.wav', 15)
		getSnippet('noise2.wav', 'noise2_snippet.wav', 12)

		self.assertEqual(Shz.identify('noise1_snippet.wav', 1, 0.0001)[0][0], (0, 'noise1.wav'))	# id and title of noise1.wav
		self.assertEqual(Shz.identify('noise1_snippet.wav', 1, 0.0001)[1], [0.])	# distances from noise1.wav

		self.assertEqual(Shz.identify('noise2_snippet.wav', 1, 0.0001)[0][0], (1, 'noise2.wav'))	# id and title of noise1.wav
		self.assertEqual(Shz.identify('noise2_snippet.wav', 1, 0.0001)[1], [0.])	# distances from noise2.wav

		# test shazam.identify() with out-of-sample snippets
		writeWav('noise3.wav', 55)
		getSnippet('noise3.wav', 'noise3_snippet.wav', 16)
		self.assertIsNone(Shz.identify('noise3_snippet.wav', 1, 0.0001))	# noise3_snippet doesn't match any song in the library

		# test shazam.list()
		self.assertTrue((0, 'noise1.wav') in Shz.list())
		self.assertTrue((1, 'noise2.wav') in Shz.list())
		self.assertFalse((2, 'noise3.wav') in Shz.list())
コード例 #2
0
def process_file(filename, sampling_rate):
    vidcap = cv2.VideoCapture(filename)
    mShazam = Shazam()

    success, image = vidcap.read()
    skip = 0
    while vidcap.isOpened():
        if skip % sampling_rate == 0:
            # timestamp = vidcap.get(cv2.cv.CV_CAP_PROP_POS_MSEC)
            timestamp = vidcap.get(cv2.CAP_PROP_POS_MSEC)

            timestamp = str(datetime.timedelta(milliseconds=timestamp))
            print("Processing Image at {}".format(timestamp))
            mShazam.ProcessImage(image, timestamp)

        skip += 1
        success, image = vidcap.read()
        if not success:
            break
    vidcap.release()
    mShazam.printResults()
    mShazam.saveResults()
コード例 #3
0
current_dir = os.path.dirname(os.path.abspath(__file__))
music_dir = current_dir + "/music"
music_list = []

if os.path.isfile(current_dir + "/database.sqlite"):
	os.remove(current_dir + "/database.sqlite")

database = Database('database.sqlite')
database.create()

for file in os.listdir(music_dir):
	if file.endswith(".mp3"):
		music_list.append(file)
print("%d tracks in database" % len(music_list))

shazam = Shazam(92)

total_duree = 0
total_keys = 0

for track in music_list:
	track_title = track[:-4]
	track_id = database.addTrack(track_title)
	print("=> Processing %s, id: %d" % (track_title, track_id))
	wavdata = sound.read(music_dir + "/" + track)

	total_duree += wavdata.getnframes()/float(wavdata.getframerate())

	# Shazam method
	keys = shazam.processTrack(wavdata,)
コード例 #4
0
ファイル: exp1.py プロジェクト: drwiiche/audiofingerprint
database = []
database.append(Database('database1.sqlite'))
database.append(Database('database2.sqlite'))
database.append(Database('database3.sqlite'))
database.append(Database('database4.sqlite'))
database.append(Database('database5.sqlite'))

# Music library
current_dir = os.path.dirname(os.path.abspath(__file__))
music_dir = current_dir + "/music_modif1"
music_list = []
for file in os.listdir(music_dir):
	if file.endswith(".mp3"):
		music_list.append(file)

shaz = Shazam(100)

duration = 2

# pour chaque musique de la bdd on prend 3 extraits
extracts_k = [1./4, 2./4, 3./4]

counter = [0, 0, 0, 0, 0]

for track in music_list:
	print track
	wavdata = sound.read(music_dir + "/" + track)
	lenght = wavdata.getnframes()
	fs = wavdata.getframerate()

	for coef in extracts_k:
コード例 #5
0
current_dir = os.path.dirname(os.path.abspath(__file__))
music_dir = current_dir + "/music"
music_list = []

if os.path.isfile(current_dir + "/database.sqlite"):
    os.remove(current_dir + "/database.sqlite")

database = Database('database.sqlite')
database.create()

for file in os.listdir(music_dir):
    if file.endswith(".mp3"):
        music_list.append(file)
print("%d tracks in database" % len(music_list))

shazam = Shazam(92)

total_duree = 0
total_keys = 0

for track in music_list:
    track_title = track[:-4]
    track_id = database.addTrack(track_title)
    print("=> Processing %s, id: %d" % (track_title, track_id))
    wavdata = sound.read(music_dir + "/" + track)

    total_duree += wavdata.getnframes() / float(wavdata.getframerate())

    # Shazam method
    keys = shazam.processTrack(wavdata, )