Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'end_time': fromWavDuration,
}
durationScript = common.loadPraatTemplate("psolaDurationPiecewise")
durationScript %= psolaDict
scriptFNFullPath = join(scriptPath, fromName)
open(scriptFNFullPath, "w").write(durationScript)
# Run the script
print("praat %s" % scriptFNFullPath)
common.runPraatScript(praatExe, scriptFNFullPath)
# Create the adjusted textgrids
fromTG = tgio.openTextGrid(fromTGFN)
toTG = tgio.openTextGrid(toTGFN)
fromFN = os.path.split(fromTGFN)[1]
adjustedTGFN = os.path.splitext(fromFN)[0] + ".TextGrid"
adjustedTG = morphTextgridDuration(fromTG, toTG)
adjustedTG.save(join(outputPath, adjustedTGFN))
# Plot the results if needed
if plotFlag:
# Containers
fromDurList = []
toDurList = []
actDurList = []
labelList = []
'start_time': 0,
'end_time': fromWavDuration,
}
durationScript = common.loadPraatTemplate("psolaDurationPiecewise")
durationScript %= psolaDict
scriptFNFullPath = join(scriptPath, fromName)
open(scriptFNFullPath, "w").write(durationScript)
# Run the script
print("praat %s" % scriptFNFullPath)
common.runPraatScript(praatExe, scriptFNFullPath)
# Create the adjusted textgrids
fromTG = tgio.openTextGrid(fromTGFN)
toTG = tgio.openTextGrid(toTGFN)
fromFN = os.path.split(fromTGFN)[1]
adjustedTGFN = os.path.splitext(fromFN)[0] + ".TextGrid"
adjustedTG = morphTextgridDuration(fromTG, toTG)
adjustedTG.save(join(outputPath, adjustedTGFN))
# Plot the results if needed
if plotFlag:
# Containers
fromDurList = []
toDurList = []
actDurList = []
labelList = []
fromStart += PRAAT_TIME_DIFF
ratio = (toEnd - toStart) / float((fromEnd - fromStart))
ratioTuple = (fromStart, fromEnd, ratio)
ratioTupleList.append(ratioTuple)
if len(ratioTupleList) == 0:
raise NoLabeledRegionFoundException(fromTGFN)
_psolaDuration(ratioTupleList, fromWavDuration, PRAAT_TIME_DIFF, path,
fromFN, numSteps, tierName, fromMinPitch, fromMaxPitch,
outputFolder, praatExe)
# Create the adjusted textgrids
fromTG = tgio.openTextGrid(fromTGFN)
fromFN = os.path.split(fromTGFN)[1]
adjustedTGFN = os.path.splitext(fromFN)[0] + ".TextGrid"
adjustedTG = manipulateTextgridDuration(fromTG, modFunc, filterFunc)
adjustedTG.save(join(join(path, outputFolder), adjustedTGFN))
def extractRMSIntensity(intensityAndPitchPath, textgridPath, tierName,
outputPath, nullLabel=""):
utils.makeDir(outputPath)
for fn in utils.findFiles(intensityAndPitchPath, filterExt=".txt"):
dataList = loadPitchAndTime(intensityAndPitchPath, fn)
name = os.path.splitext(fn)[0]
tgFN = join(textgridPath, name + ".TextGrid")
if not os.path.exists(tgFN):
continue
tg = tgio.openTextGrid(join(textgridPath, name + ".TextGrid"))
tier = tg.tierDict[tierName]
print(fn)
rmsIntensityList = []
for valueList, label, _, _ in getValuesForIntervals(dataList,
tier.entryList):
intensityVals = [intensityVal for _, _, intensityVal
in valueList]
intensityVals = [intensityVal for intensityVal in intensityVals
if intensityVal != 0.0]
label = label.strip()
if label == "" or label == nullLabel:
continue
loadPitchFlag,
praatExe,
praatScriptDir):
'''
Resynthesizes the pitch track from a source to a target wav file
Occurs over a three-step process.
'''
fromName = splitext(fromFN)[0]
toName = splitext(toFN)[0]
fromDuration = audio_scripts.getSoundFileDuration(join(path, fromFN))
fromTG = tgio.openTextGrid(join(path, fromName + ".TextGrid"))
toTG = tgio.openTextGrid(join(path, toName + ".TextGrid"))
# Iterative pitch tier data path
stepPitchTierPath = join(path, "stepPitchTiers")
scriptPath = join(path, "scriptPath") # Generated praat scripts path
pitchTierPath = join(path, "pitchTiers") # Pitch tier data path
stepOutputPath = join(path, "output") # The final data will be output here
for tmpPath in [scriptPath, pitchTierPath, stepPitchTierPath,
stepOutputPath]:
utils.makeDir(tmpPath)
# 1. Get the pitch tiers from the audio files
fromPitchData, toPitchData = getPitchData(pitchTierPath, path,
fromFN, toFN,
fromTG, toTG,
fromMinPitch, fromMaxPitch, toMinPitch, toMaxPitch,
loadPitchFlag,
praatExe,
praatScriptDir):
'''
Resynthesizes the pitch track from a source to a target wav file
Occurs over a three-step process.
'''
fromName = splitext(fromFN)[0]
toName = splitext(toFN)[0]
fromDuration = audio_scripts.getSoundFileDuration(join(path, fromFN))
fromTG = tgio.openTextGrid(join(path, fromName + ".TextGrid"))
toTG = tgio.openTextGrid(join(path, toName + ".TextGrid"))
# Iterative pitch tier data path
stepPitchTierPath = join(path, "stepPitchTiers")
scriptPath = join(path, "scriptPath") # Generated praat scripts path
pitchTierPath = join(path, "pitchTiers") # Pitch tier data path
stepOutputPath = join(path, "output") # The final data will be output here
for tmpPath in [scriptPath, pitchTierPath, stepPitchTierPath,
stepOutputPath]:
utils.makeDir(tmpPath)
# 1. Get the pitch tiers from the audio files
fromPitchData, toPitchData = getPitchData(pitchTierPath, path,
fromFN, toFN,
def getIntervals(fn, tierName, filterFunc=None):
'''
Get information about the 'extract' tier, used by several merge scripts
'''
if filterFunc is None:
filterFunc = lambda x: True
tg = tgio.openTextGrid(fn)
tier = tg.tierDict[tierName]
entryList = tier.entryList
if filterFunc is not None:
entryList = [entry for entry in entryList if filterFunc(entry)]
return entryList
def extractPraatPitch(intensityAndPitchPath, textgridPath, tierName,
outputPath, nullLabel=""):
utils.makeDir(outputPath)
for fn in utils.findFiles(intensityAndPitchPath, filterExt=".txt"):
dataList = loadPitchAndTime(intensityAndPitchPath, fn)
name = os.path.splitext(fn)[0]
tgFN = join(textgridPath, name + ".TextGrid")
if not os.path.exists(tgFN):
continue
tg = tgio.openTextGrid(tgFN)
tier = tg.tierDict[tierName]
pitchData = []
for valueList, label, _, _ in getValuesForIntervals(dataList,
tier.entryList):
f0Values = [f0Val for _, f0Val, _ in valueList]
label = label.strip()
if label == "" or label == nullLabel:
continue
pitchData.append(getPitchMeasures(f0Values, name,
label, True, True))
open(join(outputPath, "%s.txt" % name),
"w").write("\n".join(pitchData))