Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
start = data.index('=', start)
except ValueError:
break
timeVal, start = _getNextValue(data, start)
try:
start = data.index('=', start)
except ValueError:
break
pointVal, start = _getNextValue(data, start)
dataList.append([float(timeVal), float(pointVal), ])
po = PointObject2D(dataList, objectType, minT, maxT)
else:
data, objectType, minT, maxT = _parseShortHeader(fn)
dataList = data.split('\n')
dataList = [(float(dataList[i]), float(dataList[i + 1]))
for i in range(0, len(dataList), 2)
if dataList[i].strip() != '']
po = PointObject2D(dataList, objectType, minT, maxT)
return po
def resynthesizePitch(praatEXE, inputWavFN, pitchFN, outputWavFN,
minPitch, maxPitch, scriptFN=None, pointList=None):
'''
Resynthesizes the pitch in a wav file with the given pitch contour file
The pitch track to use can optionally be passed in as pointList. If
so, it will be saved as pitchFN for praat to be able to use.
'''
if scriptFN is None:
scriptFN = join(utils.scriptsPath, "resynthesize_pitch.praat")
if pointList is not None:
dur = audioio.WavQueryObj(inputWavFN).getDuration()
pointObj = dataio.PointObject2D(pointList,
dataio.PITCH,
0,
dur)
pointObj.save(pitchFN)
utils.runPraatScript(praatEXE, scriptFN,
[inputWavFN, pitchFN, outputWavFN,
minPitch, maxPitch])
durationParameters.append((durationParameters[-1][1] + PRAAT_TIME_DIFF,
fromWavDuration, 1))
# Create the praat script for doing duration manipulation
for stepAmount in stepList:
durationPointList = []
for start, end, ratio in durationParameters:
percentChange = 1 + (ratio - 1) * stepAmount
durationPointList.append((start, percentChange))
durationPointList.append((end, percentChange))
outputPrefix = "%s_%0.3g" % (outputName, stepAmount)
durationTierFN = join(durationTierPath,
"%s.DurationTier" % outputPrefix)
outputWavFN = join(outputPath, "%s.wav" % outputPrefix)
durationTier = dataio.PointObject2D(durationPointList, dataio.DURATION,
0, fromWavDuration)
durationTier.save(durationTierFN)
praat_scripts.resynthesizeDuration(praatEXE,
fromWavFN,
durationTierFN,
outputWavFN,
outputMinPitch, outputMaxPitch)
outputWavFN = "mary1_accented.wav"
outputPitchFN = "mary1_accented.pitch"
minPitch = 75
maxPitch = 450
if not os.path.exists(rootOutputPath):
os.mkdir(rootOutputPath)
# 1st - get pitch
piList = pitch_and_intensity.extractPI(join(root, wavFN),
join(rootOutputPath, pitchIntensityFN),
praatEXE, minPitch, maxPitch)
pitchList = [(timeV, pitchV) for timeV, pitchV, _ in piList]
dur = audioio.WavQueryObj(join(root, wavFN)).getDuration()
pointObj = dataio.PointObject2D(pitchList, dataio.PITCH, 0, dur)
pointObj.save(join(rootOutputPath, originalPitchFN))
# 2nd - get region to manipulate. Let's make the subject more emphatic!
tg = tgio.openTextgrid(join(root, "mary1.TextGrid"))
tier = tg.tierDict["words"]
start, stop, _ = tier.entryList[0] # Getting info for the first word
targetPitchList = [(timeV, pitchV) for timeV, pitchV in pitchList
if timeV >= start and timeV <= stop]
# 3rd - make manipulation
accent = modify_pitch_accent.PitchAccent(targetPitchList)
accent.addPlateau(0.05) # Peak is dragged out for 0.05 seconds
accent.adjustPeakHeight(60) # Plateau is raised by 60 hz
accent.shiftAccent(-0.03) # Recenter the plateau around the original peak
if keepPitchRange is True:
outputDataList = morph_sequence.morphRange(outputDataList,
fromPitchData)
if keepAveragePitch is True:
outputDataList = morph_sequence.morphAveragePitch(outputDataList,
fromPitchData)
if sourcePitchDataList is not None:
outputDataList.extend(nonMorphPitchData)
outputDataList.sort()
stepOutputName = "%s_%0.3g" % (outputName, stepList[i])
pitchFNFullPath = join(pitchTierPath, "%s.PitchTier" % stepOutputName)
outputFN = join(resynthesizedPath, "%s.wav" % stepOutputName)
pointObj = dataio.PointObject2D(outputDataList, dataio.PITCH,
0, fromDuration)
pointObj.save(pitchFNFullPath)
outputTime, outputVals = zip(*outputDataList)
mergedDataList.append((outputTime, outputVals))
praat_scripts.resynthesizePitch(praatEXE, fromWavFN, pitchFNFullPath,
outputFN, outputMinPitch,
outputMaxPitch)
# 4. (Optional) Plot the generated contours
if doPlotPitchSteps:
fromTime, fromVals = zip(*fromPitchData)
toTime, toVals = zip(*toPitchData)
def __init__(self, pointList, objectClass, minTime=0, maxTime=None):
assert(objectClass != POINT)
if maxTime is None:
maxTime = max([timeV for timeV, _ in pointList])
super(PointObject2D, self).__init__(pointList, objectClass,
minTime, maxTime)