示例#1
0
def extractIntensity(inputFN, outputFN, praatEXE,
                     minPitch, sampleStep=0.01, forceRegenerate=True,
                     undefinedValue=None):
    outputPath = os.path.split(outputFN)[0]
    utils.makeDir(outputPath)
    
    assert(os.path.exists(inputFN))
    firstTime = not os.path.exists(outputFN)
    if firstTime or forceRegenerate is True:
        
        # The praat script uses append mode, so we need to clear any prior
        # result
        if os.path.exists(outputFN):
            os.remove(outputFN)
        
        argList = [inputFN, outputFN, sampleStep,
                   minPitch, -1, -1]
        
        scriptName = "get_intensity.praat"
        scriptFN = join(utils.scriptsPath, scriptName)
        utils.runPraatScript(praatEXE, scriptFN, argList)
            
    iList = loadTimeSeriesData(outputFN, undefinedValue=undefinedValue)
    
    return iList
示例#2
0
def getSpectralInfo(praatEXE, inputWavFN, inputTGFN, outputCSVFN, tierName,
                    spectralPower=2, spectralMoment=3, scriptFN=None):
    '''
    Extracts various spectral measures from an audio file

    http://www.fon.hum.uva.nl/praat/manual/Spectrum.html
    Measures include: center_of_gravity, standard_deviation
    skewness, kertosis, central_movement
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_spectral_info.praat")
    
    argList = [inputWavFN, inputTGFN, outputCSVFN, tierName,
               spectralPower, spectralMoment]
    utils.runPraatScript(praatEXE, scriptFN, argList)
    
    # Load the output
    with io.open(outputCSVFN, "r", encoding="utf-8") as fd:
        data = fd.read()
    
    dataList = data.rstrip().split("\n")
    dataList = [row.split(",") for row in dataList]
    titleRow, dataList = dataList[0], dataList[1:]
    
    return titleRow, dataList
示例#3
0
def extractIntensity(inputFN,
                     outputFN,
                     praatEXE,
                     minPitch,
                     sampleStep=0.01,
                     forceRegenerate=True,
                     undefinedValue=None):
    outputPath = os.path.split(outputFN)[0]
    utils.makeDir(outputPath)

    assert (os.path.exists(inputFN))
    firstTime = not os.path.exists(outputFN)
    if firstTime or forceRegenerate is True:

        # The praat script uses append mode, so we need to clear any prior
        # result
        if os.path.exists(outputFN):
            os.remove(outputFN)

        argList = [inputFN, outputFN, sampleStep, minPitch, -1, -1]

        scriptName = "get_intensity.praat"
        scriptFN = join(utils.scriptsPath, scriptName)
        utils.runPraatScript(praatEXE, scriptFN, argList)

    iList = loadTimeSeriesData(outputFN, undefinedValue=undefinedValue)

    return iList
示例#4
0
def getSpectralInfo(praatEXE,
                    inputWavFN,
                    inputTGFN,
                    outputCSVFN,
                    tierName,
                    spectralPower=2,
                    spectralMoment=3,
                    scriptFN=None):
    '''
    Extracts various spectral measures from an audio file

    http://www.fon.hum.uva.nl/praat/manual/Spectrum.html
    Measures include: center_of_gravity, standard_deviation
    skewness, kertosis, central_movement
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_spectral_info.praat")

    argList = [
        inputWavFN, inputTGFN, outputCSVFN, tierName, spectralPower,
        spectralMoment
    ]
    utils.runPraatScript(praatEXE, scriptFN, argList)

    # Load the output
    with io.open(outputCSVFN, "r", encoding="utf-8") as fd:
        data = fd.read()

    dataList = data.rstrip().split("\n")
    dataList = [row.split(",") for row in dataList]
    titleRow, dataList = dataList[0], dataList[1:]

    return titleRow, dataList
示例#5
0
def resynthesizePitch(praatEXE,
                      inputWavFN,
                      pitchFN,
                      outputWavFN,
                      minPitch,
                      maxPitch,
                      scriptFN=None,
                      pointList=None):
    '''
    Resynthesizes the pitch in a wav file with the given pitch contour file
    
    The pitch track to use can optionally be passed in as pointList.  If
    so, it will be saved as pitchFN for praat to be able to use.
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "resynthesize_pitch.praat")

    if pointList is not None:
        dur = audioio.WavQueryObj(inputWavFN).getDuration()
        pointObj = dataio.PointObject2D(pointList, dataio.PITCH, 0, dur)
        pointObj.save(pitchFN)

    utils.runPraatScript(
        praatEXE, scriptFN,
        [inputWavFN, pitchFN, outputWavFN, minPitch, maxPitch])
示例#6
0
文件: kgio.py 项目: zge/praatIO
def wavToKlattgrid(praatEXE,
                   inputFullPath,
                   outputFullPath,
                   timeStep=0.005,
                   numFormants=5,
                   maxFormantFreq=5500.0,
                   windowLength=0.025,
                   preEmphasis=50.0,
                   pitchFloor=60.0,
                   pitchCeiling=600.0,
                   minPitch=50.0,
                   subtractMean=True,
                   scriptFN=None):
    '''
    Extracts the klattgrid from a wav file
    
    The default values are the same as the ones used in praat
    '''

    if subtractMean is True:
        subtractMean = "yes"
    else:
        subtractMean = "no"

    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "sound_to_klattgrid.praat")

    utils.runPraatScript(praatEXE, scriptFN, [
        inputFullPath, outputFullPath, timeStep, numFormants, maxFormantFreq,
        windowLength, preEmphasis, pitchFloor, pitchCeiling, minPitch,
        subtractMean
    ])
示例#7
0
def _audioToPIFile(inputPath,
                   inputFN,
                   outputPath,
                   outputFN,
                   praatEXE,
                   minPitch,
                   maxPitch,
                   sampleStep=0.01,
                   silenceThreshold=0.03,
                   forceRegenerate=True,
                   tgPath=None,
                   tgFN=None,
                   tierName=None,
                   undefinedValue=None):
    '''
    Extracts pitch and intensity values from an audio file
    
    Returns the result as a list.  Will load the serialized result
    if this has already been called on the appropriate files before
    '''

    inputFullFN = join(inputPath, inputFN)
    outputFullFN = join(outputPath, outputFN)

    utils.makeDir(outputPath)

    assert (os.path.exists(inputFullFN))
    firstTime = not os.path.exists(outputFullFN)
    if firstTime or forceRegenerate is True:

        # The praat script uses append mode, so we need to clear any prior
        # result
        if os.path.exists(outputFullFN):
            os.remove(outputFullFN)

        if tgPath is None or tgFN is None or tierName is None:
            argList = [
                inputFullFN, outputFullFN, sampleStep, minPitch, maxPitch,
                silenceThreshold, -1, -1
            ]

            scriptName = "get_pitch_and_intensity_via_python.praat"
            scriptFN = join(utils.scriptsPath, scriptName)
            utils.runPraatScript(praatEXE, scriptFN, argList)

        else:
            argList = [
                inputFullFN, outputFullFN,
                join(tgPath, tgFN), tierName, sampleStep, minPitch, maxPitch,
                silenceThreshold
            ]

            scriptName = "get_pitch_and_intensity_segments_via_python.praat"
            scriptFN = join(utils.scriptsPath, scriptName)
            utils.runPraatScript(praatEXE, scriptFN, argList)

    piList = loadPIAndTime(outputPath, outputFN, undefinedValue=undefinedValue)

    return piList
示例#8
0
def changeIntensity(praatEXE, wavFN, outputWavFN, newIntensity, scriptFN=None):
    '''
    Changes the intensity of the wavFN (in db)
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "change_intensity.praat")

    #  Praat crashes on exit after resynthesis with a klaatgrid
    utils.runPraatScript(praatEXE, scriptFN,
                         [wavFN, outputWavFN, newIntensity])
示例#9
0
def resynthesizeDuration(praatEXE, inputWavFN, durationTierFN, outputWavFN,
                         minPitch, maxPitch, scriptFN=None):
    '''
    Resynthesizes the duration in a wav file with the given duration tier
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "resynthesize_duration.praat")

    utils.runPraatScript(praatEXE, scriptFN,
                         [inputWavFN, durationTierFN, outputWavFN,
                          minPitch, maxPitch])
示例#10
0
def changeIntensity(praatEXE, wavFN, outputWavFN, newIntensity, scriptFN=None):
    '''
    Changes the intensity of the wavFN (in db)
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath,
                        "change_intensity.praat")

    #  Praat crashes on exit after resynthesis with a klaatgrid
    utils.runPraatScript(praatEXE, scriptFN,
                         [wavFN, outputWavFN, newIntensity])
示例#11
0
def resynthesizeDuration(praatEXE, inputWavFN, durationTierFN, outputWavFN,
                         minPitch, maxPitch, scriptFN=None):
    '''
    Resynthesizes the duration in a wav file with the given duration tier
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "resynthesize_duration.praat")

    utils.runPraatScript(praatEXE, scriptFN,
                         [inputWavFN, durationTierFN, outputWavFN,
                          minPitch, maxPitch])
示例#12
0
def extractPitch(wavFN,
                 outputFN,
                 praatEXE,
                 minPitch,
                 maxPitch,
                 sampleStep=0.01,
                 silenceThreshold=0.03,
                 forceRegenerate=True,
                 undefinedValue=None,
                 medianFilterWindowSize=0,
                 pitchQuadInterp=False):
    '''
    Extract pitch at regular intervals from the input wav file
    
    Data is output to a text file and then returned in a list in the form
    [(timeV1, pitchV1), (timeV2, pitchV2), ...]
    
    sampleStep - the frequency to sample pitch at
    silenceThreshold - segments with lower intensity won't be analyzed
                       for pitch
    forceRegenerate - if running this function for the same file, if False
                      just read in the existing pitch file
    undefinedValue - if None remove from the dataset, otherset set to
                     undefinedValue
    pitchQuadInterp - if True, quadratically interpolate pitch
    '''
    outputPath = os.path.split(outputFN)[0]

    utils.makeDir(outputPath)

    if pitchQuadInterp is True:
        doInterpolation = 1
    else:
        doInterpolation = 0

    assert (os.path.exists(wavFN))
    firstTime = not os.path.exists(outputFN)
    if firstTime or forceRegenerate is True:
        if os.path.exists(outputFN):
            os.remove(outputFN)

        argList = [
            wavFN, outputFN, sampleStep, minPitch, maxPitch, silenceThreshold,
            -1, -1, medianFilterWindowSize, doInterpolation
        ]

        scriptName = "get_pitch.praat"
        scriptFN = join(utils.scriptsPath, scriptName)
        utils.runPraatScript(praatEXE, scriptFN, argList)

    piList = loadTimeSeriesData(outputFN, undefinedValue=undefinedValue)

    return piList
示例#13
0
def getPulses(praatEXE, inputWavFN, outputPointTierFN, minPitch, maxPitch,
              scriptFN=None):
    
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_pulses.praat")
    
    argList = [inputWavFN, outputPointTierFN, minPitch, maxPitch]
    utils.runPraatScript(praatEXE, scriptFN, argList)
    
    # Load the output
    pointObj = dataio.open1DPointObject(outputPointTierFN)
    
    return pointObj
示例#14
0
def annotateSilences(praatEXE, inputWavPath, outputTGPath,
                     minPitch=100, timeStep=0.0, silenceThreshold=-25.0,
                     minSilDur=0.1, minSoundDur=0.1,
                     silentLabel='silence', soundLabel='sound', scriptFN=None):
    '''
    Marks the silences and non-silences of an audio file
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "annotate_silences.praat")

    utils.runPraatScript(praatEXE, scriptFN,
                         [inputWavPath, outputTGPath, minPitch, timeStep,
                          silenceThreshold, minSilDur, minSoundDur,
                          silentLabel, soundLabel])
示例#15
0
def annotateSilences(praatEXE, inputWavPath, outputTGPath,
                     minPitch=100, timeStep=0.0, silenceThreshold=-25.0,
                     minSilDur=0.1, minSoundDur=0.1,
                     silentLabel='silence', soundLabel='sound', scriptFN=None):
    '''
    Marks the silences and non-silences of an audio file
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "annotate_silences.praat")

    utils.runPraatScript(praatEXE, scriptFN,
                         [inputWavPath, outputTGPath, minPitch, timeStep,
                          silenceThreshold, minSilDur, minSoundDur,
                          silentLabel, soundLabel])
示例#16
0
文件: kgio.py 项目: timmahrt/praatIO
def resynthesize(praatEXE, wavFN, klattFN, outputWavFN, doCascade=True,
                 scriptFN=None):
    
    if doCascade:
        method = "Cascade"
    else:
        method = "Parallel"
    
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath,
                        "resynthesize_from_klattgrid.praat")
    
    #  Praat crashes on exit after resynthesis with a klaatgrid
    utils.runPraatScript(praatEXE, scriptFN,
                         [wavFN, klattFN, outputWavFN, method])
示例#17
0
def resynthesize(praatEXE, wavFN, klattFN, outputWavFN, doCascade=True,
                 scriptFN=None):
    
    if doCascade:
        method = "Cascade"
    else:
        method = "Parallel"
    
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath,
                        "resynthesize_from_klattgrid.praat")
    
    #  Praat crashes on exit after resynthesis with a klaatgrid
    utils.runPraatScript(praatEXE, scriptFN,
                         [wavFN, klattFN, outputWavFN, method])
示例#18
0
def _extractPIFile(inputFN,
                   outputFN,
                   praatEXE,
                   minPitch,
                   maxPitch,
                   sampleStep=0.01,
                   silenceThreshold=0.03,
                   pitchUnit="Hertz",
                   forceRegenerate=True,
                   undefinedValue=None,
                   medianFilterWindowSize=0,
                   pitchQuadInterp=False):
    '''
    Extracts pitch and intensity values from an audio file

    Returns the result as a list.  Will load the serialized result
    if this has already been called on the appropriate files before
    '''
    outputPath = os.path.split(outputFN)[0]
    utils.makeDir(outputPath)

    assert (os.path.exists(inputFN))
    firstTime = not os.path.exists(outputFN)
    if firstTime or forceRegenerate is True:

        # The praat script uses append mode, so we need to clear any prior
        # result
        if os.path.exists(outputFN):
            os.remove(outputFN)

        if pitchQuadInterp is True:
            doInterpolation = 1
        else:
            doInterpolation = 0

        argList = [
            inputFN, outputFN, sampleStep, minPitch, maxPitch,
            silenceThreshold, pitchUnit, -1, -1, medianFilterWindowSize,
            doInterpolation
        ]

        scriptName = "get_pitch_and_intensity.praat"
        scriptFN = join(utils.scriptsPath, scriptName)
        utils.runPraatScript(praatEXE, scriptFN, argList)

    piList = loadTimeSeriesData(outputFN, undefinedValue=undefinedValue)

    return piList
示例#19
0
def resynthesizePitch(praatEXE,
                      inputWavFN,
                      pitchFN,
                      outputWavFN,
                      minPitch,
                      maxPitch,
                      scriptFN=None):
    '''
    Resynthesizes the pitch in a wav file with the given pitch contour
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "resynthesize_pitch.praat")

    utils.runPraatScript(
        praatEXE, scriptFN,
        [inputWavFN, pitchFN, outputWavFN, minPitch, maxPitch])
示例#20
0
def getFormants(praatEXE,
                inputWavFN,
                outputTxtFN,
                maxFormant,
                stepSize=0.01,
                window_length=0.025,
                preemphasis=50,
                scriptFN=None,
                undefinedValue=None):
    '''
    Get F1, F2, and F3 for the audio file
    
    maxFormant = 5500 for females, 5000 for males, <8000 for children
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_formants.praat")

    argList = [
        inputWavFN, outputTxtFN, stepSize, maxFormant, window_length,
        preemphasis, -1, -1
    ]
    utils.runPraatScript(praatEXE, scriptFN, argList)

    # Load the output
    path, fn = os.path.split(outputTxtFN)
    dataList = utils.openCSV(path, fn)

    # The new praat script includes a header
    if dataList[0][0] == "time":
        dataList = dataList[1:]

    # Handle undefined values, convert values to float
    returnList = []
    for row in dataList:
        keep = True
        for i in range(1, 4):
            if '--' in row[i]:
                if undefinedValue is not None:
                    row[i] = undefinedValue
                else:
                    keep = False
                    break

        if keep is True:
            returnList.append([float(val) for val in row])

    return returnList
示例#21
0
def getPulses(praatEXE, inputWavFN, outputPointTierFN, minPitch, maxPitch,
              scriptFN=None):
    '''
    Gets the pitch/glottal pulses for an audio file.

    http://www.fon.hum.uva.nl/praat/manual/Sound___Pitch__To_PointProcess__peaks____.html
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_pulses.praat")
    
    argList = [inputWavFN, outputPointTierFN, minPitch, maxPitch]
    utils.runPraatScript(praatEXE, scriptFN, argList)
    
    # Load the output
    pointObj = dataio.open1DPointObject(outputPointTierFN)
    
    return pointObj
示例#22
0
def extractPitch(wavFN, outputFN, praatEXE,
                 minPitch, maxPitch, sampleStep=0.01,
                 silenceThreshold=0.03, forceRegenerate=True,
                 undefinedValue=None, medianFilterWindowSize=0,
                 pitchQuadInterp=False):
    '''
    Extract pitch at regular intervals from the input wav file
    
    Data is output to a text file and then returned in a list in the form
    [(timeV1, pitchV1), (timeV2, pitchV2), ...]
    
    sampleStep - the frequency to sample pitch at
    silenceThreshold - segments with lower intensity won't be analyzed
                       for pitch
    forceRegenerate - if running this function for the same file, if False
                      just read in the existing pitch file
    undefinedValue - if None remove from the dataset, otherset set to
                     undefinedValue
    pitchQuadInterp - if True, quadratically interpolate pitch
    '''
    outputPath = os.path.split(outputFN)[0]
    
    utils.makeDir(outputPath)
    
    if pitchQuadInterp is True:
        doInterpolation = 1
    else:
        doInterpolation = 0
    
    assert(os.path.exists(wavFN))
    firstTime = not os.path.exists(outputFN)
    if firstTime or forceRegenerate is True:
        if os.path.exists(outputFN):
            os.remove(outputFN)
        
        argList = [wavFN, outputFN, sampleStep,
                   minPitch, maxPitch, silenceThreshold, -1, -1,
                   medianFilterWindowSize, doInterpolation]
        
        scriptName = "get_pitch.praat"
        scriptFN = join(utils.scriptsPath, scriptName)
        utils.runPraatScript(praatEXE, scriptFN, argList)

    piList = loadTimeSeriesData(outputFN, undefinedValue=undefinedValue)

    return piList
示例#23
0
def changeGender(praatEXE, wavFN, outputWavFN, pitchFloor, pitchCeiling,
                 formantShiftRatio, pitchMedian=0.0, pitchRange=1.0,
                 duration=1.0, scriptFN=None):
    '''
    Changes the speech formants in a file using praat's change gender function

    PitchMedian = 0.0; no change in median pitch
    PitchRange = 1.0; no change in pitch range
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath,
                        "change_gender.praat")

    #  Praat crashes on exit after resynthesis with a klaatgrid
    utils.runPraatScript(praatEXE, scriptFN,
                         [wavFN, outputWavFN, pitchFloor, pitchCeiling,
                          formantShiftRatio, pitchMedian, pitchRange,
                          duration])
示例#24
0
def changeGender(praatEXE, wavFN, outputWavFN, pitchFloor, pitchCeiling,
                 formantShiftRatio, pitchMedian=0.0, pitchRange=1.0,
                 duration=1.0, scriptFN=None):
    '''
    Changes the speech formants in a file using praat's change gender function

    PitchMedian = 0.0; no change in median pitch
    PitchRange = 1.0; no change in pitch range
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath,
                        "change_gender.praat")

    #  Praat crashes on exit after resynthesis with a klaatgrid
    utils.runPraatScript(praatEXE, scriptFN,
                         [wavFN, outputWavFN, pitchFloor, pitchCeiling,
                          formantShiftRatio, pitchMedian, pitchRange,
                          duration])
示例#25
0
def getSpectralInfo(praatEXE, inputWavFN, inputTGFN, outputCSVFN, tierName,
                    spectralPower=2, spectralMoment=3, scriptFN=None):

    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_spectral_info.praat")
    
    argList = [inputWavFN, inputTGFN, outputCSVFN, tierName,
               spectralPower, spectralMoment]
    utils.runPraatScript(praatEXE, scriptFN, argList)
    
    # Load the output
    with io.open(outputCSVFN, "r", encoding="utf-8") as fd:
        data = fd.read()
    
    dataList = data.rstrip().split("\n")
    dataList = [row.split(",") for row in dataList]
    titleRow, dataList = dataList[0], dataList[1:]
    
    return titleRow, dataList
示例#26
0
def run_praat_script(filename, praat_exe, dname, audio_in, tg_in, pfloor,
                     pceiling, out):
    #print(dname)
    subinfo = []
    print(audio_in, tg_in)

    subinfo.append("Sending the following information to Praat Script:\n")
    subinfo.append("\tAudio File: %s\n" % audio_in)
    subinfo.append("\tText File: %s\n" % tg_in)
    subinfo.append("\tPath-to-Praat: %s\n" % praat_exe)
    praatscriptpath = os.path.join(dname, filename)
    #print(praatscriptpath)
    #audio_in = input("What audio file do you want to analyze? ")
    #tg_in = input("What is the matching TextGrid file? ")
    utils.runPraatScript(
        praat_exe, praatscriptpath,
        [audio_in.strip("'\ "),
         tg_in.strip("'\ "), pfloor, pceiling, out])
    return subinfo
示例#27
0
def getPulses(praatEXE,
              inputWavFN,
              outputPointTierFN,
              minPitch,
              maxPitch,
              scriptFN=None):
    '''
    Gets the pitch/glottal pulses for an audio file.

    http://www.fon.hum.uva.nl/praat/manual/Sound___Pitch__To_PointProcess__peaks____.html
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_pulses.praat")

    argList = [inputWavFN, outputPointTierFN, minPitch, maxPitch]
    utils.runPraatScript(praatEXE, scriptFN, argList)

    # Load the output
    pointObj = dataio.open1DPointObject(outputPointTierFN)

    return pointObj
示例#28
0
def _extractPIFile(inputFN, outputFN, praatEXE,
                   minPitch, maxPitch, sampleStep=0.01, silenceThreshold=0.03,
                   pitchUnit="Hertz", forceRegenerate=True,
                   undefinedValue=None, medianFilterWindowSize=0,
                   pitchQuadInterp=False):
    '''
    Extracts pitch and intensity values from an audio file

    Returns the result as a list.  Will load the serialized result
    if this has already been called on the appropriate files before
    '''
    outputPath = os.path.split(outputFN)[0]
    utils.makeDir(outputPath)
    
    assert(os.path.exists(inputFN))
    firstTime = not os.path.exists(outputFN)
    if firstTime or forceRegenerate is True:
        
        # The praat script uses append mode, so we need to clear any prior
        # result
        if os.path.exists(outputFN):
            os.remove(outputFN)
        
        if pitchQuadInterp is True:
            doInterpolation = 1
        else:
            doInterpolation = 0
    
        argList = [inputFN, outputFN, sampleStep,
                   minPitch, maxPitch, silenceThreshold, pitchUnit, -1, -1,
                   medianFilterWindowSize, doInterpolation]
        
        scriptName = "get_pitch_and_intensity.praat"
        scriptFN = join(utils.scriptsPath, scriptName)
        utils.runPraatScript(praatEXE, scriptFN, argList)

    piList = loadTimeSeriesData(outputFN, undefinedValue=undefinedValue)
    
    return piList
示例#29
0
def resynthesizePitch(praatEXE, inputWavFN, pitchFN, outputWavFN,
                      minPitch, maxPitch, scriptFN=None, pointList=None):
    '''
    Resynthesizes the pitch in a wav file with the given pitch contour file
    
    The pitch track to use can optionally be passed in as pointList.  If
    so, it will be saved as pitchFN for praat to be able to use.
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "resynthesize_pitch.praat")

    if pointList is not None:
        dur = audioio.WavQueryObj(inputWavFN).getDuration()
        pointObj = dataio.PointObject2D(pointList,
                                        dataio.PITCH,
                                        0,
                                        dur)
        pointObj.save(pitchFN)

    utils.runPraatScript(praatEXE, scriptFN,
                         [inputWavFN, pitchFN, outputWavFN,
                          minPitch, maxPitch])
示例#30
0
def getFormants(praatEXE, inputWavFN, outputTxtFN, maxFormant,
                stepSize=0.01, window_length=0.025, preemphasis=50,
                scriptFN=None, undefinedValue=None):
    '''
    Get F1, F2, and F3 for the audio file
    
    maxFormant = 5500 for females, 5000 for males, <8000 for children
    '''
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "get_formants.praat")

    argList = [inputWavFN, outputTxtFN, stepSize, maxFormant, window_length,
               preemphasis, -1, -1]
    utils.runPraatScript(praatEXE, scriptFN, argList)
    
    # Load the output
    path, fn = os.path.split(outputTxtFN)
    dataList = utils.openCSV(path, fn)

    # The new praat script includes a header
    if dataList[0][0] == "time":
        dataList = dataList[1:]
        
    # Handle undefined values, convert values to float
    returnList = []
    for row in dataList:
        keep = True
        for i in range(1, 4):
            if '--' in row[i]:
                if undefinedValue is not None:
                    row[i] = undefinedValue
                else:
                    keep = False
                    break
        
        if keep is True:
            returnList.append([float(val) for val in row])
    
    return returnList
示例#31
0
文件: kgio.py 项目: timmahrt/praatIO
def wavToKlattgrid(praatEXE, inputFullPath, outputFullPath, timeStep=0.005,
                   numFormants=5, maxFormantFreq=5500.0, windowLength=0.025,
                   preEmphasis=50.0, pitchFloor=60.0, pitchCeiling=600.0,
                   minPitch=50.0, subtractMean=True,
                   scriptFN=None):
    '''
    Extracts the klattgrid from a wav file
    
    The default values are the same as the ones used in praat
    '''
    
    if subtractMean is True:
        subtractMean = "yes"
    else:
        subtractMean = "no"
    
    if scriptFN is None:
        scriptFN = join(utils.scriptsPath, "sound_to_klattgrid.praat")
    
    utils.runPraatScript(praatEXE, scriptFN,
                         [inputFullPath, outputFullPath, timeStep,
                          numFormants, maxFormantFreq, windowLength,
                          preEmphasis, pitchFloor, pitchCeiling,
                          minPitch, subtractMean])