How to use the praatio.tgio.Textgrid 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 / pyAcoustics / pyacoustics / morph / morph_duration.py View on Github external
def morphTextgridDuration(fromTG, toTG):
    
    adjustedTG = tgio.Textgrid()
    
    for tierName in fromTG.tierNameList:
        fromTier = fromTG.tierDict[tierName]
        toTier = toTG.tierDict[tierName]
        adjustedTier = fromTier.morph(toTier)
        adjustedTG.addTier(adjustedTier)
            
    return adjustedTG
github timmahrt / pyAcoustics / pyacoustics / morph / morph_duration.py View on Github external
def manipulateTextgridDuration(fromTG, modFunc, filterFunc=None):
    
    # By default, all regions are manipulated (except silence)
    if filterFunc is None:
        filterFunc = lambda x: True
    
    adjustedTG = tgio.Textgrid()
    
    for tierName in fromTG.tierNameList:
        fromTier = fromTG.tierDict[tierName]
        adjustedTier = fromTier.manipulate(modFunc, filterFunc)
        adjustedTG.addTier(adjustedTier)
    
    return adjustedTG
github timmahrt / pysle / pysle / praattools.py View on Github external
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 / pyAcoustics / pyacoustics / textgrids / syllabify_textgrids.py View on Github external
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)
        
        outputTG = tgio.Textgrid()
        outputTG.addTier(tg.tierDict["words"])
        outputTG.addTier(tg.tierDict["phones"])
#         outputTG.addTier(syllableTG.tierDict["syllable"])
        outputTG.addTier(syllableTG.tierDict["tonic"])
        
        outputTG.save(join(outputPath, fn))
github CoEDL / kaldi_helpers / kaldi_helpers / input_scripts / textgrid_to_json.py View on Github external
each containing data in the following format: 
                        {'audio_file_name': ,
                        'transcript': ,
                        'start_ms': ,
                        'stop_ms': }
                        
    :param input_directory: directory path containing input_scripts files from where the method
    :return: list of interval data in dictionary form
    """
    intervals: List[Dict[str, Union[str, int]]] = []

    for root, directories, files in os.walk(input_directory):
        for filename in files:
            basename, extension = os.path.splitext(filename)
            if filename.endswith(".TextGrid"):
                text_grid: tgio.Textgrid = tgio.openTextgrid(os.path.join(root, filename))
                speech_tier: tgio.IntervalTier = text_grid.tierDict["Speech"]
                for start, stop, label in speech_tier.entryList:
                    label_word: str = label.replace('"', '')
                    intervals.append({
                        "audio_file_name": os.path.join(".", basename + ".wav"),
                        "transcript": label_word,
                        "start_ms": seconds_to_milliseconds(float(start)),
                        "stop_ms": seconds_to_milliseconds(float(stop))
                    })
    return intervals
github timmahrt / praatIO / examples / merge_tiers.py View on Github external
path = join('.', 'files')
outputPath = join(path, "merged_textgrids")
if not os.path.exists(outputPath):
    os.mkdir(outputPath)

# Let's use praatio to construct some hypothetical textgrids
tg = tgio.openTextgrid(join(path, "bobby_words.TextGrid"))
wordTier = tg.tierDict["word"]
entryList = wordTier.entryList

bobbyPhoneTG = tgio.openTextgrid(join(path, "bobby_phones.TextGrid"))


bobbyTG = tgio.Textgrid()
bobbyTG.addTier(bobbyPhoneTG.tierDict["phone"])
bobbyTG.addTier(tgio.IntervalTier("nouns", [entryList[1], ]))
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"])
github timmahrt / praatIO / examples / merge_adjacent_intervals.py View on Github external
def merge_adjacent(path, fn, outputPath):
    '''
    Goes through every tier of a textgrid; combines adjacent filled intervals
    '''
    
    assert(path != outputPath)
    
    if not os.path.exists(outputPath):
        os.mkdir(outputPath)
    
    outputTG = tgio.Textgrid()
    
    tg = tgio.openTextgrid(join(path, fn))
    for tierName in tg.tierNameList:
        tier = tg.tierDict[tierName]
        
        newEntryList = []
        currentEntry = list(tier.entryList[0])
        for nextEntry in tier.entryList[1:]:

            # Is a boundary shared?
            if currentEntry[1] == nextEntry[0]:
                currentEntry[1] = nextEntry[1]  # Old end = new end
                currentEntry[2] += " - " + nextEntry[2]
            # If not
            else:
                newEntryList.append(currentEntry)
github timmahrt / pyAcoustics / pyacoustics / speech_detection / textgrids.py View on Github external
newRightEntryList = [(entry[0], entry[1], str(i))
                         for i, entry in enumerate(rightEntryList)]
    
    # This shouldn't be necessary
    newLeftEntryList = [entry for entry in newLeftEntryList
                        if entry[1] <= duration and entry[0] < entry[1]]
    newRightEntryList = [entry for entry in newRightEntryList
                         if entry[1] <= duration and entry[0] < entry[1]]
    
    # Output textgrid
    leftTier = tgio.IntervalTier(leftChannelName, newLeftEntryList,
                                    0, duration)
    rightTier = tgio.IntervalTier(rightChannelName, newRightEntryList,
                                     0, duration)
    
    outputTG = tgio.Textgrid()
    outputTG.addTier(leftTier)
    outputTG.addTier(rightTier)
    
    outputTG.save(outputFN)
github timmahrt / praatIO / praatio / tgio.py View on Github external
# Merge the interval tiers
        intervalTier = None
        if len(intervalTierNameList) > 0:
            intervalTier = self.tierDict[intervalTierNameList.pop(0)]
        for tierName in intervalTierNameList:
            intervalTier = intervalTier.union(self.tierDict[tierName])

        # Merge the point tiers
        pointTier = None
        if len(pointTierNameList) > 0:
            pointTier = self.tierDict[pointTierNameList.pop(0)]
        for tierName in pointTierNameList:
            pointTier = pointTier.merge(self.tierDict[tierName])
        
        # Create the final textgrid to output
        tg = Textgrid()
        
        if intervalTier is not None:
            tg.addTier(intervalTier)
        
        if pointTier is not None:
            tg.addTier(pointTier)
        
        return tg