-
Notifications
You must be signed in to change notification settings - Fork 0
2. Examples for a first try
-
Create a working folder. Copy an audio file into this folder (flac, mp3, wav...)
-
Using Windows Explorer, in the same folder. Top left menu: File > Open Windows PowerShell
-
Then enter the following commands, one line at a time
pyimport essentia.standard as es
Here, replace
music.flacwith the name and extension of your audio fileaudio = es.MonoLoader(filename="music.flac")()
rhythm_extractor = es.RhythmExtractor2013(method="multifeature")
bpm, beats, beats_confidence, _, beats_intervals = rhythm_extractor(audio)
print("BPM:", bpm)
Result
PS E:\Test> py Python 3.12.5 (tags/v3.12.5:ff3bc82, Aug 6 2024, 20:45:27) [MSC v.1940 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import essentia.standard as es 2024-08-24 19:12:17.310518: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. [ INFO ] MusicExtractorSVM: no classifier models were configured by default 2024-08-24 19:12:18.239514: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. >>> audio = es.MonoLoader(filename="09. Slow roll.flac")() >>> rhythm_extractor = es.RhythmExtractor2013(method="multifeature") >>> bpm, beats, beats_confidence, _, beats_intervals = rhythm_extractor(audio) >>> print("BPM:", bpm) BPM: 156.33270263671875 >>> >>> >>> exit() PS E:\Test> -
You can exit from Python with
exit()orquit()orCtrl + Z -
You can clear the screen with
Clear-Hostorcls
Still in a working folder with an audio file
-
Download these files:
mood_happy-discogs-effnet-1.pb
mood_happy-discogs-effnet-1.json : for json files, you may need to right-click on the link > Save link target as...
discogs-effnet-bs64-1.pb -
Create a file called
script.py, and paste this code inside it. On line 8, replaceaudio.wavwith the name and extension of your audio file, and save your filescript.py
import json with open('mood_happy-discogs-effnet-1.json', 'r') as json_file: metadata = json.load(json_file) from essentia.standard import MonoLoader, TensorflowPredictEffnetDiscogs, TensorflowPredict2D audio = MonoLoader(filename="audio.wav", sampleRate=16000, resampleQuality=4)() embedding_model = TensorflowPredictEffnetDiscogs(graphFilename="discogs-effnet-bs64-1.pb", output="PartitionedCall:1") embeddings = embedding_model(audio) model = TensorflowPredict2D(graphFilename="mood_happy-discogs-effnet-1.pb", output="model/Softmax") predictions = model(embeddings) for label, probability in zip(metadata['classes'], predictions.mean(axis=0)): print(f'{label}: {probability}')
-
Put these files in your working folder
-
Open PowerShell and run this command
py script.py
Result
PS E:\Test> py script.py 2024-08-24 19:26:21.417805: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. [ INFO ] MusicExtractorSVM: no classifier models were configured by default 2024-08-24 19:26:22.285506: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. [ INFO ] TensorflowPredict: Successfully loaded graph file: `discogs-effnet-bs64-1.pb` 2024-08-24 19:26:23.779818: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled [ INFO ] TensorflowPredict: Successfully loaded graph file: `mood_happy-discogs-effnet-1.pb` [ INFO ] TensorflowPredict: Successfully loaded graph file: `mood_happy-discogs-effnet-1.pb` happy: 0.6639894843101501 non_happy: 0.33601048588752747 PS E:\Test>