Praat scripting notes: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 4: | Line 4: | ||
<!-- | <!-- | ||
Types | |||
Form types | |||
sentence | |||
comment | |||
integer | |||
positive | |||
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 | |||
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$ | |||
For anything more complex, you will be working with '''the list and selections within it''' | |||
* [https://www.fon.hum.uva.nl/praat/manual/_selectObject_.html selectObject] change selection, by ID or name | |||
* [https://www.fon.hum.uva.nl/praat/manual/_plusObject_.html plusObject] add to current selection, by ID or name | |||
* [https://www.fon.hum.uva.nl/praat/manual/_minusObject_.html minusOject] removes from current selection, by ID or name | |||
* [https://www.fon.hum.uva.nl/praat/manual/_removeObject_.html removeObject] removes objects from list | |||
:: if in the selection, removes that; does not otherwise affect the selection | |||
* selected$() is a function that returns the '''name''' of objects within the selection | |||
** selected$() | |||
** selected$(num) | |||
** selected$(type$) | |||
** selected$(type$, num) | |||
* selected() is a function that returns the '''ID''' of objects within the selection | |||
** selected() - return ID of the topmost selected object | |||
** selected(number) - return ID of so-manieth item (from the bottom if negative) | |||
** selected (type$) - return ID of first selected object of the type | |||
** selected (type$, i) - return ID of so-manieth selected object of the type | |||
An object has a full name and a given name, e.g. when you start fresh and create a recording, then | |||
writeInfoLine () | |||
appendInfoLine( selected$() ) | |||
appendInfoLine( selected$("Sound") ) | |||
will print | |||
Sound untitled | |||
untitled | |||
The first is a full name, the second a given name. You could split those out like:. | |||
fullName$ = selected$() | |||
type$ = extractWord$ (fullName$, "") | |||
name$ = extractLine$ (fullName$, " ") | |||
appendInfoLine( type$ ) | |||
appendInfoLine( name$ ) | |||
Which would give: | |||
Sound | |||
untitled | |||
* [ select all | |||
* [ Remove | |||
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 | |||
for i from 1 to nFiles | |||
mycode | |||
endfor | |||
if i < 20 and word$ = “STIM” | |||
do this | |||
elsif i = 20 and not word$ = “STIM” | |||
do that | |||
else | |||
do this | |||
endif | |||
'''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''' | |||
Create Strings as file list... list 'source_directory$'/'file_name_or_initial_substring$'*'file_extension$' | |||
head_words = selected("Strings") | |||
Drawing | |||
Erase all | |||
Draw inner box | |||
Erase all | |||
form presens a form | |||
: "OK" sets the mentioned variables | |||
: "Cancel" sets done | |||
: (doesn't ''define'' one, it does it right then) | |||
form Concatenate sound files | |||
comment Directory of input sound files | |||
text Sound_directory C:\temp\ | |||
sentence Sound_file_extension .wav | |||
comment Save the final file as | |||
text Save_as C:\temp\temp.wav | |||
endform | |||
Write to WAV file... 'save_as$' | |||
Add menu command... | |||
Add action command... | |||
Line 14: | Line 169: | ||
https://www.fon.hum.uva.nl/praat/manual/Scripting.html | https://www.fon.hum.uva.nl/praat/manual/Scripting.html | ||
--> | |||
==External scripting== | |||
<!-- | |||
There are various libraries that interact with praat's files, and make have python initiate praat running praat scripts | |||
For example, praatio allows: | |||
from praatio import textgrid | |||
tg = textgrid.openTextgrid(r"C:\Users\tim\Documents\transcript.TextGrid", False) | |||
# Textgrid, IntervalTier, and PointTier | |||
--> | --> |
Revision as of 11:49, 20 June 2024