How to use the praatio.utilities.utils.invertIntervalList 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 / audioio.py View on Github external
params = audiofile.getparams()
    sampwidth = params[1]
    framerate = params[2]
    nframes = params[3]
    
    duration = nframes / float(framerate)
    
    # Can't specify both the keepList and the deleteList
    assert(keepList is None or deleteList is None)
    
    if keepList is None and deleteList is None:
        keepList = [(0, duration), ]
        deleteList = []
    elif keepList is None:
        keepList = utils.invertIntervalList(deleteList, duration)
    else:
        deleteList = utils.invertIntervalList(keepList, duration)
        
    keepList = [[row[0], row[1], "keep"] for row in keepList]
    deleteList = [[row[0], row[1], "delete"] for row in deleteList]
    iterList = sorted(keepList + deleteList)
    
    # Grab the sections to be kept
    audioSampleList = []
    byteCode = sampWidthDict[sampwidth]
    for startT, stopT, label in iterList:
        diff = stopT - startT
        
        if label == "keep":
            audiofile.setpos(int(framerate * startT))
            frames = audiofile.readframes(int(framerate * diff))
github timmahrt / ProMo / promo / f0_morph.py View on Github external
fromPitchData will be sampled from this list.  In
                         essence, this allows one to leave segments of
                         the original pitch contour untouched by the
                         morph process.
    '''

    fromDuration = audio_scripts.getSoundFileDuration(fromWavFN)

    # Find source pitch samples that will be mixed in with the target
    # pitch samples later
    nonMorphPitchData = []
    if sourcePitchDataList is not None:
        timeList = sorted(fromPitchData)
        timeList = [(row[0][0], row[-1][0]) for row in timeList]
        endTime = sourcePitchDataList[-1][0]
        invertedTimeList = praatio_utils.invertIntervalList(timeList, endTime)
        invertedTimeList = [(start, stop) for start, stop in invertedTimeList
                            if stop - start > minIntervalLength]
        
        for start, stop in invertedTimeList:
            pitchList = praatio_utils.getValuesInInterval(sourcePitchDataList,
                                                          start,
                                                          stop)
            nonMorphPitchData.extend(pitchList)

    # Iterative pitch tier data path
    pitchTierPath = join(pitchPath, "pitchTiers")
    resynthesizedPath = join(pitchPath, "f0_resynthesized_wavs")
    for tmpPath in [pitchTierPath, resynthesizedPath]:
        utils.makeDir(tmpPath)

    # 1. Prepare the data for morphing - acquire the segments to merge
github timmahrt / praatIO / examples / delete_vowels.py View on Github external
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,
                                   doShrink=doShrink)
    wavObj.save(outputWavFN)
    
    shrunkTG = copy.deepcopy(tg)
    for start, stop in sorted(deleteList, reverse=True):
        shrunkTG = shrunkTG.eraseRegion(start, stop, doShrink=doShrink)
    
    shrunkTG.save(outputTGFN)
github timmahrt / praatIO / praatio / audioio.py View on Github external
sampwidth = params[1]
    framerate = params[2]
    nframes = params[3]
    
    duration = nframes / float(framerate)
    
    # Can't specify both the keepList and the deleteList
    assert(keepList is None or deleteList is None)
    
    if keepList is None and deleteList is None:
        keepList = [(0, duration), ]
        deleteList = []
    elif keepList is None:
        keepList = utils.invertIntervalList(deleteList, duration)
    else:
        deleteList = utils.invertIntervalList(keepList, duration)
        
    keepList = [[row[0], row[1], "keep"] for row in keepList]
    deleteList = [[row[0], row[1], "delete"] for row in deleteList]
    iterList = sorted(keepList + deleteList)
    
    # Grab the sections to be kept
    audioSampleList = []
    byteCode = sampWidthDict[sampwidth]
    for startT, stopT, label in iterList:
        diff = stopT - startT
        
        if label == "keep":
            audiofile.setpos(int(framerate * startT))
            frames = audiofile.readframes(int(framerate * diff))
            
            actualNumFrames = int(len(frames) / float(sampwidth))
github timmahrt / praatIO / praatio / audioio.py View on Github external
a sine wave
        sineWaveAmplitude: if None and operation is "sine wave"
                           use max amplitude.
        '''
    
        assert(operation in ["shrink", "silence", "sine wave"])
    
        duration = float(self.nframes) / self.framerate
        
        # Need to specify what to keep or what to delete, but can't
        # specify both
        assert(keepList is not None or deleteList is not None)
        assert(keepList is None or deleteList is None)
        
        if keepList is None:
            keepList = utils.invertIntervalList(deleteList, duration)
        else:
            deleteList = utils.invertIntervalList(keepList, duration)
        keepList = [[row[0], row[1], "keep"] for row in keepList]
        deleteList = [[row[0], row[1], "delete"] for row in deleteList]
        iterList = sorted(keepList + deleteList)
        
        zeroBinValue = struct.pack(sampWidthDict[self.sampwidth], 0)
        
        # Grab the sections to be kept
        audioFrames = b""
        for startT, stopT, label in iterList:
            diff = stopT - startT
            
            if label == "keep":
                self.audiofile.setpos(int(self.framerate * startT))
                frames = self.audiofile.readframes(int(self.framerate * diff))