Praat scripting from Pitch file to table

468 views Asked by At

I'm having some problem with Praat. In particular I need to write a script that extracts, given an audio file, pitch, pitch tier, point process and voice report and then saves all the results in different comma-separated-values files as if they were .csv that I need to open later with Python. As long as I save these results as Praat text files I have no problems, but when it comes to tables I'm able to create them only with pitch tier and voice report. With the pitch I tried to read the various attributes manually to build a table but some of them are not accessible, the big problem is when I try to access the frames that results in a failed execution of the script (here is the code I'm using)

audio = Read from file:name$

pitch = To Pitch: 0.0, 75, 300

pitch_table_columns$ = "xmin xmax nx dx x1 ceiling max_n_candidates frame_n frame_intensity frame_n_candidates frame_candidate_n frame_candidate_frequency frame_candidate_strength"
pitch_table = Create Table with column names: "pitch_table", 0, pitch_table_columns$

selectObject: pitch
xmin = Object_'pitch'.xmin
xmax = Object_'pitch'.xmax
nx = Object_'pitch'.nx
dx = Object_'pitch'.dx
#x1 = Object_'pitch'.x1
#ceiling = 300
#maxncandidates = Object_'pitch'.maxnCandidates
frames = Get number of frames
selectObject: pitch
for i from 1 to frames
    #intensity = Object_'pitch'.frame[i].intensity
    ncandidates = Object_'pitch'.frame[i].nCandidates
    for j in ncandidates
        frequency = Object_'pitch'.frame[i].candidate[j].frequency
        strength = Object_'pitch'.frame[i].candidate[j].strength
        selectObject: pitch_table
        Append row
        r = Get number of rows
        Set numeric value: r, "xmin", xmin
        Set numeric value: r, "xmax", xmax
        Set numeric value: r, "nx", nx
        Set numeric value: r, "dx", dx
        Set numeric value: r, "x1", x1
        Set numeric value: r, "ceiling", ceiling
        Set numeric value: r, "max_n_candidates", maxncandidates
        Set numeric value: r, "frame_n", i
        Set numeric value: r, "frame_intensity", intensity
        Set numeric value: r, "frame_n_candidates", ncandidates
        Set numeric value: r, "frame_candidate_n", j
        Set numeric value: r, "frame_candidate_frequency", frequency
        Set numeric value: r, "frame_candidate_strength", strength
    endfor
endfor

selectObject: pitch
Save as text file: "pitch.Pitch"

selectObject: pitch_table
Save as comma-separated file: "table.csv"

Commented out lines are for the attributes a I cannot access, however when I get to

ncandidates = Object_'pitch'.frame[i].nCandidates

the script fails and this forbids me to keep going. Similarly I don't know how to get the table from the point process. Anyone knows what is wrong with my code or if there is a better way to achive the same (or at least similar) results?

0

There are 0 answers