scriptingpraat

How to get or save the pitch listing in praat using scripting


I am trying to use scripting in praat to either save or write to a file with the values given from using "Pitch Listing" under "Pitch". This is my code for the script so far:

selectObject: 1
View & Edit
editor: 1
    Select: 0.0, 10000
    Pitch listing
    p$ = Get pitch
    fileappend pitch123.txt 'p$'

This code only returns the mean for the sound file and I am wondering if there is a way to avoid getting small chunks of the file and getting the average pitch and instead being able to get the data given the way praat does it like so :

Time_s   F0_Hz
0.254558   125.982312
0.264558   127.975510
0.274558   123.010164
0.284558   120.761760
0.294558   119.652539
0.304558   118.916850

Even just being able to save the file that pops up from "Pitch Listing" would work. Any help is appreciated. Thanks!


Solution

  • Using the new syntax (Praat >= 5.3.63), you can create a Pitch object and loop through the frames to get the Pitch value for that frame (by default, one frame every 10 msec).

    writeFileLine: "./pitch_list.txt", "time,pitch"
    selectObject: 1
    To Pitch: 0, 75, 600
    no_of_frames = Get number of frames
    
    for frame from 1 to no_of_frames
        time = Get time from frame number: frame
        pitch = Get value in frame: frame, "Hertz"
        appendFileLine: "pitch_list.txt", "'time','pitch'"
    endfor