def getChords(spectra): chords = [] for chromum in getChroma(spectra): chord, score = Pitch.getChord(chromum) chords.append(chord) return chords
def writeCsv(sampling,frames,output): csvfile = open(output, 'wb'); writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL); writer.writerow(["Timestamp", "ZCR", "Spectrum Variance", "RMS", "STE", "Pitch", "ZCR diff.", "Spec. Var. diff.", "RMS diff.", "STE diff."]); prev_zcr = 0.; prev_var = 0.; prev_rms = 0.; prev_ste = 0.; for i in xrange(0,len(frames)): windowSize = len(frames[i]) - 1 timestamp = "%0.3f" % (sampling[i] / float(freq)) chord, score = Pitch.getChord(frames[i].spectrum().chroma()) diff_zcr = frames[i].zcr() - prev_zcr; diff_var = frames[i].spectrum().variance() - prev_var; diff_rms = frames[i].rms() - prev_rms; diff_ste = frames[i].energy(windowSize)[0] - prev_ste; row = [timestamp, frames[i].zcr(), frames[i].spectrum().variance(), frames[i].rms(), frames[i].energy(windowSize)[0], score, diff_zcr, diff_var, diff_rms, diff_ste]; writer.writerow(row); prev_zcr = frames[i].zcr(); prev_var = frames[i].spectrum().variance(); prev_rms = frames[i].rms(); prev_ste = frames[i].energy(windowSize)[0]; print "The result is written on %s" % output
print o print "Extracting Frames" frames = audiofile.framesFromOnsets(o) #for i in range(0, len(frames)): # print "Frame " + str(i) # plt.plot(frames[i]) # plt.show() #frameSize = 16384 #frames = audioFile.frames(frameSize) print "Start | End | Chord | (% match)" print "-------------------------------" frameIndex = 0 startIndex = 0 for frame in frames: spectrum = frame.spectrum() chroma = spectrum.chroma() chord, score = Pitch.getChord(chroma) endIndex = startIndex + len(frame) startTime = startIndex / frame.sampleRate endTime = endIndex / frame.sampleRate print "%.2f | %.2f | %-4s | (%.2f)" % (startTime, endTime, chord, score) frameIndex = frameIndex + 1 startIndex = startIndex + len(frame)
print "Extracting Frames" frames = audiofile.framesFromOnsets(o) #for i in range(0, len(frames)): # print "Frame " + str(i) # plt.plot(frames[i]) # plt.show() #frameSize = 16384 #frames = audioFile.frames(frameSize) print "Start | End | Chord | (% match)" print "-------------------------------" frameIndex = 0 startIndex = 0 for frame in frames: spectrum = frame.spectrum() chroma = spectrum.chroma() print chroma chord, score = Pitch.getChord(chroma) endIndex = startIndex + len(frame) startTime = startIndex / frame.sampleRate endTime = endIndex / frame.sampleRate print "%.2f | %.2f | %-4s | (%.2f)" % (startTime, endTime, chord, score) frameIndex = frameIndex + 1 startIndex = startIndex + len(frame)