def test_pitch_io(self): '''Tests for reading/writing pitch tiers''' fn = "mary.PitchTier" inputFN = join(self.dataRoot, fn) outputFN = join(self.outputRoot, fn) pp = dataio.open2DPointObject(inputFN) pp.save(outputFN) self.assertTrue(areTheSame(inputFN, outputFN, dataio.open2DPointObject))
def test_duration_tier_io(self): '''Tests for reading/writing duration tiers''' fn = "mary.DurationTier" inputFN = join(self.dataRoot, fn) outputFN = join(self.outputRoot, fn) dt = dataio.open2DPointObject(inputFN) dt.save(outputFN) self.assertTrue(areTheSame(inputFN, outputFN, dataio.open2DPointObject))
def extractPitchTier(wavFN, outputFN, praatEXE, minPitch, maxPitch, sampleStep=0.01, silenceThreshold=0.03, forceRegenerate=True, medianFilterWindowSize=0, pitchQuadInterp=False): ''' Extract pitch at regular intervals from the input wav file Data is output to a text file and then returned in a list in the form [(timeV1, pitchV1), (timeV2, pitchV2), ...] sampleStep - the frequency to sample pitch at silenceThreshold - segments with lower intensity won't be analyzed for pitch forceRegenerate - if running this function for the same file, if False just read in the existing pitch file pitchQuadInterp - if True, quadratically interpolate pitch ''' outputPath = os.path.split(outputFN)[0] utils.makeDir(outputPath) if pitchQuadInterp is True: doInterpolation = 1 else: doInterpolation = 0 assert (os.path.exists(wavFN)) firstTime = not os.path.exists(outputFN) if firstTime or forceRegenerate is True: if os.path.exists(outputFN): os.remove(outputFN) argList = [ wavFN, outputFN, sampleStep, minPitch, maxPitch, silenceThreshold, medianFilterWindowSize, doInterpolation ] scriptName = "get_pitchtier.praat" scriptFN = join(utils.scriptsPath, scriptName) utils.runPraatScript(praatEXE, scriptFN, argList) pitchTier = dataio.open2DPointObject(outputFN) return pitchTier
def extractPitchTier(wavFN, outputFN, praatEXE, minPitch, maxPitch, sampleStep=0.01, silenceThreshold=0.03, forceRegenerate=True, medianFilterWindowSize=0, pitchQuadInterp=False): ''' Extract pitch at regular intervals from the input wav file Data is output to a text file and then returned in a list in the form [(timeV1, pitchV1), (timeV2, pitchV2), ...] sampleStep - the frequency to sample pitch at silenceThreshold - segments with lower intensity won't be analyzed for pitch forceRegenerate - if running this function for the same file, if False just read in the existing pitch file pitchQuadInterp - if True, quadratically interpolate pitch ''' outputPath = os.path.split(outputFN)[0] utils.makeDir(outputPath) if pitchQuadInterp is True: doInterpolation = 1 else: doInterpolation = 0 assert(os.path.exists(wavFN)) firstTime = not os.path.exists(outputFN) if firstTime or forceRegenerate is True: if os.path.exists(outputFN): os.remove(outputFN) argList = [wavFN, outputFN, sampleStep, minPitch, maxPitch, silenceThreshold, medianFilterWindowSize, doInterpolation] scriptName = "get_pitchtier.praat" scriptFN = join(utils.scriptsPath, scriptName) utils.runPraatScript(praatEXE, scriptFN, argList) pitchTier = dataio.open2DPointObject(outputFN) return pitchTier
fromWavFN = fromName + ".wav" fromPitchFN = fromName + ".txt" fromTGFN = join(root, fromName + ".TextGrid") toName = "mary1_stylized" toPitchFN = toName + ".PitchTier" # Prepare the data for morphing # 1st load it into memory fromPitchList = pitch_and_intensity.audioToPI(root, fromWavFN, root, fromPitchFN, praatEXE, minPitch, maxPitch, forceRegenerate=False) fromPitchList = [(time, pitch) for time, pitch, _ in fromPitchList] # Load in the target pitch contour pitchTier = dataio.open2DPointObject(join(root, toPitchFN)) toPitchList = [(time, pitch) for time, pitch in pitchTier.pointList] # The target contour doesn't contain enough sample points, so interpolate # over the provided samples # (this step can be skipped if there are enough sample points--a warning # will be issued if there are any potential problems) toPitchList = interpolation.quadraticInterpolation(toPitchList, 4, 1000, 0) # 3rd select which sections to align. # We'll use textgrids for this purpose. tierName = "PhonAlign" fromPitch = f0_morph.getPitchForIntervals(fromPitchList, fromTGFN, tierName) toPitch = f0_morph.getPitchForIntervals(toPitchList, fromTGFN, tierName) # Run the morph process