diff --git a/classifier/README.md b/classifier/feature_extraction/README.md similarity index 51% rename from classifier/README.md rename to classifier/feature_extraction/README.md index d507e21..9c81058 100644 --- a/classifier/README.md +++ b/classifier/feature_extraction/README.md @@ -1,16 +1,20 @@ # Feature extraction -The file `feature_extractor` is a python module that uses the open-source library [Essentia](http://essentia.upf.edu/documentation/index.html) to extract audio features from a file in the path specified in the first parameter and save the features' values to a binary file in the path specified in the second parameter. +The file `feature_extractor` is a python module that uses the open-source library [Essentia](http://essentia.upf.edu/documentation/index.html) to extract audio features from an audio file in the path specified in the first parameter and save the features' values to a json file in the path specified in the second parameter. + +The module can be imported or executed as a script using one of the following commands +`python feature_extractor.py ` +or +`python3 feature_extractor.py ` + +A python script is also provided for a batch feature extraction. The script can be executed using one of the following commands: +`python batch_feature_extractor.py ` +or +`python3 batch_feature_extractor.py ` **Dependencies:** - essentia - numpy - scipy -- matplotlib - -All dependencies are available both for python2 and python3 versions and can all be installed using the commands `pip install ` or `pip3 install ` for python2 and python3 respectively. -The module can be imported or executed as a script using one of the following commands -`python feature_extractor.py ` -or -`python3 feature_extractor.py ` \ No newline at end of file +All dependencies are available both for python2 and python3 versions and can all be installed using the commands `pip install ` or `pip3 install ` for python2 and python3 respectively. \ No newline at end of file diff --git a/classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc b/classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc new file mode 100644 index 0000000..1323d3f Binary files /dev/null and b/classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc differ diff --git a/classifier/feature_extraction/batch_feature_extractor.py b/classifier/feature_extraction/batch_feature_extractor.py new file mode 100644 index 0000000..7c65815 --- /dev/null +++ b/classifier/feature_extraction/batch_feature_extractor.py @@ -0,0 +1,17 @@ +import sys +from os import listdir +from os.path import isfile, join +import multiprocessing as mp +from feature_extractor import extractFeatures + +audioFiles = [file for file in listdir(sys.argv[1]) if isfile(join(sys.argv[1], file))] + +# Without multithreading +# for file in audioFiles: +# extractFeatures(sys.argv[1] + file, +# sys.argv[2] + file[0:file.rfind('.')] + '.json', int(sys.argv[3])) + +pool = mp.Pool(processes = 8) +[pool.apply(extractFeatures, args=(sys.argv[1] + file, + sys.argv[2] + file[0:file.rfind('.')] + '.json', + int(sys.argv[3]))) for file in audioFiles] diff --git a/classifier/feature_extractor.py b/classifier/feature_extraction/feature_extractor.py similarity index 80% rename from classifier/feature_extractor.py rename to classifier/feature_extraction/feature_extractor.py index ef09ffe..a29190c 100644 --- a/classifier/feature_extractor.py +++ b/classifier/feature_extraction/feature_extractor.py @@ -1,13 +1,15 @@ +# import essentia.standard import essentia -import essentia.standard -from essentia.standard import * -import essentia.streaming -from pylab import plot, show, figure, imshow -import matplotlib.pyplot as plt +from essentia.standard import (MonoLoader, Windowing, Spectrum, MFCC, + ZeroCrossingRate, SpectralCentroidTime, RollOff, Flux, FrameGenerator, + YamlOutput) + +# Disable annoying info level logging +essentia.log.infoActive = False def extractFeatures(audioPath, outputPath, sampleRate): # Loads the audio file specified - loader = essentia.standard.MonoLoader(filename = audioPath, sampleRate = sampleRate) + loader = MonoLoader(filename = audioPath, sampleRate = sampleRate) audio = loader() # Sets up the functions that will be used