just working with Praat at the moment, and I\'m trying to write a script to do the following with a collection of 3 Sound (narrative) files. I\'ve managed as far as c), the
The easiest way to do this would be to write your output to a Table
object and then use Praat's Save to comma-separated file
command to save it to an external file. Examples below use the new (slightly more reasonable) new syntax, so make sure to update Praat before trying them out (or try the shorthand versions in this answer's edit history).
Here's an example:
# Create a Table with no rows
table = Create Table with column names:
..."table", 0, "Narrative Label Midpoint Time F1 F2 F3"
for i to number_of_intervals
# Assuming you have your Formant objects in an array named "burg"
selectObject(burg[i])
# Run your analysis here
# For this example, I'm assuming values for the columns are in
# variables called narrative$, label$, midpoint, time, f1, f2 and f3
selectObject(table)
Append row
current_row = Get number of rows
# Insert your values
Set string value: current_row, "Narrative", narrative$
Set string value: current_row, "Label", label$
Set numeric value: current_row, "Midpoint", midpoint
Set numeric value: current_row, "Time", time
Set numeric value: current_row, "F1", f1
Set numeric value: current_row, "F2", f2
Set numeric value: current_row, "F3", f3
endfor
# Save it!
# Remember to select it if the table is not the active selection at
# the end of the loop
Save to comma-separated file: /path/to/file
# And then you can get rid of it
removeObject(table)
Or you could use, if you prefer tabs
Save to tab-separated file: /path/to/file
Note that this method won't allow you to have "Narrative#" as a column name.
Alternatively, you could use Praat's file directives write directly to the file as explained in the documentation:
sep$ = ","
# sep$ = tab$
# Create / overwrite file and write header
writeFileLine: "/path/to/file",
..."Narrative#" + sep$ +
..."Label" + sep$ +
..."Midpoint" + sep$ +
..."Time" + sep$ +
..."F1" + sep$ +
..."F2" + sep$ +
..."F3"
for i to number_of_intervals
selectObject(burg[i])
# Run your analysis here
appendFileLine: "/path/to/file",
...narrative$ + sep$ +
...label$ + sep$ +
...string$(midpoint) + sep$ +
...string$(time) + sep$ +
...string$(f1) + sep$ +
...string$(f2) + sep$ +
...string$(f3)
endfor