4 changed files with 37 additions and 14 deletions
			
			
		@ -1,16 +1,20 @@ | 
				
			|||||
# Feature extraction | 
					# 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 <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>` | 
				
			||||
 | 
					or | 
				
			||||
 | 
					`python3 feature_extractor.py <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>` | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					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 <audio_files_directory> <feature_files_directory> <audio_files_sample_rate>` | 
				
			||||
 | 
					or | 
				
			||||
 | 
					`python3 batch_feature_extractor.py <audio_files_directory> <feature_files_directory> <audio_files_sample_rate>` | 
				
			||||
 | 
					
 | 
				
			||||
**Dependencies:** | 
					**Dependencies:** | 
				
			||||
- essentia | 
					- essentia | 
				
			||||
- numpy | 
					- numpy | 
				
			||||
- scipy | 
					- scipy | 
				
			||||
- matplotlib | 
					 | 
				
			||||
 | 
					
 | 
				
			||||
All dependencies are available both for python2 and python3 versions and can all be installed using the commands `pip install <package_name>` or `pip3 install <package_name>` for python2 and python3 respectively. | 
					All dependencies are available both for python2 and python3 versions and can all be installed using the commands `pip install <package_name>` or `pip3 install <package_name>` 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 <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>` | 
					 | 
				
			||||
or | 
					 | 
				
			||||
`python3 feature_extractor.py <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>` | 
					 | 
				
			||||
								
									Binary file not shown.
								
							
						
					@ -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] | 
				
			||||
@ -1,13 +1,15 @@ | 
				
			|||||
 | 
					# import essentia.standard | 
				
			||||
import essentia | 
					import essentia | 
				
			||||
import essentia.standard | 
					from essentia.standard import (MonoLoader, Windowing, Spectrum, MFCC, | 
				
			||||
from essentia.standard import * | 
						ZeroCrossingRate, SpectralCentroidTime, RollOff, Flux, FrameGenerator, | 
				
			||||
import essentia.streaming | 
						YamlOutput) | 
				
			||||
from pylab import plot, show, figure, imshow | 
					
 | 
				
			||||
import matplotlib.pyplot as plt | 
					# Disable annoying info level logging | 
				
			||||
 | 
					essentia.log.infoActive = False | 
				
			||||
 | 
					
 | 
				
			||||
def extractFeatures(audioPath, outputPath, sampleRate): | 
					def extractFeatures(audioPath, outputPath, sampleRate): | 
				
			||||
	# Loads the audio file specified | 
						# Loads the audio file specified | 
				
			||||
	loader = essentia.standard.MonoLoader(filename = audioPath, sampleRate = sampleRate) | 
						loader = MonoLoader(filename = audioPath, sampleRate = sampleRate) | 
				
			||||
	audio = loader() | 
						audio = loader() | 
				
			||||
 | 
					
 | 
				
			||||
	# Sets up the functions that will be used | 
						# Sets up the functions that will be used | 
				
			||||
					Loading…
					
					
				
		Reference in new issue