praat.praat 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. form Highlighter test
  2. sentence My_sentence This should all be a string
  3. text My_text This should also all be a string
  4. word My_word Only the first word is a string, the rest is invalid
  5. boolean Binary 1
  6. boolean Text no
  7. boolean Quoted "yes"
  8. comment This should be a string
  9. real left_Range -123.6
  10. positive right_Range_max 3.3
  11. integer Int 4
  12. natural Nat 4
  13. endform
  14. # External scripts
  15. include /path/to/file
  16. runScript: "/path/to/file"
  17. execute /path/to/file
  18. stopwatch
  19. # old-style procedure call
  20. call oldStyle "quoted" 2 unquoted string
  21. assert oldStyle.local = 1
  22. # New-style procedure call with parens
  23. @newStyle("quoted", 2, "quoted string")
  24. if praatVersion >= 5364
  25. # New-style procedure call with colon
  26. @newStyle: "quoted", 2, "quoted string"
  27. endif
  28. # if-block with built-in variables
  29. if windows
  30. # We are on Windows
  31. elsif unix = 1 or !macintosh
  32. exitScript: "We are on Linux"
  33. else macintosh == 1
  34. exit We are on Mac
  35. endif
  36. # inline if with inline comment
  37. var = if macintosh = 1 then 0 else 1 fi ; This is an inline comment
  38. # for-loop with explicit from using local variable
  39. # and paren-style function calls and variable interpolation
  40. n = numberOfSelected("Sound")
  41. for i from newStyle.local to n
  42. sound'i' = selected("Sound", i)
  43. sound[i] = sound'i'
  44. endfor
  45. for i from 1 to n
  46. # Different styles of object selection
  47. select sound'i'
  48. sound = selected()
  49. sound$ = selected$("Sound")
  50. select Sound 'sound$'
  51. selectObject(sound[i])
  52. selectObject: sound
  53. # Pause commands
  54. beginPause("Viewing " + sound$)
  55. if i > 1
  56. button = endPause("Stop", "Previous",
  57. ...if i = total_sounds then "Finish" else "Next" fi,
  58. ...3, 1)
  59. else
  60. button = endPause("Stop",
  61. ...if i = total_sounds then "Finish" else "Next" fi,
  62. ...2, 1)
  63. endif
  64. editor_name$ = if total_textgrids then "TextGrid " else "Sound " fi + name$
  65. nocheck editor 'editor_name$'
  66. nocheck Close
  67. nocheck endeditor
  68. # New-style standalone command call
  69. Rename: "SomeName"
  70. # Command call with assignment
  71. duration = Get total duration
  72. # Multi-line command with modifier
  73. pitch = noprogress To Pitch (ac): 0, 75, 15, "no",
  74. ...0.03, 0.45, 0.01, 0.35, 0.14, 600
  75. # do-style command with assignment
  76. minimum = do("Get minimum...", 0, 0, "Hertz", "Parabolic")
  77. # New-style multi-line command call with broken strings
  78. table = Create Table with column names: "table", 0,
  79. ..."file subject speaker
  80. ...f0 f1 f2 f3 " +
  81. ..."duration response"
  82. removeObject: pitch, table
  83. # Picture window commands
  84. selectObject: sound
  85. # do-style command
  86. do("Select inner viewport...", 1, 6, 0.5, 1.5)
  87. Black
  88. Draw... 0 0 0 0 "no" Curve
  89. Draw inner box
  90. Text bottom: "yes", sound$
  91. Erase all
  92. # Demo window commands
  93. demo Erase all
  94. demo Select inner viewport... 0 100 0 100
  95. demo Axes... 0 100 0 100
  96. demo Paint rectangle... white 0 100 0 100
  97. demo Text... 50 centre 50 half Click to finish
  98. demoWaitForInput ( )
  99. demo Erase all
  100. demo Text: 50, "centre", 50, "half", "Finished"
  101. endfor
  102. # An old-style sendpraat block
  103. sendpraat Praat
  104. ...'newline$' Create Sound as pure tone... "tone" 1 0 0.4 44100 440 0.2 0.01 0.01
  105. ...'newline$' Play
  106. ...'newline$' Remove
  107. # A new-style sendpraat block
  108. beginSendPraat: "Praat"
  109. Create Sound as pure tone: "tone", 1, 0, 0.4, 44100, 440, 0.2, 0.01, 0.01
  110. duration = Get total duration
  111. Remove
  112. endSendPraat: "duration"
  113. appendInfoLine: "The generated sound lasted for ", duration, "seconds"
  114. time = stopwatch
  115. clearinfo
  116. echo This script took
  117. print 'time' seconds to
  118. printline execute.
  119. # Old-style procedure declaration
  120. procedure oldStyle .str1$ .num .str2$
  121. .local = 1
  122. endproc
  123. # New-style procedure declaration
  124. procedure newStyle (.str1$, .num, .str2$)
  125. .local = 1
  126. endproc