def build():
    filename = 'FlavioGaete22.zip'

    # stream all the audio files from the zip archive
    print 'Processing Audio...'
    for zf in ff.iter_zip(filename):
        if '._' in zf.filename:
            continue
        print zf.filename
        WithTimbre.process(meta=zf)

    # learn k-means codes for the bfcc frames
    print 'Learning K-Means clusters...'
    BfccKmeans.process(docs=(wt.bfcc for wt in WithTimbre))

    # build an index
    print 'Building index...'
    BfccKmeansIndex.build()
Beispiel #2
0
    def test_can_handle_zip_file(self):
        STFT = stft(resample_to=SR11025(), store_fft=True)

        @simple_in_memory_settings
        class Document(STFT):
            pass

        signal = SineSynthesizer(SR11025()).synthesize(Seconds(2))

        bio = BytesIO()
        filename = 'test.wav'
        with zipfile.ZipFile(bio, mode='w') as zf:
            zf.writestr(filename, signal.encode().read())
        bio.seek(0)

        zip_wrapper = featureflow.iter_zip(bio).next()
        _id = Document.process(meta=zip_wrapper)
        doc = Document(_id)
        self.assertEqual(2, doc.ogg.duration_seconds)
Beispiel #3
0
    # forward and backward transformations
    pipeline = ff.PickleFeature(
            zounds.PreprocessingPipeline,
            needs=(log, unit_norm, kmeans),
            store=True)


if __name__ == '__main__':

    # stream all the audio files from the zip archive
    # you can download the original file here:
    # https://archive.org/details/FlavioGaete
    # - https://archive.org/download/FlavioGaete/FlavioGaete22.zip
    filename = 'FlavioGaete22.zip'
    print 'Processing Audio...'
    for zf in ff.iter_zip(filename):
        if '._' in zf.filename:
            continue
        try:
            # check if the feature already exists
            Document(zf.filename).mdct.shape
        except KeyError:
            print 'processing {filename}'.format(filename=zf.filename)
            Document.process(meta=zf, _id=zf.filename)

    print 'learn k-means clusters'
    DctKmeans.process(docs=(doc.mdct for doc in Document))

    print 'learn k-means clusters with log amplitude'
    DctKmeansWithLogAmplitude.process(docs=(doc.mdct for doc in Document))
Beispiel #4
0
        print('Downloading {url} -> {filename}...'.format(**locals()))

        with open(filename, 'wb') as f:
            for chunk in resp.iter_content(chunk_size=1000000):
                f.write(chunk)

    return filename

if __name__ == '__main__':
    index = zounds.HammingIndex(
        WithCodes, WithCodes.bfcc_kmeans_pooled, listen=True)

    zip_filename = download_zip_archive()

    print('Processing Audio...')
    for zf in ff.iter_zip(zip_filename):

        if '._' in zf.filename:
            continue

        try:
            print('processing {zf.filename}'.format(**locals()))
            WithTimbre.process(
                _id=zf.filename, meta=zf, raise_if_exists=True)
        except ff.ModelExistsError as e:
            print(e)

    # learn K-Means centroids
    try:
        print('learning K-Means centroids')
        BfccKmeans.process(