How to use the praatio.tgio.IntervalTier function in praatio

To help you get started, we’ve selected a few praatio 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 / praatIO / praatio / tgio.py View on Github external
# Tier entry data
        entryList = []
        if isInterval:
            while True:
                try:
                    startTime, endTimeI = _fetchRow(tierData, '', startTimeI)
                    endTime, labelI = _fetchRow(tierData, '', endTimeI)
                    label, startTimeI = _fetchRow(tierData, '', labelI)
                except (ValueError, IndexError):
                    break
                
                label = label.strip()
                entryList.append((startTime, endTime, label))
                
            newTG.addTier(IntervalTier(tierName, entryList,
                                       tierStartTime, tierEndTime))
            
        else:
            while True:
                try:
                    time, labelI = _fetchRow(tierData, '', startTimeI)
                    label, startTimeI = _fetchRow(tierData, '', labelI)
                except (ValueError, IndexError):
                    break
                label = label.strip()
                entryList.append((time, label))
                
            newTG.addTier(PointTier(tierName, entryList,
                                    tierStartTime, tierEndTime))

    return newTG
github timmahrt / pysle / pysle / praattools.py View on Github external
tmpStressJ = cvList.index('V')
                except ValueError:
                    for char in [u'r', u'n', u'l']:
                        if char in cvList:
                            tmpStressJ = cvList.index(char)
                            break

                phoneStart, phoneEnd = phoneList[tmpStressJ][:2]
                tonicPEntryList.append((phoneStart, phoneEnd, 'T'))

    # Create a textgrid with the two syllable-level tiers
    syllableTier = tgio.IntervalTier('syllable', syllableEntryList,
                                     minT, maxT)
    tonicSTier = tgio.IntervalTier('tonicSyllable', tonicSEntryList,
                                   minT, maxT)
    tonicPTier = tgio.IntervalTier('tonicVowel', tonicPEntryList,
                                   minT, maxT)

    syllableTG = tgio.Textgrid()
    syllableTG.addTier(syllableTier)
    syllableTG.addTier(tonicSTier)
    syllableTG.addTier(tonicPTier)

    return syllableTG
github timmahrt / praatIO / praatio / tgio.py View on Github external
cutTWithin += cropEnd - cropStart
                        
            if matchedEntry is not None:
                newEntryList.append(matchedEntry)

        if rebaseToZero is True:
            newEntryList = [(startT - cropStart, stopT - cropStart, label)
                            for startT, stopT, label in newEntryList]
            minT = 0
            maxT = cropEnd - cropStart
        else:
            minT = cropStart
            maxT = cropEnd

        # Create subtier
        croppedTier = IntervalTier(self.name, newEntryList, minT, maxT)
        
        # DEBUG info
#         debugInfo = (subTier, cutTStart, cutTWithin, cutTEnd,
#                      firstIntervalKeptProportion, lastIntervalKeptProportion)
    
        return croppedTier
github timmahrt / praatIO / praatio / tgio.py View on Github external
tierEntryList = []
        labelI = 0
        if tierType == INTERVAL_TIER:
            while True:
                try:
                    timeStart, timeStartI = _fetchRow(tierData,
                                                      "xmin = ", labelI)
                    timeEnd, timeEndI = _fetchRow(tierData,
                                                  "xmax = ", timeStartI)
                    label, labelI = _fetchRow(tierData, "text =", timeEndI)
                except (ValueError, IndexError):
                    break
                
                label = label.strip()
                tierEntryList.append((timeStart, timeEnd, label))
            tier = IntervalTier(tierName, tierEntryList, tierStart, tierEnd)
        else:
            while True:
                try:
                    time, timeI = _fetchRow(tierData, "number = ", labelI)
                    label, labelI = _fetchRow(tierData, "mark =", timeI)
                except (ValueError, IndexError):
                    break
                
                label = label.strip()
                tierEntryList.append((time, label))
            tier = PointTier(tierName, tierEntryList, tierStart, tierEnd)
        
        newTG.addTier(tier)
        
    return newTG
github timmahrt / pysle / pysle / praattools.py View on Github external
subPhoneEntryList = phoneTier.crop(wordStartT, wordEndT,
                                               "truncated", False).entryList

        if len(subPhoneEntryList) == 0:
            phoneDur = (wordEndT - wordStartT) / len(phoneList)

            phoneStartT = wordStartT
            for phone in phoneList:
                phoneEndT = phoneStartT + phoneDur
                subPhoneEntryList.append((phoneStartT, phoneEndT, phone))
                phoneStartT = phoneEndT

        phoneEntryList.extend(subPhoneEntryList)

    # Replace or add the phone tier
    newPhoneTier = tgio.IntervalTier(phoneTierName,
                                     phoneEntryList,
                                     tg.minTimestamp,
                                     tg.maxTimestamp)
    if phoneTier is not None:
        tg.replaceTier(phoneTierName, newPhoneTier)
    else:

        tg.addTier(newPhoneTier)

    return tg
github CoEDL / elpis / elpis / engines / common / output / ctm_to_textgrid.py View on Github external
def create_textgrid(wav_dictionary: Dict[str, str],
                    ctm_dictionary: dict,
                    output_directory: str) -> None:
    for index, utterance_id in enumerate(wav_dictionary.keys()):
        textgrid = tgio.Textgrid()
        tier = tgio.IntervalTier(name='default',
                                 entryList=ctm_dictionary[utterance_id],
                                 minT=0,
                                 pairedWav=str(Path(wav_dictionary[utterance_id])))
        textgrid.addTier(tier)
        textgrid.save(str(Path(output_directory, f"utterance-{index}.TextGrid")))
github timmahrt / praatIO / examples / merge_tiers.py View on Github external
bobbyTG.addTier(tgio.IntervalTier("verbs", [entryList[2], ]))
bobbyTG.addTier(tgio.IntervalTier("subjects", entryList[3:5]))

# Let's save it, in case you want to see it
bobbyTG.save(join(outputPath, "mergeExample_bobby_words_split.TextGrid"))


# And we'll do the same for mary's textgrid
tg = tgio.openTextgrid(join(path, "mary.TextGrid"))
wordTier = tg.tierDict["word"]
entryList = wordTier.entryList

maryTG = tgio.Textgrid()
maryTG.addTier(tg.tierDict["phone"])
maryTG.addTier(tgio.IntervalTier("nouns", [entryList[0], ]))
maryTG.addTier(tgio.IntervalTier("verbs", [entryList[1], ]))
maryTG.addTier(tgio.IntervalTier("subjects", entryList[2:4]))

maryTG.save(join(outputPath, "mergeExample_mary_words_split.TextGrid"))

# Let's combine Mary and Bob's textgrids
combinedTG = bobbyTG.appendTextgrid(maryTG, True)
combinedTG.save(join(outputPath,
                     "mergeExample_mary_and_bob_words_split.TextGrid"))

# And now let's merge their tiers together
# We'll go with the default merge function which accepts all labels,
# except silence. Any non-silent intervals that overlap will be merged
# together into a super interval
mergedTG = combinedTG.mergeTiers(tierList=["nouns", "verbs", "subjects"],
                                 preserveOtherTiers=True)
github CoEDL / elpis / elpis / transformer / elan.py View on Github external
def create_textgrid(wav_dictionary: Dict[str, str],
                    ctm_dictionary: dict,
                    output_directory: str) -> None:
    for index, utterance_id in enumerate(wav_dictionary.keys()):
        textgrid = tgio.Textgrid()
        tier = tgio.IntervalTier(name='phones',
                                 entryList=ctm_dictionary[utterance_id],
                                 minT=0,
                                 pairedWav=str(Path(wav_dictionary[utterance_id])))
        textgrid.addTier(tier)
        textgrid.save(str(Path(output_directory, f"utterance-{index}.TextGrid")))
github timmahrt / praatIO / examples / merge_tiers.py View on Github external
bobbyTG.addTier(tgio.IntervalTier("subjects", entryList[3:5]))

# Let's save it, in case you want to see it
bobbyTG.save(join(outputPath, "mergeExample_bobby_words_split.TextGrid"))


# And we'll do the same for mary's textgrid
tg = tgio.openTextgrid(join(path, "mary.TextGrid"))
wordTier = tg.tierDict["word"]
entryList = wordTier.entryList

maryTG = tgio.Textgrid()
maryTG.addTier(tg.tierDict["phone"])
maryTG.addTier(tgio.IntervalTier("nouns", [entryList[0], ]))
maryTG.addTier(tgio.IntervalTier("verbs", [entryList[1], ]))
maryTG.addTier(tgio.IntervalTier("subjects", entryList[2:4]))

maryTG.save(join(outputPath, "mergeExample_mary_words_split.TextGrid"))

# Let's combine Mary and Bob's textgrids
combinedTG = bobbyTG.appendTextgrid(maryTG, True)
combinedTG.save(join(outputPath,
                     "mergeExample_mary_and_bob_words_split.TextGrid"))

# And now let's merge their tiers together
# We'll go with the default merge function which accepts all labels,
# except silence. Any non-silent intervals that overlap will be merged
# together into a super interval
mergedTG = combinedTG.mergeTiers(tierList=["nouns", "verbs", "subjects"],
                                 preserveOtherTiers=True)

mergedTG.save(join(outputPath,
github timmahrt / praatIO / examples / auto_segment_speech.py View on Github external
# Get the mid point of the longest n intervals and convert them
    # into intervals to be transcribed
    entryList = entryList[:numEntries]
    pointList = [start + ((stop - start) / 2.0)
                 for _, start, stop, _ in entryList]
    pointList.sort()
    
    pointList = [0.0, ] + pointList + [duration, ]
    
    newEntryList = []
    for i in range(len(pointList) - 1):
        newEntryList.append((pointList[i], pointList[i + 1], "%d" % i))
    
    outputTG = tgio.Textgrid()
    tier = tgio.IntervalTier("toTranscribe", newEntryList, 0, duration)
    outputTG.addTier(tier)
    
    outputTG.save(outputTGFN)