[[FrontPage]]

* A Quick Look at Praat Scripting [#ncd89e32]

The contents in this page are fragmentary. Consult other sources if you want to learn Praat Scripting from a scratch((Highly recommanded: Ingmar Steiner (2006-2007) '''Automatic Speech Data Processing with Praat'''. Lecture Notes. (PDF file is available at: http://www.coli.uni-saarland.de/~steiner/praat/lecturenotes.pdf .) )).
//PDF file is [[here>www.coli.uni-saarland.de/~steiner/praat/lecturenotes.pdf]]. 

#contents

** Language Specification Worth Mentioning [#b3a53f90]

//- No declaration is required to use a variable.

- Comments
-- "''#''" and "'';''" are comment characters. Praat ignores the comment characters and after them, to the end of the line.
-- If you want to write a comment at the end of a statement, for example, you can use ";", instead of "#"
 str$ = "abcdefg"         ; string variable
 num = 3                  ; numeric variable
 echo 'str$''tab$''num'
 # An error occurs if ";" is replaced with "#"

- Variable Types
-- numerics and strings
--- Variables (either numeric or string) must begin with lower cases.
--- String variables must end with ''$''.
 str$ = "foo"
 num = 3
 ### statements below causes an error. ###
 #Str$ = "foo"  ; it begins with Upper case.
 #Num = 3
 #str = "foo"   ; it lacks $, though it has a string.
-- Arrays are also available.
--- The indices are enclosed with ''"["'' and ''"]"''
--- Like scalars, arrays must begin with lower cases.
--- Arrays which store strings must have ''$'' before ''"["''
 str$[1] = "foo"
 str$[2] = "bar"
 str$[3] = "hoge"
 str$[4] = "piyo"
 num[1] = 3
 num[2] = 34
 num[3] = 22
 num[4] = 98
 ### statements below causes an error. ###
 #str[1] = "foo"   ; it lacks $, though it has a string.
 #Num[4] = 98      ; it begins with Upper case.
-- Unfortunately, hashes (or associative arrays) are not available.

- Operators
-- Comparison Operators
--- The "euqal" operator is "="((You can also use "==" as an equal operator.)).
 num = 3
 str$ = "hoge"
 
 clearinfo
 if num = 3
     printline 'num'
 endif
 
 if str$ = "hoge"
     printline 'str$'
 endif

-- Strings
--- Using "+" and "-", not only string "addition" (i.e., concatenation), but also string "subtraction" (i.e., truncation) is possible.
 str1$ = "abc"
 str2$ = "def"
 str3$ = "c"
 
 str4$ = str1$ + str2$
 str5$ = str1$ - str3$
 
 clearinfo
 printline 'str4$'
 printline 'str5$'

--- result:
 abcdef
 ab


- index numbers start at 1 (not 0).

- 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'' 
-- It is not possible to decrement the loop counter in ''for''-loop. Use ''while-endwhile'', instead.
 n = 10
 clearinfo
 while n >= 1
     printline 'n'
     n = n-1
 endwhile

- Regular expressions are available in many functions.

- ''form'' and ''endform''

- No double quotations are required in ''print'' (and ''printline'' and ''echo'')

- procedures (or subroutines/functions)

- ''system''

- Consider the use of ''Table Object'' when you refer to the contents in text files.

- [[Scripting 3.1. Hello world>http://www.fon.hum.uva.nl/praat/manual/Scripting_3_1__Hello_world.html]] (official site)

** Functions of ScriptEditor [#m4b8a142]
- History
- Run a script

** Other ways to execute a script [#c753a9f4]

- sendpraat.exe
- praatcon.exe (in Windows)
-- scripts can be executed by using sendpraat.exe or praatcon.exe.
-- You may use option -a in praatcon.exe if you handle Unicode. (cf. [[Re: [praat-users] Bug in latest praatcon version (by Paul Boersma)>http://uk.groups.yahoo.com/group/praat-users/message/4950]]

Front page   New List of pages Search Recent changes   Help   RSS of recent changes