Introduction
Welcome! Click on the menu in the top right to see the topics covered in this tutorial. Click here to read the complete introduction.
Pausing the script ( manual ).pauseScript: 'Message to user'. beginPause/endPause is another pair of keywords in Praat that allows you to prompt the user for input at any time in your script. You might expect this would work exactly like form/endform (and use the same syntax), but it mostly does not!
- This is an introduction to how to use Praat scripts. In particular, it shows how to use the grid-maker praat script, which allows you to create and edit Text.
- For those who want to use scripts in PRAAT to automate certain procedures, the ‘Scripting tutorial’ is highly recommended. More information about the use of formulas, operators, functions etc. Can be found in the ‘Formulas tutorial’. Check the ‘Frequently.
Other languages
Português: Se achar que muitas pessoas leriam este site se fosse em português, me avise, e talvez o traduza. Se tiver qualquer dúvida em português, fala aí!
Español: Si crees que mucha gente leería este tutorial si fuera en español, avísame, y tal vez lo traduzco. Si tienes alguna duda, puedes escribirme en español.
If you speak Catalan, French or Italian and have a question, feel free to write me in your language. Chinese would take some work, but is a possibility :)
Update your version of Praat
Let's get some basics out of the way. First, install Praat! If you haven't updated Praat in a while (as in, in the last year), download the latest stable version. The Praat developers are constantly addressing bugs, and they've also made some big improvements to their scripting language. If you're using an out of date version of Praat, parts of this tutorial might not work.
Praat Windows
Open Praat. Unless you've tinkered with it, Praat should open the 'Object Window' and the 'Picture Window'. Click on the object window to bring it into focus. Note the available dropdown menus on top bar (Praat, New, Open, Save, Help). Click on the Picture window, and note that the available dropdown menus on the top bar are now different. When it's three in the morning and you're tired and find yourself screaming 'Where the f*#$ is the open Praat script command?!?!', click on a different window, try again, and when you find it scream 'Winnebago!' It'll be our little inside joke.
Now we're going to open a Scripting window. With the Object window focused, in the 'Praat' top bar dropdown menu click 'New Praat Script'. The window that opens is the scripting window. It's essentially a very simple text editor. Click on all of the top bar dropdown menus, and say 'Hmmph' when you see something and you don't know what it is. The next time you're sitting with your phone in front of you and you're about to kill time on social media, try to look up what those things are instead. To be a successful programmer you will need to feed your curiosity and hone your Google-Fu. Your curiosity will lead you to new ways of tackling problems that you wouldn't have thought up on your own.
So back to the scripting window. Type this command (type, don't copy paste!):
Run this by going to Run > Run, or better yet, by clicking Ctrl + R on Windows or Linux, or ⌘ + R on Mac.
Praat Textgrid
If you typed everything correctly, the Info window should have popped up and tried to scare you. You have just written your first Praat script! If you mistyped something, you would have gotten some type of error message. This is totally normal. You will constantly generate errors, but when you practice typing things in (that's why you don't copy and paste), you will gradually get better at paying attention to every little detail and typing carefully, like in this case the colon, and the enclosing quotes around the word 'Boo!'. All of these little details (can) matter when you program, and paying great attention to detail will serve you well.
So back to the Info window. This is going to be your primary mode of interacting with Praat scripts. When your script is doing something you don't like, you can start 'printing' the values of things to the Info window and see where you're going wrong. Let's add another line to our script, and run it again. We'll talk more about what is happening with the equal sign and everything, so for now just type it in exactly and run it.
Check out the info window again. Now it should say this:
There are a couple of things to note here. Firstly, unless there's an error, the info window only prints information we tell it to (it only printed after the appendInfoLine command. The line 'favoriteNumber = 8' didn't print anything). Secondly, the info window now says Boo! twice. This is because the command 'appendInfoLine' appends things to the info window: it adds a line to whatever is already there (the first Boo! Hp deskjet 460 driver download for macbeattree. is from the first time we ran the script). You could clear it by selecting File > Clear. When you start making longer scripts and runnning them, this can actually get kind of annoying and the window will start to fill up with old messages. Add 'clearinfo' to the top of the script, and run it again:
Now every time we run this script the info window will be cleared first. I put it at the top of nearly all of my scripts, personally.
There is another detail in the way I typed the script above. Hopefully, your burgeoning programmatic curiosity has led you to note that there is a blank line between the first and second line of code (which is now on the third line of the script), and yet the code ran without issues. Praat's language allows for blank lines, and we should use them to separate our code into logical blocks, so that we can more easily read it. This is a short example so it doesn't seem like a big deal, but once you get longer scripts this will become important, and we should develop good habits now. I would format this script like this:
Note that whitespace before a line (spaces or tabs) is also allowed, and we'll talk later about when to use it to make your code more human-readable.
There's one last thing that we should talk about before moving on. Put a hashtag in front of line 5 as below, and run it.
Whoops! That generated an error. Praat is complaining that there is no variable named 'favoriteNumber'. That's because the hashtag is Praat's 'comment' character. Any line that begins with it will be ignored by the program. You might be thinking that's really stupid, but it's not. We can use the comments to write little messages to our future selves. We should tell ourselves what we're trying to do so that we can quickly understand a script in the future, and we can also quickly comment out 'appendInfoLine' commands that are cluttering up our info window in long scripts. Below is a better example of using the comment character.
When you make longer scripts, you can include more helpful messages, like '#This script expects a wav file and a TextGrid with the same name. It reads the first tier of the TextGrid, which needs to be an interval tier.' The text grid of interest should have an interval tier'. Or you can outline your thinking for a complex problem.
Save the script by going to File > Save. I recommend saving your praat scripts with the extension '.praat'. I'll tell you why later. But it's really just a text file, so 'txt', or even no extension at all, will work. I recommend creating a folder where you will store all of your Praat scripts, so you can get a little library going. In the future, you could open this script and run it by going to Praat > Open Praat Script.
Summary
This may have seemed a very simple lesson to some and hopefully you're not already bored, but we actually learned some very important things. We learned about the different Praat windows, how to open and save a script, we learned how to print messages to the Info Window, we learned a little about formatting and also about the comment character. I recommend completing the following exercises, which are short and sweet.
Exercises
1. appendInfoLine is not the only command available. Go to Praat's manual and find other commands for writing to the info window, and understand the difference between them. (Go to Help > Scripting Tutorial, and search for Info Window. In my version it's in the Scripting tutorial 6.2.). The Praat manual should become your primary resource for learning about Praat scripting.
2. Make a script where Praat tells you it loves you. Save it and keep it for hard times.
Praat Scripts Pdf
Next page: Text editor
Praat Tutorial
In addition, here are some Praat scripts that I've written or modified:
Concatenate sound triads from table
This script concatenates groups of three sound files with pauses according to rows of file names in a tab-separated text file. Each sound triad should have the three sound file names (minus .wav) specified in order in the first three columns, with the name given to the concatenated sound file in the fourth column. Make sure to include a header for each column, since Praat reads in the first row of a table as the header. Pause duration is specified in seconds by the user. This is useful for creating stimuli for ABX or oddity experiments, particularly for jsPsych.
Concatenate sound pairs from table
This script concatenates pairs of sound files with a pause between according to rows of file names in a tab-separated text file. Each sound pair should have the two sound file names (minus .wav) specified in order in the first two columns, with the name given to the concatenated sound file in the third column. Make sure to include a header for each column, since Praat reads in the first row of a table as the header. Pause duration is specified in seconds by the user. This is useful for creating stimuli for AX experiments, particularly for jsPsych.
Make pairs of identical sounds with pause
This script reads in all files in a folder and concatenates each one with itself with a pause in between. An optional prefix for concatenated files and the pause duration in seconds are specified by the user. This can be helpful if you want all of your stimuli to be played twice during a trial. For example, we have used this script to create stimuli for an auditory word familiarity task.
Move left boundary of labeled intervals to the left and zero cross final boundaries
This script moves the left boundary of labeled intervals to the left (earlier in the sound file) by a specified duration in milliseconds and moves the final left and right boundaries to the closest zero crossings. This is useful in creating a precise duration before the beginning of a sound when cutting stimuli.
Move left boundary of labeled intervals to the right and zero cross final boundaries
This script moves the left boundary of labeled intervals to the right (later in the sound file) by a specified duration in milliseconds and moves the final left and right boundaries to the closest zero crossings. This is helpful when, like me, you use the script that moves the left boundaries to the left and then realize you forgot to label certain stimuli, so you want to undo it.
Add silence to the beginning of all sound files in a folder
This script adds a specified amount of silence to the beginning of every sound file in a folder. The resulting sound files are saved with their original names to a folder specified by the user.
Add silence to the end of all sound files in a folder
This script adds a specified amount of silence to the end of every sound file in a folder. The resulting sound files are saved with their original names to a folder specified by the user. We have used this script to add silence to stimuli we were presenting in Qualtrics, since this software sometimes clips the end of sound files.
Get F1 to F4 at 7 times points for all labeled intervals
This script extracts measurements for F1, F2, F3, and F4 at 7 equidistant times points (25%, 37.5%, 50%, 62.5%, 75%, 87.5%, and 100%) in all labeled intervals. It processes all labeled intervals for all sound files in a folder, and outputs a text file. Each sound file and its corresponding TextGrid should have the same name.
Save labeled intervals to WAV files
This script saves each interval in the selected interval tier of a TextGrid to a separate WAV sound file. The source sound must be opened as a LongSound object, and both the TextGrid and the LongSound must have identical names and they have to be selected in the Objects window before running the script. The original script is by Mietta Lennes and I have modified it only slightly so that it automatically ignores all empty intervals, intervals with a space, or intervals with a line break, because I was always having to find and delete extraneous spaces or line breaks in otherwise empty labels before the script would run all the way through.
Save labeled intervals to WAV files for all files in a folder
This script saves all labeled intervals as individual WAV sound files for a specified TextGrid tier for all files in a given folder. Like the previous script, this one also automatically ignores all empty intervals, intervals with a space, or intervals with a line break.