Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def manualPhoneCount(tgInfoPath, isleFN, outputPath, skipList=None):
if skipList is None:
skipList = []
utils.makeDir(outputPath)
isleDict = isletool.LexicalTool(isleFN)
existFNList = utils.findFiles(outputPath, filterPaths=".txt")
for fn in utils.findFiles(tgInfoPath, filterExt=".txt",
skipIfNameInList=existFNList):
if os.path.exists(join(outputPath, fn)):
continue
print(fn)
dataList = utils.openCSV(tgInfoPath, fn)
dataList = [row[2] for row in dataList] # start, stop, tmpLabel
outputList = []
for tmpLabel in dataList:
if tmpLabel not in skipList:
syllableCount, phoneCount = isletool.getNumPhones(isleDict,
tmpLabel,
#encoding: utf-8
'''
Examples of how to use pysle's pronunciationtools code
'''
from os.path import join
from pysle import isletool
from pysle import pronunciationtools
root = join(".", "files")
isleDict = isletool.LexicalTool(join(root, 'ISLEdict_sample.txt'))
# In the first example we determine the syllabification of a word,
# as it was said. (Of course, this is just an estimate)
print('-' * 50)
searchWord = 'another'
anotherPhoneList = ['n', '@', 'th', 'r']
isleWordList = isleDict.lookup(searchWord)
returnList = pronunciationtools.findBestSyllabification(
isleDict, searchWord, anotherPhoneList)
(stressedSyllable, stressedPhone, syllableList, syllabification,
stressedSyllableIndexList, stressedPhoneIndexList,
flattenedStressIndexList) = returnList
print(searchWord)
print(anotherPhoneList)
print(stressedSyllableIndexList) # We can see the first syllable was elided
#encoding: utf-8
'''
Examples that use the isletool
- looking up words based on their pronunciation
- syllabifying a user-specified phone list based on a pronunciation
in the dictionary
'''
from os.path import join
from pysle import isletool
root = join(".", "files")
isleDict = isletool.LexicalTool(join(root, 'ISLEdict_sample.txt'))
# In this first example we look up the syllabification of a word and
# get it's stress information.
searchWord = 'catatonic'
lookupResults = isleDict.lookup(searchWord)
firstEntry = lookupResults[0][0]
firstSyllableList = firstEntry[0]
firstSyllableList = ".".join([u" ".join(syllable)
for syllable in firstSyllableList])
firstStressList = firstEntry[1]
print(searchWord)
print(firstSyllableList)
print(firstStressList) # 3rd syllable carries stress
def syllabifyTextgrids(tgPath, islePath):
isleDict = isletool.LexicalTool(islePath)
outputPath = join(tgPath, "syllabifiedTGs")
utils.makeDir(outputPath)
skipLabelList = ["", "xx", "", "{B_TRANS}", '{E_TRANS}']
for fn in utils.findFiles(tgPath, filterExt=".TextGrid"):
if os.path.exists(join(outputPath, fn)):
continue
tg = tgio.openTextgrid(join(tgPath, fn))
syllableTG = praattools.syllabifyTextgrid(isleDict, tg, "words",
"phones",
skipLabelList=skipLabelList)
#encoding: utf-8
'''
An example of how to syllabify a textgrid.
This code is an optional feature of pysle that requires the
praatio library.
'''
from os.path import join
from praatio import tgio
from pysle import isletool
from pysle import praattools
root = join('.', 'files')
isleDict = isletool.LexicalTool(join(root, "ISLEdict_sample.txt"))
tg = tgio.openTextgrid(join(root, "pumpkins.TextGrid"))
# Get the syllabification tiers and add it to the textgrid
syllableTG = praattools.syllabifyTextgrid(isleDict, tg, "word", "phone",
skipLabelList=["", ])
tg.addTier(syllableTG.tierDict["syllable"])
tg.addTier(syllableTG.tierDict["tonicSyllable"])
tg.addTier(syllableTG.tierDict["tonicVowel"])
tg.save(join(root, "pumpkins_with_syllables.TextGrid"))