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 / delete_vowels.py View on Github external
def deleteVowels(inputTGFN, inputWavFN, outputPath, doShrink,
                 atZeroCrossing=True):
    
    utils.makeDir(outputPath)
    
    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)
        utils.makeDir(zeroCrossingTGPath)
        
        tg = tgio.openTextgrid(inputTGFN)
        wavObj = audioio.WavQueryObj(inputWavFN)
        
        praatio_scripts.tgBoundariesToZeroCrossings(tg,
                                                    wavObj,
                                                    zeroCrossingTGFN)

    else:
        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,
                                   keepList=keepList,
github timmahrt / praatIO / praatio / pitch_and_intensity.py 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)
        else:
            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)
            outputList.append(list(f0Measures))
        else:
            tmpValList = [intensityVal for _, _, intensityVal in entryList]
    
            if filterZeroFlag:
                tmpValList = [intensityVal for intensityVal in tmpValList
                              if intensityVal != 0.0]
github timmahrt / praatIO / praatio / praatio_scripts.py 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 = tg.new()
    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
                tier.deleteEntry(entry)
                insertEntryList.append((newStart, newStop, entry[2]))
            
            for entry in insertEntryList:
                tier.insertEntry(entry)
        
        elif isinstance(tier, tgio.PointTier):
            entryList = [entry for entry in tier.entryList
github timmahrt / pyAcoustics / pyacoustics / morph / praat_pitch.py 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,
                                                   fromPitchFN)[1]
        toPitchDataWhole = tgio.readPitchTier(pitchTierPath,
                                                 toPitchFN)[1]
        
    else:
        # 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,
                                            fromFN)
github timmahrt / pyAcoustics / examples / split_audio_on_tone.py View on Github external
minPitch, maxPitch,
                                                 sampleStep=sampleStep,
                                                 forceRegenerate=forceRegen)
    # entry = (time, pitchVal, intVal)
    pitchList = [float(entry[1]) for entry in motherPIList]
    timeDict = split_on_tone.splitFileOnTone(pitchList,
                                             piSamplingRate,
                                             toneFrequency,
                                             minEventDuration)

    # 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)
    tg.save(join(tgPath, name + ".TextGrid"))

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

# 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 CoEDL / kaldi_helpers / kaldi_helpers / output_scripts / 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='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 / ProMo / promo / f0_morph.py 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 / praatio_scripts.py 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