This handout is a supplement to the third workshop in the 2019 Praat Scripting Workshop Series, offered at the University of Georgia DigiLab. It contains some extra information that just didn’t fit in the time we had available. It is currently under construction and will likely change many times in the future. For more information about the series and for links to the other handouts, visit joeystanley.com/praat.

1 Work with multiple files

So far, we’ve only been able to extract formants from one file. That’s certainly a lot of work being done automatically, but we can take it a step further and run this script on multiple files all at once. To do this we’ll basically put this whole thing into another for loop that will cycle through all the sound files in a directory. Adding loops within loops adds quite a bit of complexity to your script, so you’re more error prone and the script gets both longer and harder to read. But the benefit is that you can work with any number of files as easily as you can with just one.

1.1 Find all the files

The first step is to use code to locate all the files you want to extract formants from. For now, the simplest way to do this requires that the files be pretty systematic in their names. They should be like how I’ve named in them in the sample file: .wav and .TextGrid files should have the same name (e.g. “19-Kathleen”) and all the files you want to work with should be in the same folder on your computer. There are ways to have a different system than this (like having all files each in their own folder, with .wav and .TextGrid files with different names), but that’s project-dependent and out of the scope of this workshop. I’ll leave it up to you to figure out how to do that.

Anyway, what we’ll do is create a new variable, I like to call mine dir$ that contains the path to the directory where all these files live. Here’s what that might look like on my computer:

dir$ = "/Users/joeystanley/Desktop/Praat Workshop/sample_recordings/"

Now comes the key function. We’re going to let Praat look through and save the filename to each file in that directory. We can do that with Create Strings as file list:. That takes two arguments. First, is the name that we want to call that list. I’ll call it speakers. The other argument is the directory where these files live, which in our case is dir$.

dir$ = "/Users/joeystanley/Desktop/Praat Workshop/sample_recordings/"
Create Strings as file list: "speakers", dir$

If you run just those two lines, you should see a new Strings object called “speakers”: