def writeRegressionPitchtrack(self,originalPitchtrackFilename,regressionPitchtrackFilename,representation): ''' write regression pitch track :param originalPitchtrackFilename: :param regressionPitchtrackFilename: :param representation: :return: ''' if regressionPitchtrackFilename: with open(regressionPitchtrackFilename, 'w+') as outfile: # non-voice insertion representationNpArray = np.array(representation) # maxIndexRepresentation = max(representationNpArray[:,0]) frameStartingTime, originalPitchtrack = self.ptSeg1.readPyinPitchtrack(originalPitchtrackFilename) lenFrame = len(frameStartingTime) wholeIndex = range(2,int(lenFrame)+1) outfile.write('frame'+','+'time'+','+'pitch'+','+'freq'+','+'noteStr'+'\n') for wi in wholeIndex: if wi in representationNpArray[:,0]: wiIndex = np.where(representationNpArray[:,0]==wi)[0][0] value = representationNpArray[wiIndex,1] # if value is in regression pitchtrack freq = uf.midi2pitch(value) noteStr = uf.cents2pitch(uf.hz2cents(float(freq))) else: value = -100.0 # if value is NOT in regression pitchtrack freq = -100.0 noteStr = 'null' outfile.write(str(wi)+',' +str(wi*float(self.nc1.hopsize)/self.nc1.samplerate)+',' +str(value)+',' +str(freq)+',' +noteStr+'\n')
def writeRegressionPitchtrack(self,originalPitchtrackFilename,regressionPitchtrackFilename,representation): ''' write regression pitch track :param originalPitchtrackFilename: :param regressionPitchtrackFilename: :param representation: :return: ''' if regressionPitchtrackFilename: with open(regressionPitchtrackFilename, 'w+') as outfile: # non-voice insertion representationNpArray = np.array(representation) # maxIndexRepresentation = max(representationNpArray[:,0]) frameStartingTime, originalPitchtrack = self.ptSeg1.readPyinPitchtrack(originalPitchtrackFilename) lenFrame = len(frameStartingTime) wholeIndex = range(2,int(lenFrame)+1) # sonicVisualizer Index start from 2 outfile.write('frame'+','+'time'+','+'pitch'+','+'freq'+','+'noteStr'+'\n') for wi in wholeIndex: if wi in representationNpArray[:,0]: wiIndex = np.where(representationNpArray[:,0]==wi)[0][0] value = representationNpArray[wiIndex,1] # if value is in regression pitchtrack freq = uf.midi2pitch(value) noteStr = uf.cents2pitch(uf.hz2cents(float(freq))) else: value = -100.0 # if value is NOT in regression pitchtrack freq = -100.0 noteStr = 'null' outfile.write(str(wi)+',' +str(wi*float(self.nc1.hopsize)/self.nc1.samplerate)+',' +str(value)+',' +str(freq)+',' +noteStr+'\n')
def pltRepresentationHelper(self,xboundary,y,representation,pitchHz): for jj in range(len(y)): if pitchHz: yout = uf.midi2pitch(y[jj]) else: yout = y[jj] representation.append([xboundary[jj],yout]) return representation