Reputation: 31
I am interested in using Praat for some bulk analysis of a few hundred .wav audio samples (around 10 seconds each). Is it possible for Praat to analyze all files in a directory, "get pitch" for each file (or get voice report), and print all these out to a .csv or .txt file?
I've tried modifying a few scripts available online, but having little programming knowledge, I am finding this difficult. If anyone provide some code to get me started, I would greatly appreciate it!
Upvotes: 3
Views: 962
Reputation: 2098
The way Praat works with directory listings is with the Strings
object. You can generate a Strings
object with names of files or of directories, and then loop through those to open each individual file and process it in whichever way you prefer.
As for the output, you could manually output to a text file, or you could save the results of your analyses in a Table
object, that can then be saved as a csv
or txt
as you prefer. You can see this in action in my related answer.
In this case, what you want is something like this
form Process files...
sentence Path /path/to/your/files
endform
# Optional: make sure the path has a trailing slash
path$ = if right$(path$) = "/" then path$ else path$ + "/" fi
output = Create Table with column names: "output", 0,
... "file mean_pitch"
files = Create Strings as file list: "files", path$ + "*wav"
total_files = Get number of strings
for i to total_files
selectObject: files
filename$ = Get string: i
sound = Read from file: path$ + filename$
# Run whatever kind of analysis you want here
# For example, get the mean pitch for each file
pitch = To Pitch: 0, 75, 600
mean = Get mean: 0, 0, "Hertz"
selectObject: output
Append row
row = Get number of rows
Set string value: row, "file", filename$
Set numeric value: row, "mean_pitch", mean
removeObject: sound, pitch
endfor
selectObject: output
Save as comma-separated file: path$ + "output.csv"
removeObject: files, output
Upvotes: 4