Beispiel #1
0
def read_wav(wav_file, output_file):
    in_processor = RNNPianoNoteProcessor()
    peak_picking = PeakPickingProcessor(threshold=0.35,
                                        smooth=0.09,
                                        combine=0.05)
    #output = write_notes
    output = write_midi
    out_processor = [peak_picking, output]
    processor = IOProcessor(in_processor, out_processor)
    processor.process(wav_file, output_file)
def beat_extractor(queue_beat):
    kwargs = dict(
        fps=100,
        correct=True,
        infile=None,
        outfile=None,
        max_bpm=170,
        min_bpm=60,
        #nn_files = [BEATS_LSTM[0]],
        transition_lambda=100,
        num_frames=1,
        online=True,
        verbose=1)

    def beat_callback(beats, output=None):
        if len(beats) > 0:
            # Do something with the beat (for now, just print the array to stdout)
            queue_beat.put(beats[0])
            #print(beats)

    #print('Process to write betas: %s' % os.getpid())
    in_processor = RNNBeatProcessor(**kwargs)
    beat_processor = DBNBeatTrackingProcessor(**kwargs)
    out_processor = [beat_processor, beat_callback]
    processor = IOProcessor(in_processor, out_processor)
    process_online(processor, **kwargs)
Beispiel #3
0
def main():
    """ music_process """

    # define parser
    p = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='''
        python music_process.py ./data/Jian_chrous.wav -o ./data/jian_beat.txt
        ''')
    # version
    p.add_argument('--version',
                   action='version',
                   version='FDGame-music-process-0.1')
    # input/output options
    # p.add_argument('single')
    # p.add_argument('./data/Jian_chrous.wav')
    io_arguments_single(p)
    ActivationsProcessor.add_arguments(p)

    # signal processing arguments
    SignalProcessor.add_arguments(p, norm=False, gain=0)

    # peak picking arguments
    DBNBeatTrackingProcessor.add_arguments(p)
    NeuralNetworkEnsemble.add_arguments(p, nn_files=None)

    # parse arguments
    args = p.parse_args()

    # set immutable arguments
    args.fps = 100

    # print arguments
    if args.verbose:
        print(args)

    # input processor
    if args.load:
        # load the activations from file
        in_processor = ActivationsProcessor(mode='r', **vars(args))
    else:
        # use a RNN to predict the beats
        in_processor = RNNBeatProcessor(**vars(args))

    # output processor
    if args.save:
        # save the RNN beat activations to file
        out_processor = ActivationsProcessor(mode='w', **vars(args))
    else:
        # track the beats with a DBN and output them
        beat_processor = DBNBeatTrackingProcessor(**vars(args))
        out_processor = [beat_processor, write_beats]

    # create an IOProcessor
    processor = IOProcessor(in_processor, out_processor)

    # and call the processing function
    args.func(processor, **vars(args))
Beispiel #4
0
def main():
    parser = argparse.ArgumentParser("merges a csv of survey responses, and a sqlite3 database of responses.")
    parser.add_argument("dumpfile", help="The output of \"flask dumpdb --outfile=dump.json\"")
    parser.add_argument("samples", help="folder with the actual mp3 samples")
    parser.add_argument('outfile', help='output file (EX: train_dataset.npz)')
    parser.add_argument('--fps', action='store', type=float, default=100, help='frames per second [default=100]')

    args = parser.parse_args()

    trials = json.load(open(args.dumpfile, "r"))['dataset']

    data = []
    labels = []
    sample_names = []
    for trial in trials:
        final_response = [r['timestamp'] for r in trial['data']['final_response']]
        sample_url = trial['url']

        o = urlparse(sample_url)
        sample_name = os.path.split(o.path)[-1]
        preprocessor = TfRhythmicGroupingPreProcessor()

        infile = os.path.join(args.samples, sample_name)

        print(infile)

        label_processor = LabelOutputProcessor(final_response, args.fps)

        # create an IOProcessor
        processor = IOProcessor(preprocessor, label_processor)
        sample_data, sample_labels = _process((processor, infile, None, vars(args)))
        data.append(sample_data)

        if sample_data.shape != data[0].shape:
            print("Shapes do not match, ", data[0].shape, sample_data.shape, "Skipping.")
            data.pop()
            continue

        labels.append(sample_labels)
        sample_names.append(sample_name)

    np.savez(args.outfile, x=data, labels=labels, sample_names=sample_names)
Beispiel #5
0
def main():
    """DBNBeatTracker"""

    # define parser
    p = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='''
    The DBNBeatTracker.py program detects all beats in an audio file according to
    the method described in:

    "A Multi-Model Approach to Beat Tracking Considering Heterogeneous Music
     Styles"
    Sebastian Böck, Florian Krebs and Gerhard Widmer.
    Proceedings of the 15th International Society for Music Information
    Retrieval Conference (ISMIR), 2014.

    It does not use the multi-model (Section 2.2.) and selection stage (Section
    2.3), i.e. this version corresponds to the pure DBN version of the
    algorithm for which results are given in Table 2.

    Instead of the originally proposed state space and transition model for the
    DBN, the following is used:

    "An Efficient State Space Model for Joint Tempo and Meter Tracking"
    Florian Krebs, Sebastian Böck and Gerhard Widmer.
    Proceedings of the 16th International Society for Music Information
    Retrieval Conference (ISMIR), 2015.

    This program can be run in 'single' file mode to process a single audio
    file and write the detected beats to STDOUT or the given output file.

      $ DBNBeatTracker.py single INFILE [-o OUTFILE]

    If multiple audio files should be processed, the program can also be run
    in 'batch' mode to save the detected beats to files with the given suffix.

      $ DBNBeatTracker.py batch [-o OUTPUT_DIR] [-s OUTPUT_SUFFIX] FILES

    If no output directory is given, the program writes the files with the
    detected beats to the same location as the audio files.

    The 'pickle' mode can be used to store the used parameters to be able to
    exactly reproduce experiments.

    ''')

    # version
    p.add_argument('--version',
                   action='version',
                   version='DBNBeatTracker.py.2016')
    # input/output options
    io_arguments(p, output_suffix='.beats.txt', online=True)
    ActivationsProcessor.add_arguments(p)
    # signal processing arguments
    SignalProcessor.add_arguments(p, norm=False, gain=0)
    # peak picking arguments
    DBNBeatTrackingProcessor.add_arguments(p)
    NeuralNetworkEnsemble.add_arguments(p, nn_files=None)

    # parse arguments
    args = p.parse_args()

    # set immutable arguments
    args.fps = 100

    # print arguments
    if args.verbose:
        print(args)

    # input processor
    if args.load:
        # load the activations from file
        in_processor = ActivationsProcessor(mode='r', **vars(args))
    else:
        # use a RNN to predict the beats
        in_processor = RNNBeatProcessor(**vars(args))

    # output processor
    if args.save:
        # save the RNN beat activations to file
        out_processor = ActivationsProcessor(mode='w', **vars(args))
    else:
        # track the beats with a DBN
        beat_processor = DBNBeatTrackingProcessor(**vars(args))
        # output handler
        from madmom.utils import write_events as writer
        # sequentially process everything
        out_processor = [beat_processor, writer]

    # create an IOProcessor
    processor = IOProcessor(in_processor, out_processor)
    # and call the processing function
    args.func(processor, **vars(args))
def main():
    """DBNBeatTracker"""

    # define parser
    p = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='''
    The DBNBeatTracker program detects all beats in an audio file according to
    the method described in:

    "A Multi-Model Approach to Beat Tracking Considering Heterogeneous Music
     Styles"
    Sebastian Böck, Florian Krebs and Gerhard Widmer.
    Proceedings of the 15th International Society for Music Information
    Retrieval Conference (ISMIR), 2014.

    It does not use the multi-model (Section 2.2.) and selection stage (Section
    2.3), i.e. this version corresponds to the pure DBN version of the
    algorithm for which results are given in Table 2.

    Instead of the originally proposed state space and transition model for the
    DBN, the following is used:

    "An Efficient State Space Model for Joint Tempo and Meter Tracking"
    Florian Krebs, Sebastian Böck and Gerhard Widmer.
    Proceedings of the 16th International Society for Music Information
    Retrieval Conference (ISMIR), 2015.

    This program can be run in 'single' file mode to process a single audio
    file and write the detected beats to STDOUT or the given output file.

      $ DBNBeatTracker single INFILE [-o OUTFILE]

    If multiple audio files should be processed, the program can also be run
    in 'batch' mode to save the detected beats to files with the given suffix.

      $ DBNBeatTracker batch [-o OUTPUT_DIR] [-s OUTPUT_SUFFIX] FILES

    If no output directory is given, the program writes the files with the
    detected beats to the same location as the audio files.

    The 'pickle' mode can be used to store the used parameters to be able to
    exactly reproduce experiments.

    ''')
    # version
    p.add_argument('--version',
                   action='version',
                   version='DBNBeatTracker.2016')
    # input/output options
    io_arguments(p, output_suffix='.beats.txt', online=True)
    ActivationsProcessor.add_arguments(p)
    # signal processing arguments
    SignalProcessor.add_arguments(p, norm=False, gain=0)
    # peak picking arguments
    DBNBeatTrackingProcessor.add_arguments(p)
    NeuralNetworkEnsemble.add_arguments(p, nn_files=None)

    # parse arguments
    args = p.parse_args()

    # set immutable arguments
    args.fps = 100

    # print arguments
    if args.verbose:
        print(args)
    print("The following mesxxsage shows the args :\n", args,
          "\n\n\nshows the vars(args) message:\n", vars(args))
    ''' 
    The args's message:

    Namespace(correct=True, fps=100, func=<function process_online at 0x00000000055E9AC8>, 
    gain=0, infile=None, load=False, max_bpm=215.0, min_bpm=55.0, nn_files=None, norm=False,
     num_frames=1, num_tempi=None, num_threads=1, observation_lambda=16, online=True, 
     origin='stream', outfile=<open file '<stdout>', mode 'w' at 0x0000000002DFB0C0>,
      save=False, sep=None, threshold=0, transition_lambda=100, verbose=None)
    '''

    # input processor
    if args.load:
        # load the activations from file
        in_processor = ActivationsProcessor(mode='r', **vars(args))
    else:
        # use a RNN to predict the beats
        in_processor = RNNBeatProcessor(**vars(args))

    # output processor
    if args.save:
        # save the RNN beat activations to file
        out_processor = ActivationsProcessor(mode='w', **vars(args))
    else:

        # track the beats with a DBN and output them
        beat_processor = DBNBeatTrackingProcessor(**vars(args))
        out_processor = [beat_processor, write_beats]
        print("ok")

    # create an IOProcessor
    processor = IOProcessor(in_processor, out_processor)

    # and call the processing function
    args.func(processor, **vars(args))
Beispiel #7
0
          "Otherwise the model's performance will be very poor.\n")

    # initialize network
    print("Initializing tagging network ...")
    model = select_model(args.model)
    net = model.build_model(batch_size=1)

    # initialize neural network
    TAGGER = Network(net, print_architecture=False)

    # load model parameters network
    if args.params is not None:
        dump_file = args.params
    else:
        out_path = os.path.join(os.path.join(EXP_ROOT), model.EXP_NAME)
        dump_file, log_file = get_dump_file_paths(out_path, 1)
        dump_file = dump_file.replace(".pkl", "_it0.pkl")
    print("Loading model from: %s" % dump_file)
    TAGGER.load(dump_file)

    # set prediction rate
    PREDICT_EVERY_K = args.predict_every_k

    # dummy prediction to compile model
    print("Compiling prediction function ...")
    TAGGER.predict(SLIDING_WINDOW[np.newaxis, np.newaxis])

    print("Starting prediction loop ...")
    processor = IOProcessor(in_processor=processor_pipeline2, out_processor=output_processor)
    process_online(processor, infile=None, outfile=None, sample_rate=32000)
Beispiel #8
0
def main():
    parser = argparse.ArgumentParser(
        "merges a csv of survey responses, and a sqlite3 database of responses."
    )
    parser.add_argument(
        "dumpfile", help="The output of \"flask dumpdb --outfile=dump.json\"")
    parser.add_argument("samples", help="folder with the actual mp3 samples")
    parser.add_argument('outfile', help='output file (EX: train_dataset.npz)')
    parser.add_argument('--fps',
                        action='store',
                        type=float,
                        default=100,
                        help='frames per second [default=100]')

    args = parser.parse_args()

    experiments = util.load_by_url(args.dumpfile)
    responses_by_url = util.get_final_responses_list(experiments)

    # trials = json.load(open(args.dumpfile, "r"))['dataset']

    n_features = 314
    n_frames = 800
    data = []
    labels = []
    sample_names = []
    for sample_url, final_responses in responses_by_url.items():

        o = urlparse(sample_url)
        sample_name = os.path.split(o.path)[-1]
        preprocessor = TfRhythmicGroupingPreProcessor()

        infile = os.path.join(args.samples, sample_name)

        print(infile)

        label_processor = LabelOutputProcessor(final_responses, args.fps)

        # create an IOProcessor
        processor = IOProcessor(preprocessor, label_processor)
        sample_data, sample_labels = _process(
            (processor, infile, None, vars(args)))

        if sample_data.shape[0] < n_frames or sample_data.shape[
                1] != n_features:
            print("SKIPPING: Shapes is {} but it must be (>={}, {}), ".format(
                sample_data.shape, n_frames, n_features))
            continue

        sample_data = np.expand_dims(sample_data, axis=2)
        data.append(sample_data[:n_frames])
        labels.append(sample_labels[:n_frames])
        sample_names.append(sample_name)

    print("DATASET:")
    print('{} clips'.format(len(data)))
    print('{} frames of audio at {} fps'.format(n_frames, args.fps))
    print('{} features per frame'.format(n_features))
    print("saving {} ...".format(args.outfile))

    data = np.array(data)
    labels = np.array(labels)
    np.savez(args.outfile, x=data, labels=labels, sample_names=sample_names)

    print("done.")