Praat scripting notes: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m (→Unsorted) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{#addbodyclass:tag_ling}} | {{#addbodyclass:tag_ling}} | ||
{{ling}} | {{ling}} | ||
https://www.fon.hum.uva.nl/praat/manual/Scripting.html | |||
==Data types and structures== | |||
<!-- | <!-- | ||
There are broadly two types: numeric and string | |||
sentence | |||
In forms, [https://www.fon.hum.uva.nl/praat/manual/Scripting_6_1__Arguments_to_the_script.html] represent types and some GUI filtering of their values | |||
word - string without spaces | |||
sentence - string with spaces | |||
text - string with spaces | |||
comment | comment | ||
real | |||
positive - real > 0 | |||
integer | integer | ||
natural - integer >= 1 | |||
realvector | |||
positivevector | |||
integervector | |||
naturalvector | |||
boolean | |||
choice | |||
option | |||
infile | |||
outfile | |||
folder | |||
--> | |||
===String operations=== | |||
<!-- | |||
noext$ = filename$ - ".wav" | |||
Read from file: noext$ + ".wav" | |||
writeInfoLine: “The value is ”, b, “.” | |||
# comment (beginning of line only) | |||
not whitespace sensitive (anymore), and people like indenting to suggest structure | |||
--> | |||
===Structures=== | |||
<!-- | |||
https://www.fon.hum.uva.nl/praat/manual/Scripting_5_6__Arrays_and_dictionaries.html | |||
https://www.fon.hum.uva.nl/praat/manual/Scripting_5_7__Vectors_and_matrices.html | |||
--> | |||
==Objects and selections== | |||
<!-- | |||
Line 53: | Line 92: | ||
** selected (type$) - return ID of first selected object of the type | ** selected (type$) - return ID of first selected object of the type | ||
** selected (type$, i) - return ID of so-manieth selected object of the type | ** selected (type$, i) - return ID of so-manieth selected object of the type | ||
--> | |||
==Files and commands== | |||
<!-- | |||
Praat info window | |||
* appendInfoLine - add to info window content | |||
* writeInfoLine - replace all info window content with this (you may prefer to use only append, and the occsaional clearinfo) | |||
* clearinfo - clear info window content | |||
* appendInfo | |||
String variable names end with dollar, numerics do not | |||
fileReadable(path$) - returns 1 if readable, 0 if not | |||
readfile$(path$) - return file contents as string | |||
readfile(path$) - return number from text file | |||
https://www.fon.hum.uva.nl/praat/manual/_readFile-S_.html | |||
environment$(string$) https://www.fon.hum.uva.nl/praat/manual/_environment-S_.html | |||
runSystem: https://www.fon.hum.uva.nl/praat/manual/_runSystem_.html | |||
runSubprocess(cmd$) - run command | |||
runSubprocess$(cmd$) - runSubprocess(cmd$) and return its output | |||
runSystem$ | |||
runScript [https://www.fon.hum.uva.nl/praat/manual/_runScript_.html] | |||
pauseScript [https://www.fon.hum.uva.nl/praat/manual/_pauseScript_.html] | |||
https://www.fon.hum.uva.nl/praat/manual/Scripting_5_8__Including_other_scripts.html | |||
sendsocket fonsg19.hum.uva.nl:6667 display hallo.wav | |||
https://www.fon.hum.uva.nl/praat/manual/Scripting_6_9__Calling_from_the_command_line.html | |||
Line 73: | Line 162: | ||
untitled | untitled | ||
--> | |||
== == | |||
<!-- | |||
for i from 1 to nFiles | |||
mycode | |||
endfor | |||
while x < 0 | |||
x = x + 2 * pi | |||
endwhile | |||
throws = 0 | |||
repeat | |||
eyes = randomInteger (1, 6) + randomInteger (1, 6) | |||
throws = throws + 1 | |||
until eyes = 12 | |||
writeInfoLine: "It took me ", throws, " trials to throw 12 with two dice." | |||
if i < 20 and word$ = “STIM” | if i < 20 and word$ = “STIM” | ||
Line 106: | Line 194: | ||
Procedures: | |||
https://www.fon.hum.uva.nl/praat/manual/Scripting_5_5__Procedures.html | |||
==Forms== | |||
<!-- | |||
form presens a form | form presens a form | ||
Line 155: | Line 218: | ||
endform | endform | ||
--> | |||
==Drawing== | |||
<!-- | |||
Erase all | |||
Draw inner box | |||
Erase all | |||
--> | |||
==External scripting== | ==External scripting== | ||
Line 182: | Line 246: | ||
--> | |||
==Extending praat== | |||
<!-- | |||
Add menu command... | |||
Add action command... | |||
--> | |||
==Unsorted== | |||
<!-- | |||
'''scripts look like wording, but you won't understand why it works until you figure out the predefined things it's referencing''' | |||
Consider: | |||
Create Strings as file list: "*.wav" | |||
num_files = Get number of strings | |||
for i from 1 to num_files | |||
selectObject: "Strings files" | |||
filename$ = Get string: i | |||
basename$ = filename$ - ".wav" | |||
Read from file: dir$ + basename$ + ".wav" | |||
endfor | |||
Why does "Get number of files" or "Get String" work? | |||
'''Get is a little magical''' | |||
* Get mean... | |||
Create Strings as file list... list 'source_directory$'/'file_name_or_initial_substring$'*'file_extension$' | |||
head_words = selected("Strings") | |||
--> | --> |
Latest revision as of 13:16, 20 June 2024
https://www.fon.hum.uva.nl/praat/manual/Scripting.html