Extract pitch values, intensity, time, and confidence from all wav files in the working directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clearinfo | |
# uncomment for a point-and-click version (then the next two lines should be commented out) | |
#inDir$ = chooseDirectory$: "Choose the folder containing your wav files" | |
wd$ = "./" | |
inDir$ = wd$ | |
# create a list of all wav files in the chosen directory | |
inDirWild$ = inDir$ + "*.wav" | |
# get the names of the wav files | |
wavList = Create Strings as file list: "wavList", inDirWild$ | |
# see how many wavs there are for the loop | |
numFiles = Get number of strings | |
# if there are no files, throw an error | |
if numFiles == 0 | |
exitScript: "I didn't find any .wav files in that folder. Exiting" | |
endif | |
# create the output directory - otherwise the script will crash | |
runSystem: "mkdir pitch_output" | |
# run the loop | |
for fileNum from 1 to numFiles | |
# select objects explicitly at the beginning of a loop, since | |
# they may not be selected by the end | |
selectObject: wavList | |
wavFile$ = Get string: fileNum | |
# load the wav | |
wav = Read from file: inDir$ + wavFile$ | |
# create pitch object | |
# GUI: Analyse Periodicity > To Pitch | |
# Settings: Time step (0); Pitch floor (75 Hz); Pitch ceiling (default: 600 Hz) | |
textGrid = To Pitch: 0, 75, 400 | |
# choose the output folder | |
outPathFolder$ = "pitch_output/" | |
# output file name | |
outPath$ = outPathFolder$ + wavFile$ + ".pitch" | |
# do not overwrite files | |
if fileReadable: outPath$ | |
pauseScript: objName$ + ".pitch" + " exists! Overwrite?" | |
endif | |
# write the text file | |
Save as text file: outPath$ | |
# Remove newly opened objects for cleanup | |
selectObject: wav | |
plusObject: textGrid | |
Remove | |
endfor | |
# Remove the wav list | |
selectObject: wavList | |
Remove |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment