Пример #1
0
    dirname = os.path.normpath(sys.argv[1])
    seq = sequencer.Sequencer() #create a sequencer to handle midi input


    tracks = glob.glob(os.path.join(dirname, '*.mid')) #match any midi file
    for t in tracks:
        track = os.path.splitext(t)[0]
        # sequence MIDI to saw + sine melody
        print "Sequencing %s..." %track
        wavData = seq.parseMidiFile("%s.mid" %track)
        sawData = wavData[0]
        melodyData = wavData[1]


        print "Saving %s... wav and melody" %track
        wave_gen.saveAudioBuffer("%s.wav" %track, sawData)
        wave_gen.saveAudioBuffer("%smelody.wav" %track, melodyData)

        print "Generating feature data..."
        data = wave_reader.wavToFeatures("%s.wav" %track)
        melody = wave_reader.wavToFeatures("%smelody.wav" %track)
        labels = melody.argmax(axis=1) #axis=1, max frequency across a sample
        numData = min(data.shape[0],labels.shape[0])
        data = data[0:numData,]
        labels = labels[0:numData]
        matrix = numpy.concatenate([data, numpy.array([labels]).T], axis=1) #horizontal concatenate
        saveFile('%sdata.csv' %track, matrix)

        seq.resetSequencer()

Пример #2
0
import numpy
from pybrain.tools.customxml import NetworkWriter, NetworkReader
import sys
import os
import wave_gen
import wave_reader
import midi_util

# Script to test a trained neural net on a wav file (000106b_.wav)
#produces a result wav so you can listen to the prediction
if __name__ == '__main__':
    dirname = os.path.normpath(sys.argv[1])
    #track = os.path.join(dirname, '000106b_.wav')

    print "Reading wav into input data..."
    data = wave_reader.wavToFeatures('000106b_.wav')
    numData = data.shape[0]
    labels = numpy.zeros(numData)

    print "Reloading neural network..."
    net = NetworkReader.readFrom(os.path.basename(dirname) + 'designnet')

    print "Activating neural network..."
    for i in range(numData):
        labels[i] = net.activate(data[i])

    print "Generating result wav..."
    cdata = numpy.array([])
    for label in labels:
        #if(freq > 0):
        #    freq = midi_util.frequencyToNoteFrequency(label)