Example #1
0
def featureExtraction(soundfiles):
    # extractor = esst.LowLevelSpectralExtractor()
    extractor = esst.Extractor(dynamics = False,
                                                dynamicsFrameSize = 88200,
                                                dynamicsHopSize = 44100,
                                                highLevel = False,
        			         lowLevel = True,
        			         lowLevelFrameSize = 2048,
        			         lowLevelHopSize = 1024,
        			         midLevel = True,
        			         namespace = "",
        			         relativeIoi = False,
        			         rhythm = False,
        			         sampleRate  = 44100,
        			         tonalFrameSize  = 4096,
        			         tonalHopSize = 2048,
			         tuning = True)

	#soundfiles = listdir(inputPath)
    for file in soundfiles:

        path1= '/Users/helena/Desktop/SMC/ASP/sms-tools/workspace/A10/code/downloaded/'
        name=file[70:-4] + '_features.json'
        outPath = path1 + 'features/' + name
        print file
        audioLoader = esst.MonoLoader(filename=file)
        audio = audioLoader()
        pool = essentia.Pool()
        pool = extractor(audio)
        aggPool = esst.PoolAggregator()(pool)
        output = esst.YamlOutput(filename = outPath, format='json')
        output(aggPool)
        print (outPath + ' exported')
def extractDefaultFeatures(audio, outputDir):

    # compute all features for all sounds
    extractor = ess.Extractor(dynamics=True,
                              dynamicsFrameSize=88200,
                              dynamicsHopSize=44100,
                              highLevel=True,
                              lowLevel=True,
                              lowLevelFrameSize=2048,
                              lowLevelHopSize=1024,
                              midLevel=True,
                              namespace="",
                              relativeIoi=False,
                              rhythm=True,
                              sampleRate=44100,
                              tonalFrameSize=4096,
                              tonalHopSize=2048,
                              tuning=True)

    pool = essentia.Pool()
    pool = extractor(audio)
    aggPool = ess.PoolAggregator()(pool)

    if not path.exists(outputDir):
        makedirs(outputDir)

    ess.YamlOutput(filename=outputDir + "features.json",
                   format="json",
                   doubleCheck=True)(aggPool)
Example #3
0
def featureExtraction(soundfiles):

    #extractor = esst.LowLevelSpectralExtractor()
    extractor = esst.Extractor(dynamics=True,
                               dynamicsFrameSize=88200,
                               dynamicsHopSize=44100,
                               highLevel=True,
                               lowLevel=True,
                               lowLevelFrameSize=2048,
                               lowLevelHopSize=1024,
                               midLevel=True,
                               namespace="",
                               relativeIoi=False,
                               rhythm=True,
                               sampleRate=44100,
                               tonalFrameSize=4096,
                               tonalHopSize=2048,
                               tuning=True)

    #soundfiles = listdir(inputPath)

    for file, outPath in soundfiles:

        audioLoader = esst.MonoLoader(filename=file)
        audio = audioLoader()
        pool = essentia.Pool()
        pool = extractor(audio)
        aggPool = esst.PoolAggregator()(pool)
        esst.YamlOutput(filename=outPath + 'features.json',
                        format='json')(aggPool)
        print(file + ' exported')
Example #4
0
 def extract_features_all(path, track_name):
     features, features_frames = es.MusicExtractor(
         lowlevelStats=['mean', 'stdev', 'min', 'max'],
         rhythmStats=['mean', 'stdev', 'min', 'max'],
         tonalStats=['mean', 'stdev', 'min', 'max'],
     )(f'{path}{track_name}')
     save_file = f'../data/essentia/{track_name[:-4]}.json'
     es.YamlOutput(filename=save_file, format="json")(features)
Example #5
0
 def extract_features_intervals(path, track_name):
     intervals = list(range(1, 31))
     for i in intervals:
         start = i - 1
         end = i
         features, features_frames = es.MusicExtractor(
             lowlevelStats=['mean', 'stdev', 'min', 'max'],
             rhythmStats=['mean', 'stdev', 'min', 'max'],
             tonalStats=['mean', 'stdev', 'min', 'max'],
             startTime=start,
             endTime=end)(f'{path}{track_name}')
         save_file = f'../data/essentia_bow/{track_name[:-4]}_{i}.json'
         es.YamlOutput(filename=save_file, format="json")(features)
Example #6
0
def savePoolToJson(input_pool, file_path="test_save.json"):
    """
  Salva input_pool no .json definido por file_name, 
  se o arquivo já existir, sobreescreve-o.

  O default de file_name serve para criar um arquivo de teste
  """

    try:
        remove(file_path)
    except FileNotFoundError:
        pass

    es_mode.YamlOutput(filename=file_path,\
                      format="json",\
                      writeVersion=False,\
                      doubleCheck=True)(input_pool)
                'lowlevelStats': stats,
                'rhythmMethod': 'degara',
                'rhythmMinTempo': 40,
                'rhythmMaxTempo': 208,
                'rhythmStats': stats,
                'tonalFrameSize': 4096,
                'tonalHopSize': 2048,
                'tonalWindowType': 'blackmanharris62',
                'tonalSilentFrames': 'noise',
                'tonalStats': stats
            }

            features, features_frames = es.FreesoundExtractor(
                **profile)(audio_in)
            file_json = output + ".json"
            es.YamlOutput(filename=file_json, format='json')(features)

            tab_header = []
            tab_value = []

            features_name = sorted(features.descriptorNames())
            for feat in range(0, len(features_name)):
                name_feature = features_name[feat]
                # print(name)
                kind_of_feature = name_feature.split(".")
                # print(type)

                # ALL FEATURES
                # if(kind_of_feature[0] != 'metadata' and
                # kind_of_feature[1] != 'silence_rate_60dB' and
                # kind_of_feature[1] != 'sound_start_frame' and
Example #8
0
import confirm_prompt #for confirming user action 
import json_flattener #for flatenning jsons

# [NOTE] Please set the path to dataset here(this is the path to directory where the instrument folders {bas, cel ... vio} will be moved in)
path_to_dataset='../../datasets/good-sounds/instruments'

instruments = os.listdir(path_to_dataset)
instruments.sort()


for instrument in instruments:  
    print("[Instrument] : " + instrument)
    files=sorted(os.listdir(os.path.join(path_to_dataset,instrument)))
    print("Number of files : "+str(len(files)))
    for file in files:
        if(file.endswith('.wav')):
            filename=os.path.join(path_to_dataset,instrument,file) 
            print("Analysing file : "+filename)
            # Compute all features, aggregate only 'mean' and 'stdev' statistics for all low-level, rhythm and tonal frame features
            features, features_frames = es.MusicExtractor(lowlevelSilentFrames='drop',
                                                              lowlevelFrameSize=2048,
                                                              lowlevelHopSize=1024,
                                                              lowlevelStats=['mean', 'stdev'])(filename)
            features_frames=[]
            es.YamlOutput(filename = filename.replace('.wav','.json'), format='json')(features)
            features=[]
            filename=[]
    print("Feature Extraction Completed Successfully")


            '**************************************************************************'
        )
        INFO('processing entire audio from ' + str(startTime) + 's to ' +
             str(endTime) + 's')
        INFO(
            '**************************************************************************'
        )
        INFO('Process step 3: Mid Level')
        computeMidLevel(input_file, pool, startTime, endTime)
        INFO('Process step 4: High Level')
        highlevel.compute(pool)

    else:
        INFO('Process step 2: Low Level')
        computeLowLevel(input_file, pool, startTime, endTime)
        INFO('Process step 3: Mid Level')
        computeMidLevel(input_file, pool, startTime, endTime)
        INFO('Process step 4: High Level')
        highlevel.compute(pool)

    # compute statistics
    INFO('Process step 5: Aggregation')
    stats = computeAggregation(pool, segments_namespace)

    # svm
    #addSVMDescriptors(stats, opt.svmpath)

    # output results to file
    INFO('writing results to ' + output_file)
    standard.YamlOutput(filename=output_file)(stats)
Example #10
0
        INFO('Process step 4: High Level')
        highlevel.compute(eqPool)
        highlevel.compute(neqPool)

    else:
        INFO('Process step 2: Low Level')
        computeLowLevel(input_file, neqPool, eqPool, startTime, endTime)
        INFO('Process step 3: Mid Level')
        computeMidLevel(input_file, neqPool, eqPool, startTime, endTime)
        INFO('Process step 4: High Level')
        highlevel.compute(eqPool)
        highlevel.compute(neqPool)

    # compute statistics
    INFO('Process step 5: Aggregation')
    neqStats = computeAggregation(neqPool, segments_namespace)
    eqStats = computeAggregation(eqPool, segments_namespace)

    # svm
    #addSVMDescriptors(neqStats, opt.svmpath)

    # output results to file
    eqStats.set('metadata.audio_properties.equal_loudness', 1)
    neqStats.set('metadata.audio_properties.equal_loudness', 0)
    INFO('writing results to ' + output_file)
    standard.YamlOutput(filename=output_file)(eqStats)
    (name, ext) = os.path.splitext(output_file)
    output_file = name + '..neq.sig'
    INFO('writing results to ' + output_file)
    standard.YamlOutput(filename=output_file)(neqStats)
Example #11
0
"""

# So let's redo the previous using a Pool
pool = es.Pool()
for frame in ess.FrameGenerator(audio, frameSize=1024, hopSize=512):
    mfcc_bands, mfcc_coeffs = mfcc(spectrum(w(frame)))
    pool.add('lowlevel.mfcc', mfcc_coeffs)
    pool.add('lowlevel.mfcc_bands', mfcc_bands)
"""
plotMfcc = pool['lowlevel.mfcc'].T[1:,:]
plt.pcolormesh(plotMfcc)
plt.show()
"""

#output = es.YamlOutput(filename = 'mfcc.sig')
output = ess.YamlOutput(filename='joeTestOut/mfcc.json', format='json')
output(pool)

# Say we're not interested in all the MFCC frames, but just their mean & variance.
# To this end, we have the PoolAggregator algorithm, that can do all sorts of
# aggregation: mean, variance, min, max, etc...
aggrPool = ess.PoolAggregator(defaultStats=['mean', 'var'])(pool)

print 'Original pool descriptor names:'
print pool.descriptorNames()
print
print 'Aggregated pool descriptor names:'
print aggrPool.descriptorNames()

output = ess.YamlOutput(filename='joeTestOut/mfccaggr.json', format='json')
output(aggrPool)
Example #12
0
def main():

    aparser = argparse.ArgumentParser()
    aparser.add_argument(
        '-c',
        action='store',
        dest='config',
        help=
        '-c type of the dataset. For ex: _1s_h100 for 1s with full length hop')
    aparser.add_argument('-t',
                         action='store',
                         dest='data_type',
                         help='-t type of data original/harmonic/residual')

    args = aparser.parse_args()
    if not args.config:
        aparser.error('Please specify the data config!')

    conf = args.config
    if args.data_type == 'original':
        path_to_dataset = PATH_TO_ORIGINAL_WAV_FILES + conf
        path_to_features = PATH_TO_ORIGINAL_FEATURES + conf
    if args.data_type == 'residual':
        path_to_dataset = PATH_TO_RESIDUAL_WAV_FILES + conf
        path_to_features = PATH_TO_RESIDUAL_FEATURES + conf
    if args.data_type == 'harmonic':
        path_to_dataset = PATH_TO_HARMONIC_WAV_FILES + conf
        path_to_features = PATH_TO_HARMONIC_FEATURES + conf

    datasets = sorted(os.listdir(path_to_dataset))
    for dataset in datasets:
        empty_files = 0
        print("[Dataset] : " + dataset)
        folder_path = os.path.join(path_to_dataset, dataset)
        lrms = sorted(os.listdir(folder_path))
        for channel in lrms:
            channel_path = os.path.join(folder_path, channel)
            sub_folders = sorted(os.listdir(channel_path))
            for sub_folder in sub_folders:
                sub_folder_path = os.path.join(channel_path, sub_folder)
                files = sorted(os.listdir(sub_folder_path))
                for filename in files:
                    filepath = os.path.join(sub_folder_path, filename)
                    features = essentia.Pool()
                    try:
                        # Compute all features, aggregate only 'mean' and 'stdev' statistics for all low-level, rhythm and tonal frame features
                        features, features_frames = es.MusicExtractor(
                            lowlevelSilentFrames='drop',
                            lowlevelFrameSize=2048,
                            lowlevelHopSize=1024,
                            lowlevelStats=['mean', 'stdev'])(filepath)
                        features_frames = []
                    except RuntimeError, e:
                        print(filepath + " is almost silent")
                        empty_files += 1
                    dump_path = os.path.join(path_to_features, dataset,
                                             channel, sub_folder)
                    create_folder(dump_path)
                    es.YamlOutput(filename=os.path.join(
                        dump_path, filename.replace('.wav', '.json')),
                                  format='json')(features)
                    features = []
                    filename = []
        print("Feature Extraction Completed Successfully for " + dataset)
        print("Total number of empty file in " + dataset + " is " +
              str(empty_files))