def callback(data): # update audio buffer buffer[:] = array(unpack('f' * bufferSize, data)) # generate predictions reset(vimp) run(vimp)
def callback(data): buffer[:] = array(unpack('f' * bufferSize, data)) mfccBuffer = np.zeros([numberBands]) reset(vectorInput) run(vectorInput) mfccBuffer = np.roll(mfccBuffer, -patchSize) mfccBuffer = pool['mfcc'][-patchSize] features = mfccBuffer features = features.tolist() return features
def callback(data): # update audio buffer buffer[:] = array(unpack('f' * bufferSize, data)) # generate predictions reset(vimp) run(vimp) # update mel and activation buffers melBuffer[:] = np.roll(melBuffer, -patchSize) melBuffer[:, -patchSize:] = pool['melbands'][-patchSize:,:].T img_mel.set_data(melBuffer) actBuffer[:] = np.roll(actBuffer, -1) actBuffer[:, -1] = softmax(20 * pool['model/Sigmoid'][-1,:].T) img_act.set_data(actBuffer) # update plots f.canvas.draw()
mfcc.bands >> None mfcc.mfcc >> (pool, 'lowlevel.mfcc') essentia.run(loader) print 'Pool contains %d frames of MFCCs' % len(pool['lowlevel.mfcc']) # <demo> --- stop --- # Let's try writing directly to a text file, no pool and no yaml files # we first need to disconnect the old connection to the pool to avoid putting the same # data in there again mfcc.mfcc.disconnect((pool, 'lowlevel.mfcc')) # we create a FileOutput fileout = FileOutput(filename = 'mfccframes.txt') # and connect it: it is a special connection as it has no input, because it can actually # take any type of input (the other algorithms will complain if you try to connect an output # to an input of a different type) mfcc.mfcc >> fileout # reset the network otherwise the loader in particular will not do anything useful essentia.reset(loader) # and rerun it! essentia.run(loader)
def runResetRun(gen, *args, **kwargs): # 0. Find networks which contain algorithms who do not play nice with our # little trick. In particular, we have a test for multiplexer that runs # multiple generators... def isValid(algo): if isinstance(algo, essentia.streaming.VectorInput) and not algo.connections.values()[0]: # non-connected VectorInput, we don't want to get too fancy here... return False if algo.name() == 'Multiplexer': return False for output, inputs in algo.connections.iteritems(): for inp in inputs: if isinstance(inp, essentia.streaming._StreamConnector) and not isValid(inp.input_algo): return False return True if not isValid(gen): print 'Network is not capable of doing the run/reset/run trick, doing it the normal way...' essentia.run(gen) return # 1. Find all the outputs in the network that are connected to pools--aka # pool feeders and for each pool feeder, disconnect the given pool, # store it, and connect a dummy pool in its place def useDummy(algo, output, input): if not hasattr(output, 'originalPools'): output.originalPools = [] output.dummyPools = [] # disconnect original output.originalPools.append(input) output.disconnect(input) # connect dummy dummy = essentia.Pool() output.dummyPools.append((dummy, input[1])) output >> output.dummyPools[-1] mapPools(gen, useDummy) # 2. Run the network essentia.run(gen) # 3. Reset the network essentia.reset(gen) # 4. For each pool feeder, disconnect the dummy pool and reconnect the # original pool def useOriginal(algo, output, input): # disconnect dummy output.disconnect(input) # the dummy pools and the original pools should have the same index idx = output.dummyPools.index(input) output.dummyPools.remove(input) # connect original output >> output.originalPools[idx] # don't need these anymore if len(output.dummyPools) == 0: del output.dummyPools del output.originalPools mapPools(gen, useOriginal) # 5. Run the network for the second and final time return essentia.run(gen)
def runResetRun(gen, *args, **kwargs): # 0. Find networks which contain algorithms who do not play nice with our # little trick. In particular, we have a test for multiplexer that runs # multiple generators... def isValid(algo): if isinstance(algo, essentia.streaming.VectorInput ) and not algo.connections.values()[0]: # non-connected VectorInput, we don't want to get too fancy here... return False if algo.name() == 'Multiplexer': return False for output, inputs in algo.connections.iteritems(): for inp in inputs: if isinstance(inp, essentia.streaming._StreamConnector ) and not isValid(inp.input_algo): return False return True if not isValid(gen): print 'Network is not capable of doing the run/reset/run trick, doing it the normal way...' essentia.run(gen) return # 1. Find all the outputs in the network that are connected to pools--aka # pool feeders and for each pool feeder, disconnect the given pool, # store it, and connect a dummy pool in its place def useDummy(algo, output, input): if not hasattr(output, 'originalPools'): output.originalPools = [] output.dummyPools = [] # disconnect original output.originalPools.append(input) output.disconnect(input) # connect dummy dummy = essentia.Pool() output.dummyPools.append((dummy, input[1])) output >> output.dummyPools[-1] mapPools(gen, useDummy) # 2. Run the network essentia.run(gen) # 3. Reset the network essentia.reset(gen) # 4. For each pool feeder, disconnect the dummy pool and reconnect the # original pool def useOriginal(algo, output, input): # disconnect dummy output.disconnect(input) # the dummy pools and the original pools should have the same index idx = output.dummyPools.index(input) output.dummyPools.remove(input) # connect original output >> output.originalPools[idx] # don't need these anymore if len(output.dummyPools) == 0: del output.dummyPools del output.originalPools mapPools(gen, useOriginal) # 5. Run the network for the second and final time return essentia.run(gen)
def load_audio(type='mono'): raw_audio = OrderedDict() stem_audio = OrderedDict() if 'mono' in type: # loads raw audio loader = MonoLoader() for name in gNameTracks: path = gRawPath[name] loader.configure(filename=path) pool = essentia.Pool() loader.audio >> (pool, 'loader.audio') essentia.run(loader) print 'Raw track contains %d samples of Audio' % len( pool['loader.audio']) raw_audio[name] = pool['loader.audio'] essentia.reset(loader) # loads stem audio for name in gNameTracks: path = gStemPath[name] loader.configure(filename=path) pool = essentia.Pool() loader.audio >> (pool, 'loader.audio') essentia.run(loader) print 'Stem track contains %d samples of Audio' % len( pool['loader.audio']) stem_audio[name] = pool['loader.audio'] essentia.reset(loader) elif 'stereo' in type: # loads raw audio Stereo: for name in gNameTracks: path = gRawPath[name] loader = AudioLoader(filename=path) pool = essentia.Pool() loader.audio >> (pool, 'loader.audio') loader.sampleRate >> None loader.numberChannels >> None loader.md5 >> None loader.bit_rate >> None loader.codec >> None essentia.run(loader) print 'Raw Stereo track contains %d samples of Audio' % len( pool['loader.audio']) raw_audio[name] = pool['loader.audio'] essentia.reset(loader) # loads stem stereo for name in gNameTracks: path = gStemStereoPath[name] loader = AudioLoader(filename=path) pool = essentia.Pool() loader.audio >> (pool, 'loader.audio') loader.sampleRate >> None loader.numberChannels >> None loader.md5 >> None loader.bit_rate >> None loader.codec >> None essentia.run(loader) print 'Stem Stereo track contains %d samples of Audio' % len( pool['loader.audio']) stem_audio[name] = pool['loader.audio'] essentia.reset(loader) return raw_audio, stem_audio
def featureExtractFile(curFile): import sys import numpy import essentia from essentia.streaming import MonoLoader from essentia.streaming import LowLevelSpectralExtractor from essentia.standard import YamlOutput from essentia.standard import YamlInput from essentia.standard import PoolAggregator from essentia.streaming import FrameCutter from essentia.streaming import AutoCorrelation import pickle filename = '/home/user/Desktop/soundsDB2/classifier/featureExtractionEssentia/frameSize.npz' npz = numpy.load(filename) frameSize = int(npz['frameSize']) # and instantiate our algorithms loader = MonoLoader(filename=curFile, sampleRate=8000) framecutter = FrameCutter(frameSize=frameSize, hopSize=frameSize / 4) autoCorrelator = AutoCorrelation() lowLevelExtractor = LowLevelSpectralExtractor(frameSize=frameSize, hopSize=frameSize / 4, sampleRate=8000) pool = essentia.Pool() loader.audio >> lowLevelExtractor.signal lowLevelExtractor.barkbands >> (pool, curFile[:-4] + '.barkbands') lowLevelExtractor.barkbands_kurtosis >> (pool, curFile[:-4] + '.barkbands_kurtosis') lowLevelExtractor.barkbands_skewness >> (pool, curFile[:-4] + '.barkbands_skewness') lowLevelExtractor.barkbands_spread >> (pool, curFile[:-4] + '.barkbands_spread') lowLevelExtractor.hfc >> (pool, curFile[:-4] + '.hfc') lowLevelExtractor.mfcc >> (pool, curFile[:-4] + '.mfcc') lowLevelExtractor.pitch >> (pool, curFile[:-4] + '.pitch') lowLevelExtractor.pitch_instantaneous_confidence >> ( pool, curFile[:-4] + '.pitch_instantaneous_confidence') lowLevelExtractor.pitch_salience >> (pool, curFile[:-4] + '.pitch_salience') lowLevelExtractor.silence_rate_20dB >> (pool, curFile[:-4] + '.silence_rate_20dB') lowLevelExtractor.silence_rate_30dB >> (pool, curFile[:-4] + '.silence_rate_30dB ') lowLevelExtractor.silence_rate_60dB >> (pool, curFile[:-4] + '.silence_rate_60dB') lowLevelExtractor.spectral_complexity >> (pool, curFile[:-4] + '.spectral_complexity') lowLevelExtractor.spectral_crest >> (pool, curFile[:-4] + '.spectral_crest') lowLevelExtractor.spectral_decrease >> (pool, curFile[:-4] + '.spectral_decrease') lowLevelExtractor.spectral_energy >> (pool, curFile[:-4] + '.spectral_energy') lowLevelExtractor.spectral_energyband_low >> (pool, curFile[:-4] + '.spectral_energyband_low') lowLevelExtractor.spectral_energyband_middle_low >> ( pool, curFile[:-4] + '.spectral_energyband_middle_low') lowLevelExtractor.spectral_energyband_middle_high >> ( pool, curFile[:-4] + '.spectral_energyband_middle_high') lowLevelExtractor.spectral_energyband_high >> None lowLevelExtractor.spectral_flatness_db >> (pool, curFile[:-4] + '.spectral_flatness_db') lowLevelExtractor.spectral_flux >> (pool, curFile[:-4] + '.spectral_flux') lowLevelExtractor.spectral_rms >> (pool, curFile[:-4] + '.spectral_rms') lowLevelExtractor.spectral_rolloff >> (pool, curFile[:-4] + '.spectral_rolloff') lowLevelExtractor.spectral_strongpeak >> (pool, curFile[:-4] + '.spectral_strongpeak') lowLevelExtractor.zerocrossingrate >> (pool, curFile[:-4] + '.zerocrossingrate') lowLevelExtractor.inharmonicity >> (pool, curFile[:-4] + '.inharmonicity') lowLevelExtractor.tristimulus >> (pool, curFile[:-4] + '.tristimulus') lowLevelExtractor.oddtoevenharmonicenergyratio >> ( pool, curFile[:-4] + '.oddtoevenharmonicenergyratio') lowLevelExtractor.inharmonicity >> None lowLevelExtractor.tristimulus >> None lowLevelExtractor.oddtoevenharmonicenergyratio >> None #mfcc.bands >> (pool, curFile[:-4]+'.mfccBands') #mfcc.mfcc >> (pool, curFile[:-4]+'.mfcc') essentia.run(loader) aggrPool = PoolAggregator(defaultStats=[ 'min', 'max', 'median', 'mean', 'var', 'skew', 'kurt', 'dmean', 'dvar' ])(pool) #aggrPool = PoolAggregator(defaultStats = ['min', 'max', 'mean', 'var'])(pool) YamlOutput(filename=curFile[:-4] + 'trainingFeatures.yaml', format="yaml")(aggrPool) essentia.reset(loader) return
sampleRate=sample_rate, weightType=weight_type, windowSize=weight_window_size) pool = e.Pool() loader.audio >> framecutter.signal framecutter.frame >> windowing.frame >> spectrum.frame spectrum.spectrum >> spectralpeaks.spectrum spectralpeaks.magnitudes >> hpcp.magnitudes spectralpeaks.frequencies >> hpcp.frequencies hpcp.hpcp >> (pool, 'tonal.caca') e.run(loader) # run and print the results. result = pool['tonal.caca'] print item[:15]+'... \n', result with open(temp_folder + '/' + item[:-3]+'txt', 'w') as textfile: # and write them to a textfile textfile.write(result) e.reset(loader) # reset essentia """ # EVALUATION! #Dictionaries... name2class = {'B#':0,'C':0, 'C#':1,'Db':1, 'D':2, 'D#':3,'Eb':3, 'E':4,'Fb':4, 'E#':5,'F':5, 'F#':6,'Gb':6, 'G':7, 'G#':8,'Ab':8, 'A':9, 'A#':10,'Bb':10, 'B':11,'Cb':11}