Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
atZeroCrossing=True):
utils.makeDir(outputPath)
wavFN = os.path.split(inputWavFN)[1]
tgFN = os.path.split(inputTGFN)[1]
outputWavFN = join(outputPath, wavFN)
outputTGFN = join(outputPath, tgFN)
if atZeroCrossing is True:
zeroCrossingTGPath = join(outputPath, "zero_crossing_tgs")
zeroCrossingTGFN = join(zeroCrossingTGPath, tgFN)
utils.makeDir(zeroCrossingTGPath)
tg = tgio.openTextgrid(inputTGFN)
wavObj = audioio.WavQueryObj(inputWavFN)
praatio_scripts.tgBoundariesToZeroCrossings(tg,
wavObj,
zeroCrossingTGFN)
else:
tg = tgio.openTextgrid(inputTGFN)
keepList = tg.tierDict["phone"].entryList
keepList = [entry for entry in keepList
if not isVowel(entry[2])]
deleteList = utils.invertIntervalList(keepList, tg.maxTimestamp)
wavObj = audioio.openAudioFile(inputWavFN,
keepList=keepList,
doShrink=doShrink)
outputWavFN = join(outputPath, wavFN)
# Find the word(s) to anonymize
# (One could imagine a search for common names or identification of
# some sort of code ('section-to-anonymize') rather than what I have
# done here.
deleteList = []
tg = tgio.openTextgrid(join(path, tgFN))
deleteList.append(tg.tierDict['word'].entryList[0])
# Get only time information from entries (i.e. remove label information)
deleteList = [(start, stop) for start, stop, _ in deleteList]
# Replace segments with a sine wave
wavQObj = audioio.WavQueryObj(join(path, wavFN))
wavQObj.deleteWavSections(outputWavFN,
deleteList=deleteList,
operation="sine wave")
wordList = [word for _, _, word in entryList]
multipleInstList = []
for word in set(wordList):
if wordList.count(word) > 1:
multipleInstList.append(word)
if len(multipleInstList) > 0:
instListTxt = "\n".join(multipleInstList)
print(("Overwriting wave files in: %s\n" +
"Intervals exist with the same name:\n%s")
% (outputPath, instListTxt))
firstWarning = False
# Output wave files
outputFNList = []
wavQObj = audioio.WavQueryObj(wavFN)
for i, entry in enumerate(entryList):
start, stop, label = entry
# Resolve output name
outputName = outputTemplate % i
if nameStyle == "append":
outputName += "_" + label
elif nameStyle == "append_no_i":
outputName = name + "_" + label
elif nameStyle == "label":
outputName = label
outputFNFullPath = join(outputPath, outputName + ".wav")
if os.path.exists(outputFNFullPath) and firstWarning:
print(("Overwriting wave files in: %s\n" +
originalPitchFN = "mary1.pitch"
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
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])
tg = tgio.openTextgrid(inputTGFN)
wavObj = audioio.WavQueryObj(inputWavFN)
praatio_scripts.tgBoundariesToZeroCrossings(tg,
wavObj,
zeroCrossingTGFN)
else:
tg = tgio.openTextgrid(inputTGFN)
keepList = tg.tierDict["phone"].entryList
keepList = [entry for entry in keepList
if not isVowel(entry[2])]
deleteList = utils.invertIntervalList(keepList, tg.maxTimestamp)
wavObj = audioio.openAudioFile(inputWavFN,
keepList=keepList,
doShrink=doShrink)
wavObj.save(outputWavFN)
shrunkTG = copy.deepcopy(tg)
for start, stop in sorted(deleteList, reverse=True):
shrunkTG = shrunkTG.eraseRegion(start, stop, doShrink=doShrink)
shrunkTG.save(outputTGFN)
outputAudioFN = join(outputPath, "barry_spliced.wav")
outputTGFN = join(outputPath, "barry_spliced.TextGrid")
tierName = "phone"
if not os.path.exists(outputPath):
os.mkdir(outputPath)
# Find the region to replace and the region that we'll replace it with
tg = tgio.openTextgrid(tgFN)
tier = tg.tierDict[tierName]
mEntry = tier.entryList[tier.find('m')[0]]
bEntry = tier.entryList[tier.find('b')[0]]
sourceAudioObj = audioio.openAudioFile(audioFN)
mAudioObj = sourceAudioObj.getSubsegment(mEntry[0], mEntry[1])
bAudioObj = sourceAudioObj.getSubsegment(bEntry[0], bEntry[1])
# Replace 'm' with 'b'
audioObj, tg = praatio_scripts.audioSplice(sourceAudioObj,
bAudioObj,
tg,
tierName,
"b",
mEntry[0],
mEntry[1])
# Replace 'b' with 'm'
# The times are now different, so we have to get them again
bEntry = tg.tierDict[tierName].entryList[tier.find('b')[0]]
audioObj, tg = praatio_scripts.audioSplice(audioObj,