1

I was wondering whether some can help me with a tricky thing which is extracting times and frequency of a Praat Pitch contour to a txt file.

I start from

File type = "ooTextFile"
Object class = "Pitch 1"

xmin = 0 
xmax = 1.592 
nx = 159 
dx = 0.01 
x1 = 0.006002267573695814 
ceiling = 1900 
maxnCandidates = 2 
frame []: 
    frame [1]:
        intensity = 0 
        nCandidates = 1 
        candidate []: 
            candidate [1]:
                frequency = 0 
                strength = 0.9 
    frame [2]:
        intensity = 0 
        nCandidates = 1 
        candidate []: 
            candidate [1]:
                frequency = 0 
                strength = 0.9 
    frame [3]:
        intensity = 0 
        nCandidates = 1 
        candidate []: 
            candidate [1]:
                frequency = 763.0480724135344 
                strength = 0.9 
    frame [4]:
        intensity = 0 
        nCandidates = 1 
        candidate []: 
            candidate [1]:
                frequency = 763.3612753914916 
                strength = 0.9 
....

and I would like to go to:

0,0
t1,0
t2,763.0480724135344
t3,763.3612753914916 
....
tn, ...

It would also be great if the script could read the information in "dx =" and compute times for the x coordinates.

Thanks in advance for your help.

Marco
  • 31
  • 4

1 Answers1

1

I've been working on some procedures to quickly convert different object types to Table representations of them, and Pitch objects are relatively straightforward. Try this:

# Execute this with your Pitch object selected
@pitchToTable()

procedure pitchToTable ()
  .obj = selected("Pitch")
  .name$ = extractWord$(selected$(), " ")
  .t1 = Get time from frame number: 1
  .m1  = To Matrix
  .m2  = Transpose
  .tor = To TableOfReal
  .id  = To Table: "Time"
  Set column label (index): 2, "F0"
  Formula: "Time", "'.t1' + (Object_'.obj'.dx * (row - 1))"
  Formula: "F0", "if self then self else undefined fi"
  Rename: .name$ + "_pitch"
  removeObject: .m1, .m2, .tor
endproc

The conversion makes use of the fact that most Praat objects can be cast to a Matrix object, which is already basically a Table. In this case, the only manipulations that need to take place are the transposing (to have a vertical table), and renaming the columns.

jja
  • 2,058
  • 14
  • 27
  • Thanks jja. It is a nice way to extract time and F0. I was used to doing something like what you suggested but it would also be nice to have a way to extract data from the Pitch file instead, isn't it? – Marco Jul 23 '16 at 19:42
  • I'm not sure I get what you mean. You mean _without using Praat_? I personally think this is not a good idea, since these formats have not been designed for exporting to external applications. Using the Praat interpreter is the best way to do it. But if you must, this can be changed into mostly-complying YAML using regular expressions, as I do in [praat2yaml.pl](https://gitlab.com/cpran/plugin_serialise/blob/master/scripts/praat2yaml.pl#L244-300). If you prefer that, I'm happy to extend the answer, but I think you might want to clarify in your question as well. – jja Jul 24 '16 at 16:27
  • I loved your answer and will definitely follow that way and integrate something like that in one of my scripts. I was just pointing that it would have also been nice to have ways, possibly excluding the use of Praat, to process the files and get the same results. If you have time I would love to see an extension of what you suggest above. If you have no time, let me thank you again for your time and your help. – Marco Jul 25 '16 at 18:40