Exemplo n.º 1
0
	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())