How to use the pysle.pronunciationtools function in pysle

To help you get started, we’ve selected a few pysle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github timmahrt / pysle / examples / pronunciationtools_examples.py View on Github external
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
print(stressedPhoneIndexList)
print(flattenedStressIndexList)
print(syllableList)
print(syllabification)


# In the second example, we have a pronunciation and find the closest dictionary
# pronunciation to it
github timmahrt / pysle / pysle / praattools.py View on Github external
wordTier = wordTier.crop(startT, stopT, "truncated", False)

    for start, stop, word in wordTier.entryList:

        if word in skipLabelList:
            continue

        subPhoneTier = phoneTier.crop(start, stop, "strict", False)

        # entry = (start, stop, phone)
        phoneList = [entry[2] for entry in subPhoneTier.entryList
                     if entry[2] != '']

        try:
            sylTmp = pronunciationtools.findBestSyllabification(isleDict,
                                                                word,
                                                                phoneList)
        except isletool.WordNotInISLE:
            print("Word ('%s') not is isle -- skipping syllabification" % word)
            continue
        except pronunciationtools.NullPronunciationError:
            print("Word ('%s') has no provided pronunciation" % word)
            continue
        except AssertionError:
            print("Unable to syllabify '%s'" % word)
            continue

        stressI = sylTmp[0]
        stressJ = sylTmp[1]
        syllableList = sylTmp[2]