Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Clean up the textgrids output by SPPAS
# Rename tiers, delete tiers, and convert the phonetic tier
# from xsampa to IPA
for mergeFN in tgFNList:
mergeName = os.path.splitext(mergeFN)[0]
nonMergeName = mergeName.split('-merge')[0]
if not os.path.exists(join(outputPath, nonMergeName + ".wav")):
shutil.copy(join(tgPath, nonMergeName + ".wav"),
join(outputPath, nonMergeName + ".wav"))
if os.path.exists(join(outputPath, nonMergeName + ".TextGrid")):
print("Skipping %s -- already exists" % mergeName + ".TextGrid")
continue
# Open tg file and remove jittered boundaries
tg = praatio_scripts.alignBoundariesAcrossTiers(join(tgPath, mergeFN),
maxDifference=0.001)
# Remove tiers
for name in removeTierList:
if name in tg.tierNameList:
tg.removeTier(name)
# Rename tiers
for fromName, toName in renameTierList:
if fromName in tg.tierNameList:
tg.renameTier(fromName, toName)
# Convert phones to IPA
tg = _xsampaToIPATier(tg, "phones")
# # Typically, the start and end of a spass file is silent but an
# # utterance with only a single ipu will not acount for this. Make
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)
wavObj.save(outputWavFN)
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,
mAudioObj,
tg,
tierName,
"m",
bEntry[0],
Incorrect items are noted in a new tier and optionally
printed to the screen
'''
def checkFunc(word):
try:
isleDict.lookup(word)
except isletool.WordNotInISLE:
returnVal = False
else:
returnVal = True
return returnVal
tg = praatio_scripts.spellCheckEntries(tg, targetTierName, newTierName,
checkFunc, printEntries)
return tg
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,
mAudioObj,
tg,
tierName,
"m",
bEntry[0],
bEntry[1])
audioObj.save(outputAudioFN)
tg.save(outputTGFN)
wavList = utils.findFiles(wavPath, filterExt=".wav", stripExt=True)
for wavName in wavList:
transcriptName = nameMod(wavName)
# Add initial and final small pauses to each transcript
with io.open(join(txtPath, transcriptName + ".txt"), "r") as fd:
txt = fd.read()
if addPause is True:
txt = "+ %s +" % txt.lower()
wavFN = join(wavPath, wavName + ".wav")
dur = praatio_scripts.audioio.WavQueryObj(wavFN).getDuration()
tg = tgio.Textgrid()
tier = tgio.IntervalTier("ipu", [(0, dur, txt), ], 0, dur)
tg.addTier(tier)
tg.save(join(outputPath, wavName + ".TextGrid"))
import os
from os.path import join
from praatio import praatio_scripts
path = join(".", "files")
outputPath = join(path, "aligned-tier_textgrids")
inputFN = join(path, "mary_misaligned.TextGrid")
outputFN = join(outputPath, "mary_aligned.TextGrid")
maxDifference = 0.01
if not os.path.exists(outputPath):
os.mkdir(outputPath)
tg = praatio_scripts.alignBoundariesAcrossTiers(inputFN, maxDifference)
tg.save(outputFN)