How to use the praatio.tgio.openTextgrid 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 / ProMo / examples / modify_pitch_accent_example.py View on Github external
if not os.path.exists(rootOutputPath):
    os.mkdir(rootOutputPath)

# 1st - get pitch
piList = pitch_and_intensity.extractPI(join(root, wavFN),
                                       join(rootOutputPath, pitchIntensityFN),
                                       praatEXE, minPitch, maxPitch)
pitchList = [(timeV, pitchV) for timeV, pitchV, _ in piList]

dur = audioio.WavQueryObj(join(root, wavFN)).getDuration()
pointObj = dataio.PointObject2D(pitchList, dataio.PITCH, 0, dur)
pointObj.save(join(rootOutputPath, originalPitchFN))


# 2nd - get region to manipulate.  Let's make the subject more emphatic!
tg = tgio.openTextgrid(join(root, "mary1.TextGrid"))
tier = tg.tierDict["words"]
start, stop, _ = tier.entryList[0]  # Getting info for the first word

targetPitchList = [(timeV, pitchV) for timeV, pitchV in pitchList
                   if timeV >= start and timeV <= stop]

# 3rd - make manipulation
accent = modify_pitch_accent.PitchAccent(targetPitchList)
accent.addPlateau(0.05)  # Peak is dragged out for 0.05 seconds
accent.adjustPeakHeight(60)  # Plateau is raised by 60 hz
accent.shiftAccent(-0.03)  # Recenter the plateau around the original peak

# 4th - integrate results
moddedPitchList = accent.reintegrate(pitchList)

# 5th - resynthesize
github timmahrt / praatIO / examples / get_pitch_and_formants.py View on Github external
medianFilterWindowSize=9)

pitch_and_intensity.generatePIMeasures(maryPitchData,
                                       join(tgPath, "mary.TextGrid"),
                                       "word", doPitch=False,
                                       medianFilterWindowSize=9)

tg = tgio.openTextgrid(join(tgPath, "bobby_words.TextGrid"))
tg = pitch_and_intensity.detectPitchErrors(bobbyPitchData, 0.75, tg)[1]
tg.save(join(rootOutputFolder, "bobby_errors.TextGrid"))

tg = tgio.openTextgrid(join(tgPath, "mary.TextGrid"))
tg = pitch_and_intensity.detectPitchErrors(bobbyPitchData, 0.75, tg)[1]
tg.save(join(rootOutputFolder, "mary_errors.TextGrid"))

tg = tgio.openTextgrid(join(tgPath, "mary.TextGrid"))
tg = pitch_and_intensity.detectPitchErrors(maryFilteredPitchData, 0.75, tg)[1]
tg.save(join(rootOutputFolder, "mary_filtered_errors.TextGrid"))

formantData = praat_scripts.getFormants(praatEXE,
                          join(wavPath, "bobby.wav"),
                          join(formantsPath, "bobby.txt"),
                          5500)
github timmahrt / pysle / examples / alignment_example.py View on Github external
from pysle import isletool
from pysle import praattools


root = join('.', 'files')
isleDict = isletool.LexicalTool(join(root, "ISLEdict_sample.txt"))

inputFN = join(root, "pumpkins_with_syllables.TextGrid")
outputFN = join(root, "pumpkins_with_naive_alignment.TextGrid")

utteranceTierName = "utterance"
wordTierName = "word"
phoneListTierName = "phoneList"
phoneTierName = "phone"

tg = tgio.openTextgrid(inputFN)

for tierName in tg.tierNameList[:]:
    if tierName == utteranceTierName:
        continue
    tg.removeTier(tierName)
tg = praattools.naiveWordAlignment(tg, utteranceTierName, wordTierName,
                                   isleDict, phoneListTierName)
tg = praattools.naivePhoneAlignment(tg, wordTierName, phoneTierName,
                                    isleDict)
tg.save(outputFN)
github timmahrt / pyAcoustics / pyacoustics / textgrids / textgrids.py View on Github external
def _navigateTGs(tgPath, name, tierName):
    '''
    Converts a textgrid into a plain text format
    
    Each labels is output by the
    '''
    
    tg = tgio.openTextgrid(join(tgPath, name + ".TextGrid"))
    tier = tg.tierDict[tierName]
    
    for start, stop, label in tier.entryList:
        if label.strip() == "":
            continue
        
        yield start, stop, label
github timmahrt / pyAcoustics / examples / estimate_speech_rate.py View on Github external
def _addSyllableNucleiToTextgrids(wavPath, tgPath, tierName,
                                 syllableNucleiPath, outputPath):
    # Add syllable nuclei to textgrids
    for name in utils.findFiles(wavPath, filterExt=".wav", stripExt=True):
        
        tg = tgio.openTextgrid(join(tgPath, name + ".TextGrid"))
        entryList = tg.tierDict[tierName].entryList
        startTimeList = [entry[0] for entry in entryList]
        nucleusSyllableList = uwe_sr.toAbsoluteTime(name, syllableNucleiPath,
                                                    startTimeList)
        flattenedSyllableList = [nuclei for sublist in nucleusSyllableList
                                 for nuclei in sublist]
        wavFN = join(wavPath, name + ".wav")
        duration = audio_scripts.getSoundFileDuration(wavFN)
        
        oom = my_math.orderOfMagnitude(len(flattenedSyllableList))
        labelTemplate = "%%0%dd" % (oom + 1)

        entryList = [(timestamp, labelTemplate % i)
                     for i, timestamp in enumerate(flattenedSyllableList)]
        print(flattenedSyllableList)
        tier = tgio.PointTier("Syllable Nuclei", entryList, 0, duration)
github timmahrt / ProMo / promo / duration_morph.py View on Github external
def textgridMorphDuration(fromTGFN, toTGFN):
    '''
    A convenience function.  Morphs interval durations of one tg to another.
    
    This assumes the two textgrids have the same number of segments.
    '''
    fromTG = tgio.openTextgrid(fromTGFN)
    toTG = tgio.openTextgrid(toTGFN)
    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 / praatIO / examples / get_pitch_and_formants.py View on Github external
# Generate pitch and intensity values for one file
pitch_and_intensity.generatePIMeasures(bobbyPitchData,
                                       join(tgPath, "bobby_words.TextGrid"),
                                       "word", doPitch=True,
                                       medianFilterWindowSize=9)

pitch_and_intensity.generatePIMeasures(maryPitchData,
                                       join(tgPath, "mary.TextGrid"),
                                       "word", doPitch=False,
                                       medianFilterWindowSize=9)

tg = tgio.openTextgrid(join(tgPath, "bobby_words.TextGrid"))
tg = pitch_and_intensity.detectPitchErrors(bobbyPitchData, 0.75, tg)[1]
tg.save(join(rootOutputFolder, "bobby_errors.TextGrid"))

tg = tgio.openTextgrid(join(tgPath, "mary.TextGrid"))
tg = pitch_and_intensity.detectPitchErrors(bobbyPitchData, 0.75, tg)[1]
tg.save(join(rootOutputFolder, "mary_errors.TextGrid"))

tg = tgio.openTextgrid(join(tgPath, "mary.TextGrid"))
tg = pitch_and_intensity.detectPitchErrors(maryFilteredPitchData, 0.75, tg)[1]
tg.save(join(rootOutputFolder, "mary_filtered_errors.TextGrid"))

formantData = praat_scripts.getFormants(praatEXE,
                          join(wavPath, "bobby.wav"),
                          join(formantsPath, "bobby.txt"),
                          5500)
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)
                currentEntry = list(nextEntry)
github CoEDL / elpis / elpis / wrappers / input / 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 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 / pyJuliusAlign / pyjuliusalign / alignFromTextgrid.py View on Github external
def textgridToCSV(inputPath, outputPath, outputExt='.csv'):
    utils.makeDir(outputPath)

    for fn in utils.findFiles(inputPath, filterExt=".TextGrid"):
        tg = tgio.openTextgrid(join(inputPath, fn))
        tier = tg.tierDict["utterances"]
        outputList = []
        for start, stop, label in tier.entryList:
            outputList.append("%s,%s,%s" % (start, stop, label))
        
        name = os.path.splitext(fn)[0]
        outputTxt = "\n".join(outputList)
        outputFN = join(outputPath, "%s%s" % (name, outputExt))
        with io.open(outputFN, "w", encoding="utf-8") as fd:
            fd.write(outputTxt)