def pyin(filename, inputSampleRate=44100, channels=1, frame_length=2048, hop_length=256, lowAmp=0.25, onsetSensitivity=0.7, pruneThresh=0.1): audio, fs = librosa.load(filename, sr=inputSampleRate) pYinInst = pYINmain.PyinMain() pYinInst.initialise(channels=channels, inputSampleRate=inputSampleRate, stepSize=hop_length, blockSize=frame_length, lowAmp=lowAmp, onsetSensitivity=onsetSensitivity, pruneThresh=pruneThresh) pYinInst.m_yin.m_yinBufferSize = int(frame_length / 2) all_frames = librosa.util.frame(audio, frame_length=frame_length, hop_length=hop_length) rmslist = [] for frame in all_frames.T: fs, rms = pYinInst.process(frame) rmslist.append(rms) monoPitch = pYinInst.getSmoothedPitchTrack() pitchlist = [ii.values for ii in fs.m_oSmoothedPitchTrack] return np.array(pitchlist), np.array(rmslist)
def pYINPtNote(filename1,fs=44100,frameSize=2048,hopSize=256): ''' Given filename, return pitchtrack and note transcription track :param filename1: :param fs: :param frameSize: :param hopSize: :return: ''' # initialise pYinInst = pYINmain.PyinMain() pYinInst.initialise(channels = 1, inputSampleRate = fs, stepSize = hopSize, blockSize = frameSize, lowAmp = 0.25, onsetSensitivity = 0.7, pruneThresh = 0.1) # frame-wise calculation audio = ess.MonoLoader(filename = filename1, sampleRate = fs)() # rms mean # rms = [] # for frame in ess.FrameGenerator(audio, frameSize=frameSize, hopSize=hopSize): # rms.append(RMS(frame, frameSize)) # rmsMean = np.mean(rms) # print 'rmsMean', rmsMean for frame in ess.FrameGenerator(audio, frameSize=frameSize, hopSize=hopSize): fs = pYinInst.process(frame) # calculate smoothed pitch and mono note monoPitch = pYinInst.getSmoothedPitchTrack() # output smoothed pitch track print('pitch track') for ii in fs.m_oSmoothedPitchTrack: print(ii.values) print('\n') fs = pYinInst.getRemainingFeatures(monoPitch) # output of mono notes, # column 0: frame number, # column 1: pitch in midi numuber, this is the decoded pitch # column 2: attack 1, stable 2, silence 3 print('mono note decoded pitch') for ii in fs.m_oMonoNoteOut: print(ii.frameNumber, ii.pitch, ii.noteState) print('\n') print('note pitch tracks') for ii in fs.m_oNotePitchTracks: print(ii) print('\n') # median pitch in Hz of the notes print('median note pitch') for ii in fs.m_oNotes: print(ii.values) print('\n')
def plot(self,canvas,a,b): global filename filename = tkFileDialog.askopenfilename() f_s, afAudioData = wavfile.read(filename) afAudioData = afAudioData.astype(np.float) #convert to float # Normalizing and Downsizing File if (len(afAudioData.shape) > 1): afAudioData = afAudioData.mean(axis = 1) if (len(afAudioData) > 1): afAudioData = afAudioData/max(abs(afAudioData)) c = ['r','b','g'] # plot marker colors a.clear() # clear axes from previous plot a.plot((np.arange(0,len(afAudioData)).astype(float))/f_s, afAudioData) # create pYIN Object pYinInst = pYINmain.PyinMain() pYinInst.initialise(channels = 1, inputSampleRate = f_s, stepSize = hopSize, blockSize = frameSize, lowAmp = 0.25, onsetSensitivity = 0.7, pruneThresh = 0.1) fstart_vec = np.array(range(0,len(afAudioData)-frameSize, hopSize)) for fstart in fstart_vec: if fstart+frameSize <= len(afAudioData): frame = afAudioData[fstart:fstart+frameSize] else: frame = afAudioData[fstart:end] fs = pYinInst.process(frame) monoPitch = pYinInst.getSmoothedPitchTrack() pitches = [] for ii in fs.m_oSmoothedPitchTrack: pitches = np.concatenate((pitches,ii.values), axis=0) p = 69 + 12 * np.log2(abs(pitches)/440) x = fstart_vec.astype(float)/float(f_s) b.plot(x,p) # b.yticks(np.arange(min(pitches), max(pitches)+1, 1.0)) #b.yaxis.set_major_locator(plt.MaxNLocator(3)) canvas.draw()
sys.path.append(srcpath) import pYINmain import essentia.standard as ess import numpy as np from YinUtil import RMS if __name__ == "__main__": # initialise filename1 = srcpath + '/testAudioLong.wav' fs = 44100 frameSize = 2048 hopSize = 256 pYinInst = pYINmain.PyinMain() pYinInst.initialise(channels=1, inputSampleRate=fs, stepSize=hopSize, blockSize=frameSize, lowAmp=0.25, onsetSensitivity=0.7, pruneThresh=0.1) # frame-wise calculation audio = ess.MonoLoader(filename=filename1, sampleRate=fs)() # rms mean # rms = [] # for frame in ess.FrameGenerator(audio, frameSize=frameSize, hopSize=hopSize): # rms.append(RMS(frame, frameSize))