Пример #1
0
def compute(audio, pool, options):
    defaultStats=['mean', 'min', 'max', 'var', 'dmean', 'dvar', 'dmean2', 'dvar2', 'value']
    aggPool = essentia.PoolAggregator(defaultStats=defaultStats)(pool)
    descriptors = aggPool.descriptorNames()
    profile = 'music'

    INFO('Computing High-Level descriptors...')

    if profile == 'music':
        # Excitement
        excitement(aggPool)
        # Excitement
        intensity(aggPool)

    INFO('100% done...')
Пример #2
0
def computeSegments(audio, segments, extractors, megalopool, options):

    sampleRate = options['sampleRate']

    for segment in segments:

        segmentName = 'segment_' + str("%02d" % segments.index(segment))

        if options['verbose']:
            print 'Processing', segmentName, 'from second', segment[
                0], 'to second', segment[1]

        # creating pool...
        poolSegment = essentia.Pool()

        # creating audio segment
        audioSegment = audio[segment[0] * sampleRate:segment[1] * sampleRate]

        # creating the pool
        #poolSegment.setCurrentNamespace('metadata')
        #poolSegment.setGlobalScope([ 0.0, len(audioSegment) / sampleRate ])
        poolSegment.add('metadata.duration_processed',
                        float(len(audioSegment)) /
                        sampleRate)  #, poolSegment.GlobalScope)

        # process all extractors
        options['computed'] = []
        computeAllExtractors(extractors, audioSegment, poolSegment, options)

        # remove unwanted descriptors
        wantedStats = cleanStats(poolSegment, options)

        # adding to megalopool
        segmentScope = [segment[0], segment[1]]
        poolSegmentAggregation = essentia.PoolAggregator(
            exceptions=wantedStats)(poolSegment)
        #megalopool.add(segmentName, poolSegment.aggregate_descriptors(wantedStats))#, segmentScope)
        addToPool(segmentName, megalopool, poolSegmentAggregation)

    return megalopool
Пример #3
0
def compute(profile, inputFilename, outputFilename, userOptions = {}):

    # load profile
    profileDirectory = __file__.split(os.path.sep)[:-1]
    profileDirectory.append('profiles')
    profileDirectory.append('%s_config.yaml' % profile)

    try:
        # try to load the predefined profile, if it exists
        config = open(os.path.sep.join(profileDirectory), 'r').read()
    except:
        # otherwise, just load the file that was specified
        config = open(profile, 'r').read()

    options = yaml.load(config)
    mergeRecursiveDict(options, userOptions)

    # which format for the output?
    format = options['outputFormat']
    if format not in [ 'xml', 'yaml' ]:
        raise essentia.EssentiaError('output format should be either \'xml\' or \'yaml\'')
    if format == 'xml':
        xmlOutput = True
    else:
        xmlOutput = False

    # we need this for dependencies checking
    options['computed'] = []
    options['generatedBy'] = {}

    # get list of extractors to compute
    extractors = options['extractors']

    # create pool & megalopool
    pool = essentia.Pool()

    # load audio file into memory
    audio = loadAudioFile(inputFilename, pool, options)

    # preprocess audio by applying a DC filter, normalization, etc...
    # preprocessing is a special step because it modifies the audio, hence it
    # must be executed before all the other extractors
    audio = preProcess(audio, pool, options, 'metadata')
    options['globalPreprocessing'] = options['preprocessing']
    del options['preprocessing']

    # process all extractors
    computeAllExtractors(extractors, audio, pool, options)

    # process segmentation if asked
    if options['segmentation']['doSegmentation']:
        segments = segmentation.compute(inputFilename, audio, pool, options)

    # remove unwanted descriptors
    wantedStats = cleanStats(pool, options)

    # add to megalopool
    #megalopool = essentia.Pool()
    scope = [ 0.0, len(audio)/options['sampleRate'] ]
    #megalopool.add('global', pool.aggregate_descriptors(wantedStats))#, scope)
    megalopool = essentia.PoolAggregator(exceptions=wantedStats)(pool)
    # special case for spectral contrast, which is only 1 matrix, therefore no
    # stats are computed:
    spectral_contrast_stats(megalopool, 'lowlevel.spectral_contrast', wantedStats)

    # plotting descriptors evolution
    try:
        if options['plots']:
            import plotting
            plotting.compute(inputFilename, audio, pool, options)
    except KeyError: pass

    # compute extractors on segments
    if options['segmentation']['doSegmentation']:
        if options['segmentation']['computeSegments']:
            if len(segments) == 0:
                megalopool.add('void', [0])
            else:
                computeSegments(audio, segments, extractors, megalopool, options)

    # save to output file
    essentia.YamlOutput(filename=outputFilename)(megalopool)