Skip to content

Instantly share code, notes, and snippets.

@Gabrock94
Created November 1, 2019 04:01
Show Gist options
  • Save Gabrock94/4b82d3f8068c51b848a53afe3f6caa58 to your computer and use it in GitHub Desktop.
Save Gabrock94/4b82d3f8068c51b848a53afe3f6caa58 to your computer and use it in GitHub Desktop.
This script can be used to automatically analyze all the audio files contained in a single folder. Settings are Optimized for cry analysis.
#############################################################################################
# Extract f0, f1-f4 and Intensity from all the wav (or .xyz) files stored in a directory #
# #
# Giulio Gabrieli #
# v.1.0.1 #
# Last Edit: 11/04/2019 #
#############################################################################################
#Change this line with the location of the Wav files
directory$ = "C:\Users\giulio001\Desktop\Cry_DEP\Raw\Extracted\7\"
#This is the name of the output file (csv)
outputfile$ = "Output_DEP_PraatOptimized_07"
form Files
endform
clearinfo
strings = Create Strings as file list: "list", directory$ + "/*.wav" #File format can be changed here
numberOfFiles = Get number of strings
writeFileLine: outputfile$+".csv", "ID,tmin, tmax, f0, f0_min, f0_max, std_f0, f1, f2, f3, f4, Intensity"
for ifile to numberOfFiles
selectObject: strings
fileName$ = Get string: ifile
relativo = ifile / numberOfFiles
percentuale = relativo * 100
clearinfo
appendInfoLine: percentuale
Read from file: directory$ + "/" + fileName$
soundname$ = selected$ ("Sound")
To Pitch... 0.01 250 800
select Pitch 'soundname$'
startTime = Get start time
endTime = Get end time
numberOfTimeSteps = (endTime - startTime) / 0.05
selectObject: strings
fileName$ = Get string: ifile
Read from file: directory$ + "/" + fileName$
soundname$ = selected$ ("Sound")
To Formant (burg)... 0.01 5 6000 0.05 50
selectObject: strings
fileName$ = Get string: ifile
Read from file: directory$ + "/" + fileName$
soundname$ = selected$ ("Sound")
To Intensity... 50 0.01
for step to numberOfTimeSteps
appendFile: outputfile$+".csv", fileName$,","
select Pitch 'soundname$'
tmin = startTime + (step - 1) * 0.05
tmax = tmin + 0.05
midpoint = (tmin + tmax) / 2
mean = Get mean: tmin, tmax, "Hertz"
minimum = Get minimum: tmin, tmax, "Hertz", "Parabolic"
maximum = Get maximum: tmin, tmax, "Hertz", "Parabolic"
stdev = Get standard deviation: tmin, tmax, "Hertz"
appendFile: outputfile$+".csv", fixed$ (tmin, 6), ",", fixed$ (tmax, 6), ",", fixed$ (mean, 2),
... ",", fixed$ (minimum, 2), ",", fixed$ (maximum, 2), ",", fixed$ (stdev, 2),","
select Formant 'soundname$'
f1 = Get value at time... 1 midpoint Hertz Linear
f2 = Get value at time... 2 midpoint Hertz Linear
f3 = Get value at time... 3 midpoint Hertz Linear
f4 = Get value at time... 4 midpoint Hertz Linear
appendFile: outputfile$+".csv", fixed$ (f1, 6), ",",fixed$ (f2, 6), ",",fixed$ (f3, 6), ",",fixed$ (f4, 6),","
select Intensity 'soundname$'
intensity = Get value at time... midpoint Cubic
appendFileLine: outputfile$+".csv", fixed$ (intensity, 6)
endfor
endfor
appendInfoLine: "All done :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment