FrontPage
A Quick Look at Praat Scripting †
- This page is intended as a brief but somewhat "unorthodox" introduction to Praat scripting.
- The primary target readers are ones who have some (partial) knowledge about programming/script language (e.g., C, perl, awk, python, VBA), and thus know, say, what array/if (conditional)/for (iteration, loop) mean. If you new to programming, see other sources*1.
- The contents are fragmentary. For unknown commands, consult Help in Praat first. It provides you valuable information.
Table of Contents
Hello world †
- Choose New Praat script from the Praat menu to open the ScriptEditor window.
- Type:
echo Hello world
- Choose Run from the Run menu (or type C-r) to execute.
Language Specification Worth Mentioning †
General †
- Output to the Info Window: echo, printline, and print
- The three scripts below work in the same way (clearinfo clears the Info window):
- The two scripts below, however, do not work in the same way.
- Comments
- Variable Types
- numerics and strings
- Arrays are also available.
- Unfortunately, hashes (or associative arrays) are not available.
- Strings
- autoincrement/autodecrement operators (e.g., i++, i--) are not available.
- Conditional statements
- if(-elsif)(-else)-endif
- NOTE: elsif (or elif), rather than elseif and else if.
- Loops
- for i (from m) to n-endfor, while-endwhile, repeat-until
- Subroutines: procedure-endproc
- Regular expressions are available in some string functions:
- index_regex(str$,regex$)
- rindex_regex(str$,regex$)
- replace_regex$(str$,regex$,substr$,n)
- Generally, index numbers start at 1 (not 0).
- Check, for example, the value of the following string functions:
- mid$(str$,index,len)
str$ = "abcdefg"
len = length(str$)
clearinfo
for i from 1 to len
hop$ = mid$(str$,i,1)
printline 'i''tab$''hop$'
endfor
- index(str$,substr$)
str$ = "abcdefg"
substr$ = "bcd"
clearinfo
n = index(str$,substr$)
printline 'n'
Particular to Praat (1): Object Manipulation †
Those who conquer object manipulation techniques conquer Praat scripting. (The present author)
Particular to Praat (2): form-endform †
Functions of ScriptEditor †
Other ways to execute a script †
- praatcon.exe (in Windows)
- sendpraat.exe
|