Beispiel #1
0
    def getSpanOffsetByChannel(self, mfcc):
        output = []
        for i in range(len(mfcc[:, 1])):
            span = max(mfcc[i, :].ravel()) - min(mfcc[i, :].ravel())
            offset = (span / 2.0) - max(mfcc[i, :].ravel())
            output.append((span, offset))
        return output


if __name__ == "__main__":
    import numpy as np

    testFile1 = "../tests/testSong1Original.wav"
    testFile2 = "../tests/testSong2Synth.wav"

    h = Hearing(tutorsong=None)
    mfcc1 = h.calcMfcc(testFile1)
    mfcc2 = h.calcMfcc(testFile2)

    mfccZero = np.zeros([3, 22])
    mfccMin = np.full([3, 22], max(mfcc1.ravel()))

    mfccRandom = (np.random.rand(3, 23) * 2 - 1) * 150
    mfccRandom2 = (np.random.rand(3, 23) * 2 - 1) * 150

    tutorsong = np.concatenate((mfcc1, mfcc1, mfcc1, mfcc1, mfcc1), axis=1)
    syllablesMfccs = [
        mfcc1,
        mfcc2,
        mfccZero,
        mfccRandom,
Beispiel #2
0
from architecture.components.hearing import Hearing
import numpy as np
from sklearn.decomposition import PCA


if __name__ == "__main__":
    # testfiles = [
    #     "./testSong1Original.wav",
    #     "./testSong2Synth.wav"
    # ]
    testfiles = []
    for i in range(12):
        testfiles.append("./testpattern-{i}.wav".format(i=i))
    h = Hearing(channels=12)
    dataTmp = []
    for f in testfiles:
        mfcc = h.calcMfcc(f)
        dataTmp.append(mfcc.T)

    data = np.concatenate(dataTmp)
    print "data shape:",data.shape


    pca = PCA(n_components=12)
    pca.fit(data)
    print(pca.explained_variance_ratio_)




Beispiel #3
0
    [0.1, 0.1, 0.1, 0.1, 100, -10, 0.1, 0.1, 0.1, 100, 0.25],
    [10, 10, 10, 10, 10, -10, 10, 10, 10, 10, 0.25],
    [1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 0.25],
    [0.0001, 0.0001, 0.0001, 0.0001, 0.0001, -0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.25]
]

testfiles = [
    "./testpattern-0.wav",
    "./testpattern-2.wav",
    "./testpattern-3.wav",
    "./testpattern-4.wav",
    "./testpattern-6.wav",
    "./testpattern-7.wav"
]

h = Hearing(tutorsong=None)
mfccs = []

for tf in testfiles:
    mfcc = h.calcMfcc(tf)
    mfccs.append(mfcc)

# for mfcc in mfccs:
#     print mfcc.shape

trainingDataInput = []
trainingDataOutput = []

for patternIndex in range(len(patterns)):
    mfccLen = getMfccLen(patterns[patternIndex][-1])
    for i in range(mfccLen):
        def outputStream(content):
            global output
            output.append(content)


        ss = SoundSynthesizer(inputStream, outputStream)
        ss.synthesize()

        d2w = Dat2Wav
        sound = d2w.convert(output)
        d2w.writeWAV(sound, filehandleTemp, 44100)

        print "done synthing, now creating data"

        h = Hearing(tutorsong=None)
        mfcc = h.calcMfcc(filehandleTemp)

        for mfccIndex in range(len(mfcc[1, :])):

            patternStr = [str(p) for p in pattern]
            filehandleInputs.write(",".join([str(mfccIndex)] + patternStr) + "\n")

            mfccStr = [str(m) for m in mfcc[:, mfccIndex]]
            filehandleOutputs.write(",".join(mfccStr) + "\n")

        os.remove(filehandleTemp)

        print "done writing data\n"

    filehandleInputs.close()