mirror of
https://github.com/wassname/pysle.git
synced 2026-07-27 11:26:14 +08:00
FEATURE: Index to stressed vowel; marking of stressed vowels on textgrids
- the index to the stressed syllable was provided in the past. Now the library also includes the index to the stressed vowel. This is provided with relation to the phones in the syllable and all phones in the word. - the code that marks the stressed syllables in the textgrids also now marks the stressed vowels - several variables renamed to be more informative
This commit is contained in:
+5
-1
@@ -43,6 +43,10 @@ What can you do with this library?
|
||||
Major revisions
|
||||
================
|
||||
|
||||
Ver 1.3 (March 15, 2016)
|
||||
|
||||
- added indicies for stressed vowels
|
||||
|
||||
Ver 1.2 (June 20, 2015)
|
||||
|
||||
- Python 3.x support
|
||||
@@ -82,7 +86,7 @@ Installation
|
||||
If you on Windows, you can use the installer found here (check that it is up to date though)
|
||||
`Windows installer <http://www.timmahrt.com/python_installers>`_
|
||||
|
||||
Otherwise, to manually install, after downloading, from a command-line shell, navigate to the directory containing setup.py and type::
|
||||
Otherwise, to manually install, after downloading the source from github, from a command-line shell, navigate to the directory containing setup.py and type::
|
||||
|
||||
python setup.py install
|
||||
|
||||
|
||||
+12
-11
@@ -69,21 +69,22 @@ def _parsePronunciation(pronunciationStr):
|
||||
secondary stress locations
|
||||
'''
|
||||
syllableTxt = pronunciationStr.split("#")[1].strip()
|
||||
syllableList = [x for x in syllableTxt.split(' . ')]
|
||||
syllableList = [x.split() for x in syllableTxt.split(' . ')]
|
||||
|
||||
# Find stress
|
||||
stressList = []
|
||||
stressedSyllableList = []
|
||||
stressedPhoneList = []
|
||||
for i, syllable in enumerate(syllableList):
|
||||
# Primary stress
|
||||
if "'" in syllable:
|
||||
stressList.insert(0, i)
|
||||
# Secondary stress
|
||||
elif '"' in syllable:
|
||||
stressList.append(i)
|
||||
for j, phone in enumerate(syllable):
|
||||
if "'" in phone:
|
||||
stressedSyllableList.insert(0, i)
|
||||
stressedPhoneList.insert(0, j)
|
||||
break
|
||||
elif '"' in phone:
|
||||
stressedSyllableList.insert(i)
|
||||
stressedPhoneList.insert(j)
|
||||
|
||||
syllableList = [x.split(" ") for x in syllableList]
|
||||
|
||||
return syllableList, stressList
|
||||
return syllableList, stressedSyllableList, stressedPhoneList
|
||||
|
||||
|
||||
def getNumPhones(isleDict, label, maxFlag):
|
||||
|
||||
+33
-16
@@ -39,7 +39,8 @@ def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
||||
skipLabelList = []
|
||||
|
||||
syllableEntryList = []
|
||||
tonicEntryList = []
|
||||
tonicSEntryList = []
|
||||
tonicPEntryList = []
|
||||
for start, stop, word in wordTier.entryList:
|
||||
|
||||
if word in skipLabelList:
|
||||
@@ -63,8 +64,20 @@ def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
||||
continue
|
||||
|
||||
syllableList = returnList[1]
|
||||
stressIndexList = returnList[3]
|
||||
|
||||
stressedSyllableIndexList = returnList[3]
|
||||
stressedPhoneIndexList = returnList[4]
|
||||
flattenedPhoneIndexList = returnList[5]
|
||||
|
||||
try:
|
||||
stressI = stressedSyllableIndexList[0]
|
||||
stressJ = stressedPhoneIndexList[0]
|
||||
except IndexError:
|
||||
stressI = None # Function word probably
|
||||
stressJ = None #
|
||||
|
||||
if stressI is not None:
|
||||
syllableList[stressI][stressJ] += "'"
|
||||
|
||||
i = 0
|
||||
# print(syllableList)
|
||||
for k, syllable in enumerate(syllableList):
|
||||
@@ -84,24 +97,28 @@ def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
||||
|
||||
syllableEntryList.append((syllableStart, syllableEnd, label))
|
||||
|
||||
# Create the tonic tier entry
|
||||
try:
|
||||
stressIndex = stressIndexList[0]
|
||||
except IndexError:
|
||||
stressIndex = None # Function word probably
|
||||
|
||||
tonicLabel = ''
|
||||
if k == stressIndex:
|
||||
tonicLabel = 'T'
|
||||
|
||||
tonicEntryList.append((syllableStart, syllableEnd, tonicLabel))
|
||||
# Create the tonic syllable tier entry
|
||||
if k == stressI:
|
||||
tonicSEntryList.append((syllableStart, syllableEnd, 'T'))
|
||||
|
||||
# Create the tonic phone tier entry
|
||||
if k == stressI:
|
||||
syllablePhoneTier = phoneTier.crop(syllableStart, syllableEnd,
|
||||
True, False)[0]
|
||||
|
||||
phoneList = [entry for entry in syllablePhoneTier.entryList
|
||||
if entry[2] != '']
|
||||
phoneStart, phoneEnd = phoneList[stressJ][:2]
|
||||
tonicPEntryList.append((phoneStart, phoneEnd, 'T'))
|
||||
|
||||
# Create a textgrid with the two syllable-level tiers
|
||||
syllableTier = tgio.IntervalTier("syllable", syllableEntryList)
|
||||
tonicTier = tgio.IntervalTier('tonic', tonicEntryList)
|
||||
tonicSTier = tgio.IntervalTier('tonicSyllable', tonicSEntryList)
|
||||
tonicPTier = tgio.IntervalTier('tonicPhone', tonicPEntryList)
|
||||
|
||||
syllableTG = tgio.Textgrid()
|
||||
syllableTG.addTier(syllableTier)
|
||||
syllableTG.addTier(tonicTier)
|
||||
syllableTG.addTier(tonicSTier)
|
||||
syllableTG.addTier(tonicPTier)
|
||||
|
||||
return syllableTG
|
||||
|
||||
@@ -275,13 +275,25 @@ def findBestSyllabification(isleDict, wordText, actualPronunciationList):
|
||||
alignedPhoneList = alignedAPronList[bestIndex]
|
||||
alignedSyllables = alignedSyllableList[bestIndex]
|
||||
syllabification = isleWordList[bestIndex][0]
|
||||
stressedIndex = isleWordList[bestIndex][1]
|
||||
stressedSyllableIndexList = isleWordList[bestIndex][1]
|
||||
stressedPhoneIndexList = isleWordList[bestIndex][2]
|
||||
|
||||
stressedSyllable, syllableList = _syllabifyPhones(alignedPhoneList,
|
||||
alignedSyllables,
|
||||
stressedIndex)
|
||||
stressedSyllableIndexList)
|
||||
|
||||
return stressedSyllable, syllableList, syllabification, stressedIndex
|
||||
# Count the index of the stressed phones, if the stress list has
|
||||
# become flattened (no syllable information)
|
||||
flattenedStressIndexList = []
|
||||
for i, j in zip(stressedSyllableIndexList, stressedPhoneIndexList):
|
||||
k = j
|
||||
for l in range(i):
|
||||
k += len(syllableList[l])
|
||||
flattenedStressIndexList.append(k)
|
||||
|
||||
return (stressedSyllable, syllableList, syllabification,
|
||||
stressedSyllableIndexList, stressedPhoneIndexList,
|
||||
flattenedStressIndexList)
|
||||
|
||||
|
||||
def findClosestPronunciation(isleDict, wordText, aPron):
|
||||
|
||||
@@ -29,7 +29,8 @@ isleDict = isletool.LexicalTool(islevPath)
|
||||
syllableTG = praattools.syllabifyTextgrid(isleDict, tg, "word", "phone",
|
||||
skipLabelList=["",])
|
||||
tg.addTier(syllableTG.tierDict["syllable"])
|
||||
tg.addTier(syllableTG.tierDict["tonic"])
|
||||
tg.addTier(syllableTG.tierDict["tonicSyllable"])
|
||||
tg.addTier(syllableTG.tierDict["tonicPhone"])
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user