예제 #1
0
windowing = zounds.HalfLapped()


# Segment audio files #########################################################

class Settings(ff.PersistenceSettings):
    id_provider = ff.UserSpecifiedIdProvider(key='_id')
    key_builder = ff.StringDelimitedKeyBuilder(seperator='|')
    database = ff.LmdbDatabase(path='onsetdata', key_builder=key_builder)
    event_log = ff.EventLog(
        path='onsetdataevents', channel=ff.InMemoryChannel())


STFT = zounds.stft(
    resample_to=zounds.SR11025(),
    wscheme=windowing)


class WithOnsets(STFT, Settings):
    bark = zounds.ArrayWithUnitsFeature(
        zounds.BarkBands,
        needs=STFT.fft,
        store=True)

    transience = zounds.ArrayWithUnitsFeature(
        zounds.MeasureOfTransience,
        needs=STFT.fft,
        store=True)

    sliding_detection = zounds.ArrayWithUnitsFeature(
예제 #2
0
import zounds
import argparse

samplerate = zounds.SR11025()
BaseModel = zounds.stft(resample_to=samplerate, store_fft=True)


@zounds.simple_in_memory_settings
class Sound(BaseModel):
    pass


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--local-path',
        required=True,
        type=str,
        help='local path where the nsynth tar files should be stored')
    parser.add_argument(
        '--port',
        default=8888,
        type=int,
        help='port to run the in-browser REPL in')
    args = parser.parse_args()

    ns = zounds.NSynth(path=args.local_path)
    zounds.ingest(ns, Sound, multi_threaded=True)

    app = zounds.ZoundsApp(
        model=Sound,
예제 #3
0
"""
Demonstrate how to download and process sounds from https://freesound.org
"""

import zounds
import argparse

BaseModel = zounds.stft(resample_to=zounds.SR11025())


@zounds.simple_lmdb_settings('freesound', map_size=1e10, user_supplied_id=True)
class Sound(BaseModel):
    bark = zounds.ArrayWithUnitsFeature(zounds.BarkBands,
                                        needs=BaseModel.fft,
                                        store=True)

    chroma = zounds.ArrayWithUnitsFeature(zounds.Chroma,
                                          needs=BaseModel.fft,
                                          store=True)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--api-key',
        help='your Freesound API key (http://freesound.org/apiv2/apply/)',
        type=str,
        required=True)
    parser.add_argument('--query',
                        help='the text query to run against freesound',
                        type=str,
예제 #4
0
import zounds

samplerate = zounds.SR22050()
BaseModel = zounds.stft(resample_to=samplerate, store_fft=True)


@zounds.simple_in_memory_settings
class Sound(BaseModel):
    pass


if __name__ == '__main__':
    url = 'https://ia802606.us.archive.org/9/items/AOC11B/onclassical_luisi_bach_partita_e-minor_bwv-830_3.ogg'
    _id = Sound.process(meta=url)
    snd = Sound(_id)

    band = zounds.FrequencyBand(50, samplerate.nyquist)
    bark_scale = zounds.BarkScale(band, 100)
    mel_scale = zounds.MelScale(band, 100)
    chroma_scale = zounds.ChromaScale(band)

    bark_bands = bark_scale.apply(snd.fft, zounds.HanningWindowingFunc())
    mel_bands = mel_scale.apply(snd.fft, zounds.HanningWindowingFunc())
    chroma_bands = chroma_scale.apply(snd.fft, zounds.HanningWindowingFunc())

    app = zounds.ZoundsApp(
        model=Sound,
        visualization_feature=Sound.fft,
        audio_feature=Sound.ogg,
        globals=globals(),
        locals=locals())
예제 #5
0
"""
Demonstrate an extremely simple audio encoder that learns basis functions for
individual audio frames from a corpus of data
"""

import featureflow as ff
import zounds
from random import choice

samplerate = zounds.SR11025()
STFT = zounds.stft(resample_to=samplerate)


class Settings(ff.PersistenceSettings):
    """
    These settings make it possible to specify an id (rather than automatically
    generating one) when analyzing a file, so that it's easier to reference
    them later.
    """
    id_provider = ff.UserSpecifiedIdProvider(key='_id')
    key_builder = ff.StringDelimitedKeyBuilder()
    database = ff.LmdbDatabase(
            'mdct_synth', map_size=1e10, key_builder=key_builder)


class Document(STFT, Settings):
    """
    Inherit from a basic processing graph, and add a Modified Discrete Cosine
    Transform feature
    """
    mdct = zounds.ArrayWithUnitsFeature(
예제 #6
0
import zounds
from zounds.spectral import time_stretch, pitch_shift
from zounds.ui import AppSettings
import argparse

sr = zounds.SR11025()
BaseModel = zounds.stft(resample_to=sr, store_resampled=True)


@zounds.simple_in_memory_settings
class Sound(BaseModel):
    pass


if __name__ == '__main__':
    parser = argparse.ArgumentParser(parents=[AppSettings()])
    parser.add_argument(
        '--sound-uri',
        default=
        'https://archive.org/download/LucaBrasi2/06-Kevin_Gates-Out_The_Mud_Prod_By_The_Runners_The_Monarch.ogg'
    )
    args = parser.parse_args()

    _id = Sound.process(meta=args.sound_uri)
    snd = Sound(_id)

    original = snd.resampled
    slow = zounds.AudioSamples(time_stretch(original, 0.75).squeeze(), sr)
    fast = zounds.AudioSamples(time_stretch(original, 1.25).squeeze(), sr)

    higher = zounds.AudioSamples(pitch_shift(original, 1.0).squeeze(), sr)
예제 #7
0
"""
Demonstrate how to build a hamming-distance index over a binary/bit-packed
feature.

This example is particularly handy for performance profiling of the hamming
index.
"""

import zounds
import numpy as np

samplerate = zounds.SR11025()
BaseModel = zounds.stft(resample_to=samplerate, store_resampled=False)


def produce_fake_hash(x):
    """
    Produce random, binary features, totally irrespective of the content of
    x, but in the same shape as x.
    """
    h = np.random.binomial(1, 0.5, (x.shape[0], 1024))
    packed = np.packbits(h, axis=-1).view(np.uint64)
    return zounds.ArrayWithUnits(
        packed, [x.dimensions[0], zounds.IdentityDimension()])


@zounds.simple_lmdb_settings(
    'hamming_index', map_size=1e11, user_supplied_id=True)
class Sound(BaseModel):

    fake_hash = zounds.ArrayWithUnitsFeature(
예제 #8
0
"""
Demonstrate how to download and process sounds from https://freesound.org
"""

import zounds
import argparse

BaseModel = zounds.stft(resample_to=zounds.SR11025())


@zounds.simple_lmdb_settings('freesound', map_size=1e10, user_supplied_id=True)
class Sound(BaseModel):
    bark = zounds.ArrayWithUnitsFeature(
        zounds.BarkBands,
        needs=BaseModel.fft,
        store=True)

    chroma = zounds.ArrayWithUnitsFeature(
        zounds.Chroma,
        needs=BaseModel.fft,
        store=True)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--api-key',
        help='your Freesound API key (http://freesound.org/apiv2/apply/)',
        type=str,
        required=True)
    parser.add_argument(
예제 #9
0
import argparse
import featureflow as ff
import zounds


class Settings(ff.PersistenceSettings):
    id_provider = ff.UuidProvider()
    key_builder = ff.StringDelimitedKeyBuilder()
    database = ff.LmdbDatabase(path='timbre', key_builder=key_builder)


windowing = zounds.HalfLapped()
STFT = zounds.stft(resample_to=zounds.SR22050(), wscheme=windowing)


class WithTimbre(STFT, Settings):
    bark = zounds.ConstantRateTimeSeriesFeature(
            zounds.BarkBands,
            needs=STFT.fft,
            store=True)

    bfcc = zounds.ConstantRateTimeSeriesFeature(
            zounds.BFCC,
            needs=bark,
            store=True)


@zounds.simple_settings
class BfccKmeans(ff.BaseModel):
    docs = ff.Feature(
            ff.IteratorNode,
예제 #10
0
import zounds
from zounds.spectral import time_stretch, pitch_shift
from zounds.ui import AppSettings
import argparse

sr = zounds.SR11025()
BaseModel = zounds.stft(resample_to=sr, store_resampled=True)


@zounds.simple_in_memory_settings
class Sound(BaseModel):
    pass


if __name__ == '__main__':
    parser = argparse.ArgumentParser(parents=[
        AppSettings()
    ])
    parser.add_argument(
        '--sound-uri',
        default='https://archive.org/download/LucaBrasi2/06-Kevin_Gates-Out_The_Mud_Prod_By_The_Runners_The_Monarch.ogg')
    args = parser.parse_args()

    _id = Sound.process(meta=args.sound_uri)
    snd = Sound(_id)

    original = snd.resampled
    slow = zounds.AudioSamples(time_stretch(original, 0.75).squeeze(), sr)
    fast = zounds.AudioSamples(time_stretch(original, 1.25).squeeze(), sr)

    higher = zounds.AudioSamples(pitch_shift(original, 1.0).squeeze(), sr)
예제 #11
0
This implementation differs in that it does not use the MDCT transform on the
frequency domain, as getting the overlaps just right, such that they satisfy
MDCT invertibility requirements, is tricky, and requires some low level
knowledge that zounds' Scale attempts to abstract away.

See section 3.3 Setting MDCT Sizes for information about what we're fudging/
glossing over in this implementation.  We instead use the DCT2 transform, which
makes inversion easier, at the cost of more redundancy.
"""

from __future__ import division
import zounds
import scipy

samplerate = zounds.SR11025()
BaseModel = zounds.stft(resample_to=samplerate)

windowing_func = zounds.OggVorbisWindowingFunc()

scale = zounds.GeometricScale(300, 3030, 0.05, 100)


@zounds.simple_in_memory_settings
class Document(BaseModel):
    bark = zounds.ArrayWithUnitsFeature(zounds.BarkBands,
                                        samplerate=samplerate,
                                        stop_freq_hz=samplerate.nyquist,
                                        needs=BaseModel.fft,
                                        store=True)

    long_windowed = zounds.ArrayWithUnitsFeature(
예제 #12
0
"""
Demonstrate how to build a hamming-distance index over a binary/bit-packed
feature.

This example is particularly handy for performance profiling of the hamming
index.
"""

import zounds
import numpy as np

samplerate = zounds.SR11025()
BaseModel = zounds.stft(resample_to=samplerate, store_resampled=False)


def produce_fake_hash(x):
    """
    Produce random, binary features, totally irrespective of the content of
    x, but in the same shape as x.
    """
    h = np.random.binomial(1, 0.5, (x.shape[0], 1024))
    packed = np.packbits(h, axis=-1).view(np.uint64)
    return zounds.ArrayWithUnits(
        packed, [x.dimensions[0], zounds.IdentityDimension()])


@zounds.simple_lmdb_settings('hamming_index',
                             map_size=1e11,
                             user_supplied_id=True)
class Sound(BaseModel):
예제 #13
0
This implementation differs in that it does not use the MDCT transform on the
frequency domain, as getting the overlaps just right, such that they satisfy
MDCT invertibility requirements, is tricky, and requires some low level
knowledge that zounds' Scale attempts to abstract away.

See section 3.3 Setting MDCT Sizes for information about what we're fudging/
glossing over in this implementation.  We instead use the DCT2 transform, which
makes inversion easier, at the cost of more redundancy.
"""


import zounds
import scipy

samplerate = zounds.SR11025()
BaseModel = zounds.stft(resample_to=samplerate)

windowing_func = zounds.OggVorbisWindowingFunc()

scale = zounds.GeometricScale(300, 3030, 0.05, 100)


@zounds.simple_in_memory_settings
class Document(BaseModel):
    bark = zounds.ArrayWithUnitsFeature(
        zounds.BarkBands,
        samplerate=samplerate,
        stop_freq_hz=samplerate.nyquist,
        needs=BaseModel.fft,
        store=True)