How to use the praatio.tgio 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 / examples / View on Github external
def deleteVowels(inputTGFN, inputWavFN, outputPath, doShrink,
    wavFN = os.path.split(inputWavFN)[1]
    tgFN = os.path.split(inputTGFN)[1]
    outputWavFN = join(outputPath, wavFN)
    outputTGFN = join(outputPath, tgFN)
    if atZeroCrossing is True:
        zeroCrossingTGPath = join(outputPath, "zero_crossing_tgs")
        zeroCrossingTGFN = join(zeroCrossingTGPath, tgFN)
        tg = tgio.openTextgrid(inputTGFN)
        wavObj = audioio.WavQueryObj(inputWavFN)

        tg = tgio.openTextgrid(inputTGFN)
    keepList = tg.tierDict["phone"].entryList
    keepList = [entry for entry in keepList
                if not isVowel(entry[2])]
    deleteList = utils.invertIntervalList(keepList, tg.maxTimestamp)
    wavObj = audioio.openAudioFile(inputWavFN,
github timmahrt / praatIO / praatio / View on Github external

    # Warn user that normalizing a second time nullifies the first normalization
    if globalZNormalization is True and localZNormalizationWindowSize > 0:
        raise NormalizationException()

    if globalZNormalization is True:
        if doPitch:
            dataList = myMath.znormalizeSpeakerData(dataList, 1, True)
            dataList = myMath.znormalizeSpeakerData(dataList, 2, True)

    # Raw values should have 0 filtered; normalized values are centered around 0, so don't filter
    filterZeroFlag = not globalZNormalization

    tg = tgio.openTextgrid(tgFN)
    piData = tg.tierDict[tierName].getValuesInIntervals(dataList)

    outputList = []
    for interval, entryList in piData:
        label = interval[0]
        if doPitch:
            tmpValList = [f0Val for _, f0Val, _ in entryList]
            f0Measures = getPitchMeasures(tmpValList, tgFN, label,
                                          medianFilterWindowSize, filterZeroFlag)
            tmpValList = [intensityVal for _, _, intensityVal in entryList]
            if filterZeroFlag:
                tmpValList = [intensityVal for intensityVal in tmpValList
                              if intensityVal != 0.0]
github timmahrt / praatIO / praatio / View on Github external
def _shiftTimes(tg, timeV, newTimeV):
    Change all instances of timeV in the textgrid to newTimeV
    These are meant to be small changes.  No checks are done to see
    if the new interval steps on other intervals
    tg =
    for tierName in tg.tierNameList:
        tier = tg.tierDict[tierName]
        if isinstance(tier, tgio.IntervalTier):
            entryList = [entry for entry in tier.entryList
                         if entry[0] == timeV or entry[1] == timeV]
            insertEntryList = []
            for entry in entryList:
                if entry[0] == timeV:
                    newStart, newStop = newTimeV, entry[1]
                elif entry[1] == timeV:
                    newStart, newStop = entry[0], newTimeV
                insertEntryList.append((newStart, newStop, entry[2]))
            for entry in insertEntryList:
        elif isinstance(tier, tgio.PointTier):
            entryList = [entry for entry in tier.entryList
github timmahrt / pyAcoustics / pyacoustics / morph / View on Github external
# This allows us to continue on with our script with zeros removed
            returnList.append((pitchDatum, time))
        name = os.path.splitext(fn)[0] + ".PitchTier"
        savePitchData(pitchTierData, 0, duration, pitchTierPath, name)
        return returnList
    if loadPitchFlag:
        fromPitchFN = os.path.splitext(fromFN)[0] + ".PitchTier"
        toPitchFN = os.path.splitext(toFN)[0] + ".PitchTier"
        # This is the raw data, undivided by labeled interval in the textgrids
        fromPitchDataWhole = tgio.readPitchTier(pitchTierPath,
        toPitchDataWhole = tgio.readPitchTier(pitchTierPath,
        # Creates /fromFN.PitchTier/ in /fromPath+'pitchTiers'/
        fromPitchDataWhole = createPitchTierESPS(path, fromFN, fromMinPitch,
                                                 fromMaxPitch, True)
        toPitchDataWhole = createPitchTierESPS(path, toFN, toMinPitch,
                                               toMaxPitch, True)
        fromDuration = audio_scripts.getSoundFileDuration(join(path, fromFN))
        toDuration = audio_scripts.getSoundFileDuration(join(path, toFN))
        fromPitchDataWhole = savePitchTrack(fromPitchDataWhole, fromDuration,
github timmahrt / pyAcoustics / examples / View on Github external
minPitch, maxPitch,
    # entry = (time, pitchVal, intVal)
    pitchList = [float(entry[1]) for entry in motherPIList]
    timeDict = split_on_tone.splitFileOnTone(pitchList,

    # Output result as textgrid
    duration = audio_scripts.getSoundFileDuration(join(inputPath, fn))
    tg = tgio.Textgrid()
    for key in ['beep', 'speech', 'silence']:
        entryList = timeDict[key]
        tier = tgio.IntervalTier(key, entryList, 0, duration)
        tg.addTier(tier), name + ".TextGrid"))

    # Output audio portions between tones
    if generateWavs:
        split_on_tone.extractSubwavs(timeDict, inputPath, fn, subwavPath)
github timmahrt / praatIO / examples / View on Github external
join(pitchPath, "mary_filtered.txt"),
                                                         praatEXE, 75, 450,

# Generate pitch and intensity values for one file
                                       join(tgPath, "bobby_words.TextGrid"),
                                       "word", doPitch=True,

                                       join(tgPath, "mary.TextGrid"),
                                       "word", doPitch=False,

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

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

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

formantData = praat_scripts.getFormants(praatEXE,
                          join(wavPath, "bobby.wav"),
                          join(formantsPath, "bobby.txt"),
github CoEDL / kaldi_helpers / kaldi_helpers / output_scripts / 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',
        textgrid.addTier(tier), f"utterance-{index}.TextGrid")))
github timmahrt / ProMo / promo / View on Github external
def getPitchForIntervals(data, tgFN, tierName):
    Preps data for use in f0Morph
    tg = tgio.openTextgrid(tgFN)
    data = tg.tierDict[tierName].getValuesInIntervals(data)
    data = [dataList for _, dataList in data]

    return data
github timmahrt / praatIO / praatio / View on Github external
# Get the end time
    filterStopT = timeV + maxDifference
    if filterStopT > tg.maxTimestamp:
        filterStopT = tg.maxTimestamp

    croppedTG = tg.crop(filterStartT, filterStopT, "lax", False)

    matchList = [(tierName, timeV, entry, orderID)]
    for subTierName in tierNameList:
        subCroppedTier = croppedTG.tierDict[subTierName]
        # For each item that exists in the search span, find the boundary
        # that lies in the search span
        for subCroppedEntry in subCroppedTier.entryList:
            if subCroppedTier.tierType == tgio.INTERVAL_TIER:
                subStart, subEnd, _ = subCroppedEntry
                # Left boundary?
                leftMatchVal = None
                if subStart >= filterStartT and subStart <= filterStopT:
                    leftMatchVal = subStart

                # Right boundary?
                rightMatchVal = None
                if subEnd >= filterStartT and subEnd <= filterStopT:
                    rightMatchVal = subEnd
                # There should be at most one matching boundary
                assert(leftMatchVal is None or rightMatchVal is None)
                # Set the matching boundary info