def test_loud(self): with bl_song("/tmp/test.mp3") as song: self.assertAlmostEqual(song["force"], 11.403019) # self.assertEqual(song.force_vector.tempo, 2.517007) # self.assertEqual(song.force_vector.amplitude, 0.107364) # self.assertEqual(song.force_vector.frequency, -1.432200) # self.assertEqual(song.force_vector.attack, 10.210849) self.assertEqual(song["channels"], 2) self.assertEqual(song["nSamples"], 25021440) self.assertEqual(song["sample_rate"], 44100) self.assertEqual(song["bitrate"], 198332) self.assertEqual(song["nb_bytes_per_sample"], 2) self.assertEqual(song["calm_or_loud"], BL_LOUD) self.assertEqual(song["duration"], 283) self.assertEqual(song["artist"], "David TMX") self.assertEqual(song["title"], "Lost in dreams") self.assertEqual(song["album"], "Renaissance") self.assertEqual(song["tracknumber"], "14") self.assertEqual(song["genre"], "(255)")
def analyze(url_lib, url_csv, self): if self.recursive: file_list = [ os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(url_lib)) for f in fn ] else: file_list = [ os.path.join(url_lib, f) for f in os.listdir(url_lib) if os.path.isfile(os.path.join(url_lib, f)) ] audio_files = [] for file_n in file_list: guess = mimetypes.guess_type(file_n)[0] if guess is not None and "audio" in guess: audio_files.append(file_n) if not audio_files: print("Please enter a valid directory containing audio files") self.goBtn.set_label("Go") return self.label_done.hide() self.progressBar.show() self.progressBar.set_ellipsize(Pango.EllipsizeMode.MIDDLE) self.progressBar.set_show_text(True) with open(url_csv, "w") as csvfile: library_writer = csv.writer(csvfile, delimiter='|', quotechar="'", quoting=csv.QUOTE_MINIMAL) for i, file_n in enumerate(audio_files): if self.e.isSet(): self.e.clear() break with bliss.bl_song(file_n) as song: # Test if the file has been decoded properly (ugly) if song["duration"] > 0: self.progressBar.set_text(song["filename"]) library_writer.writerow( (song["filename"], song["album"], song["force_vector"]["attack"], song["force_vector"]["tempo"], song["force_vector"]["amplitude"], song["force_vector"]["frequency"])) csvfile.flush() else: print("Couldn't decode file '%s', skipping..." % file_n) self.progressBar.set_fraction(i / (len(audio_files) - 1)) self.progressBar.hide() self.label_done.set_label("Done!") self.label_done.show() self.goBtn.set_label("Go") print("Scan completed, data is availabe at '%s'" % url_csv)
file_list = [ os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(url)) for f in fn ] audio_files = [] for file_n in file_list: guess = mimetypes.guess_type(file_n)[0] if guess is not None and "audio" in guess: audio_files.append(file_n) playlist = [] force_vectors = [] for file_n in audio_files: with bliss.bl_song(file_n) as song: if song['duration'] > 0: force_vector = np.array(( song['force_vector']['attack'], song['force_vector']['amplitude'], song['force_vector']['frequency'], song['force_vector']['tempo'], )) playlist.append(os.path.basename(file_n)) force_vectors.append(force_vector) print('Analyzing %s...' % file_n) index = 0 if first_song_playlist in playlist: index = playlist.index(first_song_playlist)
#!/usr/bin/env python from bliss import bl_song if __name__ == "__main__": # Some example code import json # You can create an empty bl_song and manually set some fiels song = bl_song() song.set("artist", "foobar") song.set("force", 1) print(bl_song) print(song.get("artist")) print(str(song.get("force"))) print(song["artist"]) song["artist"] = "foo" print(song["artist"]) # You can also load metadata from a given file song = bl_song("/tmp/test.mp3") print(song["genre"]) song.free() # Call free on the song when done, to free dynamically # allocated memory, in the C code # Best syntax is to use a with statement which frees automatically with bl_song("/tmp/test.mp3") as song: print(song["artist"]) print(song["force_vector"]) song["sample_array"] = [] song["nSamples"] = 0 # Do *not* forget to update number of samples song["force_vector"] = {"tempo": 1., "attack": 2., "amplitude": 3.,
#!/use/bin/env python from bliss import bl_song, distance # Some examples of distance computation if __name__ == "__main__": # Compute directly with filenames distance_out = distance.distance("/tmp/test.mp3", "/tmp/test.mp3") print(distance_out["distance"]) # Always free the bl_song struct when done! distance_out["song1"].free() distance_out["song2"].free() distance_out = distance.cosine_similarity("/tmp/test.mp3", "/tmp/test.mp3") print(distance_out["similarity"]) # Always free the bl_song struct when done! distance_out["song1"].free() distance_out["song2"].free() # Compute using a previously loaded bl_song with bl_song("/tmp/test.mp3") as song1: print(distance.distance(song1, song1)["distance"]) print(distance.cosine_similarity(song1, song1)["similarity"])