Log files

With some commands in the Analyses menu of the SoundEditor and TextGridEditor, you can write combined information about times, pitch values, formants, and intensities to the Info window and/or to a log file.

A log file is a text file on disk. It consists of a number of similar lines, whose format you determine with the log settings in the Analyses menu.

Every time you press F12 (or choose Log 1 from the Analysis menu), Praat will write a line to the Info window and/or to log file 1. If you press Shift-F12 (or choose Log 2 from the Analysis menu), Praat will write a line to the Info window and/or to log file 2.

With the log settings command window, you determine the following:

Write log 1 to
  this determines whether your log line will be written to log file 1 only, to the Info window only, or to both.
Log file 1
  the name of the log file. Click Browse to select a file to write to. On most platforms you can also use a home-relative name such as `~/Desktop/pitchLog.txt`.
Log 1 format
  the format of the line that Praat will write. See below.

The same goes for log file 2.

## Usage

The logging facility has been implemented in Praat especially for former users of Kay CSL, who have been used to doing it for years and like to continue doing it in Praat. Otherwise, you may prefer to use the TextGridEditor to mark time points and run an automatic analysis afterwards.

If you do want to use the logging facility, you typically start by deleting any old log file (by choosing Delete log file 1 or Delete log file 2), if you want to re-use the file name. Otherwise, you can change the log file name (with Log settings...). After this, you will move the cursor to various time locations and press F12 (or Shift-F12) each time, so that information about the current time will be written to the log file.

## Example 1: pitch logging

Suppose you want to log the time of the cursor and the pitch value at the cursor. You could use the following log format:

`Time 'time:6' seconds, pitch 'f0:2' hertz
`

If you now click at 3.456789876 seconds, and the pitch happens to be 355.266 hertz at that time, the following line will be appended to the log file and/or to the Info window:

`Time 3.456790 seconds, pitch 355.27 hertz.
`

The parts ":6" and ":2" denote the number of digits after the decimal point. If you leave them out, the values will be written with a precision of 17 digits.

The words 'time' and 'f0' mean exactly the same as the result of the commands Get cursor and Get pitch. Therefore, if instead of setting a cursor line you selected a larger piece of the sound, 'time' will give the centre of the selection and 'f0' will give the mean pitch in the selection.

Beware of the following pitfall: if your pitch units are not hertz, but semitones, then 'f0' will give the result in semitones. A format as in this example will then be misleading.

## Example 2: formant logging

Suppose you want to log the start and finish of the selection, its duration, and the mean values of the first three formants, all separated by tab stops for easy importation into Microsoft® Excel™. You could use the following log format:

`'t1:4''tab$''t2:4''tab$''f1:0''tab$''f2:0''tab$''f3:0'
`

You see that 't1' and 't2' are the start and finish of the selection, respectively, and that they are written with 4 digits after the decimal point. By using ":0", the three formant values are rounded to whole numbers in hertz. The word `tab$` is the tab stop.

## Loggable values

The following values can be logged:

  `time`: the time of the cursor, or the centre of the selection.
  `t1`: the start of the selection ("B").
  `t2`: the end of the selection ("E").
  `dur`: the duration of the selection.
  `freq`: the frequency at the frequency cursor.
  `f0`: the pitch at the cursor time, or the mean pitch in the selection.
  `f1`, `f2`, `f3`, `f4`, `f5`: the first/second/third/fourth/fifth formant at the cursor time, or the mean first/second/third/fourth/fifth formant in the selection.
  `b1`, `b2`, `b3`, `b4`, `b5`: the bandwidth of the first/second/third/fourth/fifth formant at the cursor time or at the centre of the selection.
  `intensity`: the intensity at the cursor time, or the mean intensity in the selection, in dB.
  `power`: the spectral power at the cursor cross, in Pa2/Hz.
  `tab$`: the tab stop.
  `editor$`: the title of the editor window (i.e. the name of the visible Sound or TextGrid).

## More flexibility in logging

You may sometimes require information in your log file that cannot be generated directly by the loggable values above. Suppose, for instance, that you want to log the values for F1 and F2-F1 at the points where you click. You could write the following script:

`f1 = Get first formant
` `f2 = Get second formant
` `f21 = f2 - f1
` `appendInfoLine: fixed$ (f1, 0), " ", fixed$ (f21, 0)
` `appendFileLine: "D:\Praat logs\Formant log.txt", fixed$ (f1, 0), tab$, fixed$ (f21, 0)
`

With this script, the information would be appended both to the Info window and to the file "Formant log.txt" on your desktop.

You can make this script accessible with Option-F12 (or Command-F12) by saving the script and specifying the name of the script file in the Log script 3 (or 4) field in the Log settings... window.

These scripts may take arguments. Suppose, for instance, that you want to specify a vowel symbol as you press Option-F12. The following script will take care of that:

`form: "Save vowel and formants"
` `word: "Vowel", "a"
` `endform
` `f1 = Get first formant
` `f2 = Get second formant
` `f21 = f2 - f1
` `appendInfoLine: vowel$, " ", fixed$ (f1, 0), " ", fixed$ (f21, 0)
` `appendFileLine: "~/Praat logs/Vowels and formants log", vowel$, tab$, fixed$ (f1, 0), tab$, fixed$ (f21, 0)
`

Beware of the following pitfall: because of the nature of scripts, you should not try to do this when you have two editor windows with the same name. We cannot predict which of the two windows will answer the Get queries...

### Links to this page

- What was new in 4.0?