30-04-2021



  1. Praat Scripts Download
  2. Praat Scripts For Speech Perception
  3. Praat Scripts Free

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 Praat script editor obviously is the first choice to handle Praat scripts but principally you can use any text editor you like for editing. You don't even need Praat to edit Praat scripts! Usually, that's a bad idea because you want to test your scripts frequently during development and of course you need Praat to run scripts.

This was written a long time ago and needs to be revised. Send me an email encouraging me to fix it.

We want to get good at dealing with strings. It can be a real pain at first, but getting comfortable with manipulating strings programmatically (regardless of programming language) is a very powerful skill set that will serve you for the rest of your life as a researcher.

How to run a script Scripts save Praat users time and effort by automating a sequence of operations. To run a Praat script, go to the Control menu in the Praat objects window and select New Praat script. Then pull up the code for the desired script by clicking on one of the links below. Praat script to export all possible data about audio. Create text file from textGrid using Praat or any other audio processing tool. How do I print data with commas separating each element in praat script. How can you find and replace text in a file using.

Scripts

String functions

Beyond simply combining strings, Praat has a bunch of really useful functions that we can use to parse and manipulate strings. You could use these, for example, to dynamically create file names, or to separate a complex string like '01-e-23.wav' into smaller parts.

Let's say I ran an experiment using some software like PsychoPy or E-Prime. It's generated a bunch of files, and I want to open up each sound file and do something to it in my script. My folder also contains a bunch of files that are not sound files I'm interested in, so I know there's going to be a part of my script that checks if the file ends in 'wav' before asking Praat to open it. Using Praat's built-in string functions I could, for example, get the right 3 characters in a file name and see if they are 'wav' by using the right$() function.

Here's the definition of the right$() function from the Praat manual:

Praat ScriptsScripts

Note that in Praat's new syntax, this could also be written as right$: a$, n

Let's get the right three characters of the string '01-e-23.wav', and save it to a variable called ext$:

Let's look at what this means and carefully understand what's happening. Remember that a 'function' in computer languages is basically a series of commands that will give you back a value: you 'call' it, possibly giving it 'arguments' (elements to act on), and it will 'return' a value. Here, the function is the right$: function. It has two arguments: the string to act on (fil$), and the number of characters we want (3). Hopefully you have noted this already, but its first argument is a string, and its second argument is a number. As stated in its definition in the manual, it returns a string, so when we save its return value, we must save it to a string variable with a trailing dollar sign. The following calls to right$() have mistakes in them. Run them and observe the error message, then find the errors and fix them.

I don't like how we hard-coded the number three into the call to right$(). What if we want to reuse this script and the files are .aiff files? That file extension has 4 letters, and we would have to run through our script and change all of the (right) threes. Let's 'once and done' it. We'll get the length of the extension by using the length() function:

There is an important difference between the length() function, and the one we used to get the rightmost letters. Can you spot it? right$() has a dollar sign after its name, and length() doesn't. That's because, you guessed it, right$ will return a string, and length will return a number. Check out how this is reflected in the variables we used to save the return value (ext$ and extLen). right$() returns a string, so we save it to a string variable (ext$). length() returns a number, so we saved it to a numeric variable (extLen).

Now go to the Praat manual and read the page on string functions. Check out what's available to you. Don't stress too much about things you don't understand (but get curious!). You can use these creatively to parse and analayze strings.

Practice

This one's a big task, but it covers pretty much all of the concepts we've been talking about, and is really practical. Your toils will bear good fruit. Recall our example before of wanting to manipulate a bunch of sound files. Going back to our example, we can imagine that our experimental software generated a bunch of names like '1-e-23.wav'. The first character represents a condition (condition 1), the 'e' represents a target vowel, and the '23' represents a participant number.

Using available string functions, make a script that will print a line to the info window saying 'This is participant 23's pronunciation of e in condition 1. It is a wav file'.

This gets the job done, but we should always be thinking ahead and trying to plan for potential errors in the future. We have to understand that this solution has several assumptions:

  • I'm hard-coding the number of characters to mess with in the left$ mid$ and right$ functions. This means I must not have more than 9 conditions, or everything will break. Comment out the line for fil$ by adding a hashtag in front of it, and add this line below it, then rerun the script and see what it prints out:
  • We run into a similar problem if we're using a label for a sound that has more than one character:

  • What if our files have names instead of participant numbers? Not everybody has the same length name. We should always be on the lookout for ways of future-proofing our code, and making it more generalizeable. Maybe in this case, it would be more flexible to treat the hyphens as separators, and allow for values of different lengths.

Now let's make a more flexible script to parse our file names. It still has assumptions, though: it assumes that the file name has two hyphens, and that it has a file extension. The improvement is that the components between these can be any length.

We've now made a script that can take apart a file name that has a file extension and has two hyphens. Comment out what we have for fil$, and add some more names, trying to break the script. Try '13A-shibboleth-Frankie.TextGrid', for example.

Of course there is plenty of room for improvement, but I hope this showed that we can get pretty creative with Praat's built-in string functions.

I also want to reiterate a couple of habits that I think you should get into. Before I went around looping through files, we tested this idea on its own, in an isolated test script. This simplifies our life.

Praat Scripts Download

We commented our thinking throughout the steps of the scripts. When we come back to this script after a good while, this will help us quickly remember what we were trying to do. Trust me, when you're dealing with a challenging problem and spent a lot of time working it through, you probably won't remember all of the logical leaps you took after a few weeks. This will save you a lot of time later and makes your script more understandable to others.

If you do ever get more into programming, the next step for dealing with strings is learning about regular expressions (regex). They're basically their own mini language that you can use to parse strings in very complex ways. The truth is they are a major pain in the ass if you're not using them regularly, because they are really hard for humans to read. But I don't know of a better alternative, and practically every good language lets you use them, including Praat. So if you get heavy into searching through text, go learn about regular expressions, but put on your patient cap before starting. Just be content that what you learn will transfer over to any programming language you will learn in the future. If you're into database work, you will need to get good at regexes.

Praat Scripts For Speech Perception

Next page: The End

Praat Scripts Free

  • Measure Pitch, Jitter, Shimmer, and HNR

    This script measures Pitch (Fundamental Frequency or F0), the standard deviation thereof, jitter, shimmer, and harmonics to noise ratio (HNR). The a...
    Recent Activity

    Loading logs...

  • Manipulate Pitch

    This is the script I use to manipulate pitch by +/- 0.5 ERB. I've used this method in all of my papers since I switched to ERB from Hz (you can edit ...
    Recent Activity

    Loading logs...

  • Parselmouth Praat Scripts in Python

    This script will measure pitch, standard deviation of pitch, hnr, jitter, shimmer, and formants in python using parselmouth, a a package that runs Pra...
    Recent Activity

    Loading logs...

  • Nomalize amplitude

    Normalizes amplitude of all files in a directory to 70dB using RMS
    Recent Activity

    Loading logs...

  • Select: All components*contains supplemental materials for a preprint

    Loading projects and components...

    0'>

    Type the following to continue: