17 September 2011

Do you have a Praat script that can...

As I have mentioned before, Praat scripts can take care of many repetitive actions for you, saving you many mouse clicks. But be warned, a script cannot do anything that requires human judgment, such as labeling segments. I cannot stress this enough: you have to know exactly what the script is doing.

When I first started using Praat, I used many small scripts, each of which performed one small job. For instance, after a recording session, I would use one script to cut the large file of the entire recording session into smaller files, a separate script to extract measurements, another script to normalise the intensity of the sounds, and yet another script to ramp in and out, and so on. What I found was that the problem with such an approach is that it is very easy to lose track of what manipulations you have already done to a set of sound files — especially if you are working on multiple projects at the same time, with different normalisation scripts, etc. As a result, a few years ago, I changed the way that I used Praat scripts.

Now, for each project, I create one large Praat script that contains all manipulations: taking original measurements, manipulating intensity, pitch, ramping, etc., renaming files, and taking new measurements after all manipulations have been completed. This way, when the time comes to write up the Method section, all of the information is easily accessible and traceable.

Due to this new project-based scripting technique, I create a new script for each project that I am working on. However, I rarely code a script from scratch. Bits and pieces can be reused from other scripts, and in this way new scripts can be generated very quickly. Below, I have listed all of the Praat scripts that I have in my possession. I receive frequent requests along the lines of, "Do you have a script that does x?"

Every Praat script that I have is listed below, along with a brief description. I have omitted some scripts that are very similar to those posted here, or some of the larger scripts that have been tailored to a particular set of stimuli. Each script may be downloaded by clicking on the name. Please feel free to download, modify, and redistribute the scripts without restriction. What's mine is yours:

text grid maker.praat My first ever Praat script. Very useful for creating textgrids once a recording has been completed. Saves you many mouseclicks and RSI.

text grid reviewer.praat Once you (or a research assistant) have created textgrids, it can be useful to open each sound file and its corresponding textgrid to review the boudnaries and annotations that have been created. This script makes the reviewing process easy. It allows you to make edits and saves the changes before moving to the next textgrid.

duration logger.praat Useful for measuring the length of intervals marked in a textgrid. Bits of this script show up in all of my larger scripts that have the word "measure" in their filename.

wav aif converter.praat A simple, but very useful script for those who wish to share soundfiles between Macs and PCs. Wav files can be easily converted to aiff and vice versa without altering the file's quality.

get measurements.praat Similar to duration logger.praat except that this script outputs a range of measurements: formants, f0, amplitude at 25, 50 and 75% of each vowel.

load all sound files.praat A very simple, but very useful script. It loads all soundfiles in a directory into Praat. Praat annoyingly does not function like most Windows/OSX apps. You cannot drag and drop a file into Praat. Opening many files is a bit of a chore. Newer versions of Praat at least let you open multiple files at once. This script makes things even easier. I always include a version of this script when asking others to listen to a bunch of sound files for me. It just makes life easier. highly recommended.

token selection.praat Very similar to load all sound files.praat above. Option may be enabled for soundfiles to being playing when script is run.

sound chainer.praat Combines all files in a directory into a single file, adding 1 second of silence between each sound.

on off ramp.praat Quick and easy way to ramp many files that have already been cut.

chop from point.praat Reads in all sounds and textgrids in a directory, identifies which parts of the original sound have been labelled, extracts the labelled sound, ramps the beginning and end of the sound, outputs newly cut sounds, and preserves textgrids.

ramp, chop - preserve textgrids.praat One of my first 'larger' scripts. As the name implies, it excises individual tokens from a larger file, ramps the onset and offset to zero dB, and preserves the textgrid information for the excised segment.

norm, ramp, chop - preserve textgrids.praat Similar to the script above, except that it normalises each token as well as ramp in and out.

chop, measure, preserve textgrids.praat No ramping or scaling in this version of the script.

chop, measure, scale intensity, fix duration.praat Similar to other scripts listed here except that all tokens are fixed to a set duration by calculating and adding x amount of silence to the end of each sound. Useful for experiments that require regular presentation of simuli, such as one sound each second, as might occur in fMRI.

scale intensity (energy) with output.praat Reads in soundfiles, takes intensity measurements, scales each file to a specified dB value, takes new intensity measurements. An error message is displayed if any sounds clip due to scaling.

scale peak steps.praat Outputs a variety of acoustic measurements. Calculates the difference between the intensity of the vowel and a prespecified intensity (dB_target). Scales the entire soundfile so that the vowel's intensity will now equal dB_target. Outputs a new set of acoustic measurements, this time for the scaled stimuli.

pitch fixer.praat Sets the pitch of each token to a predetermined (flat) value.

sound mixer, step maker.praat Generates a continuum of x steps between two soundfiles that serve as  endpoints. The continuum is created by mixing the two sounds together.

create Klatt sound.praat Synthesises the syllable /da/ using Klatt synthesis.

Michael_Klatt_cont_plusplot_2d.praat This impressive script was developed by one of my previous supervisors, Michael Tyler. The script takes as its input two vowels defined in F1/F2 space. One is an anchor and the other a starting point. The script will generate a continuum of vowels at a given distance apart (in erbs) at a fixed radius from the anchor vowel. The user can choose this to be the distance between the anchor vowel and the starting point or the user provides a radius in erbs.  The user specifies whether the direction is anticlockwise or clockwise. Most people won't find much use for this, but it is very advanced stuff.

I will continue adding to the list as I develop new scripts, or come across scripts that I consider to be useful.

16 comments:

Juan Carlos Oscar Hedman said...

Thanks Mark for sharing the Praat scripts!!!
I´m investigating about products humidity measurement, and using Praat.

Ricard said...

I've seen you control Praat script language. Congratulations. I need to create words by synthesis as [káko], [kíku], but I have enough knowledge to create ... so I'm looking for a script that enables setting changes in vowel formants as needed. You know a script that allows to do this? Thank you very much for your attention

Mark Antoniou said...

I'm not sure what sort of synthesis you are planning on using. If you plan to use LPC within Praat, you could use a mathematical formula to generate equally-spaced formant steps between tokens. I haven't done this in my own work because I have not been satisfied with the quality of LPC stimuli.

Another program worth checking out if you have Matlab and the Signal Processing Toolbox is Straight (http://www.wakayama-u.ac.jp/~kawahara/STRAIGHTadv/index_e.html). Good luck.

Sylvie said...

Hi Mark,

Thank you so much for sharing the praat scripts. I'm looking for a script for my research. Do you have a script that I can use for the following purpose? I marked several points using point tier and want to measure F0 value of those points.

Thanks in advance!

Sylvie

Mark Antoniou said...

Hi Sylvie,
I have not got a script that looks at that. But that doesn't mean that you can't modify one of my existing scripts to do that for you. For instance, you could keep the code that reads in the files and creates a text file in which the measurements will be kept etc.

Try doing a measurement by hand in Praat. Then click Praat and New Praat script. In the Praat script window click Edit and then Paste History and Praat will paste the code necessary for performing those steps. Then it it just a matter of integrating that into the script.

Good luck!

Phạm Hiển said...
This comment has been removed by the author.
Phạm Hiển said...

Hi Mark,

You are guru of praat scipting. I have hundreds of wav files recorded isolate words. Each file records a word. Do you have a Praat script for doing following jobs: measure word durations, measure the length intervals preceding the words then save them as a table, and chop just the words and save them as wave files.

Thanks in advance!

Duc

Mark Antoniou said...

Thanks Duc. The script chop, measure, preserve textgrids.praat does just about everything that you want. You will need to modify it to get the preceding (and/or following) intervals. Other than that it should work fine. You also may need to modify which tier of your textgrids the script looks on to find word boundaries.

Iin said...

Thanks Mark for sharing many scripts.
I have a problem with editing the sound..try to add/delete duration..but the text grid does not automatically change..so i should manually add/delete text..and it is not that easy..
could you suggest which script that suitable for kind of need?

Mark Antoniou said...

I don't have a script that does exactly what you want, Lin. If you have a sound file and add 50 ms duration,, all you would need to do is get the duration of the sound and add the new value (i.e., 50 ms). You could do this with something like

soundDuration = soundDuration + 0.05

Iin said...

thanks for your suggestion..i need to add/delete duration in several segments in different interval..i did delete one interval..but the rest of interval would be change also.

Mark Antoniou said...

You could create a more complicated version of what I have recommended above, by subtracting the duration that you have deleted to each boundary, although this will get messy very quickly. Good luck

seeker said...

Hi Mark,

I have four sound categories and wanting to compare the mean pitch for across categories. I have more than 40 sounds in each category. I am trying to create a script that can extract the mean pitch and mean HNR for each of the sounds.

I am using the following script to extract the mean pitch of sounds. All files with prefix Sound gets loaded into the list of objects. However, the script fails at editor fileName$'command saying Editor "Sound woscreamCT.wav does not exist where woscreamCT.wav is the last file in the directory.

Where could the script be going wrong? Also what does 0 and 5 mean in the Select command (duration of the sound file in msec?)

Thank you.

Sincerely,
Shanker

directory$ = "/Thesis/.../Sounds/Final"
Create Strings as file list... list 'directory$'/*.wav
numberOfFiles = Get number of strings
for ifile to numberOfFiles
select Strings list
fileName$ = Get string... ifile
Read from file... 'directory$'/'fileName$'
endfor
Edit
editor 'fileName$'
Select... 0 5
Zoom to selection
f0 = Get pitch
fileappend 'end_directory$'test.txt 'f0''tab$'
endeditor
endfor
select all
Remove

Mark Antoniou said...

Where could the script be going wrong?

The problem is that you are looking for the Praat Sound object called woscreamCT.wav, but Praat removes the .wav extension when it loads files into the Objects window.

To fix this, delete
fileName$ = Get string... ifile

Then, under Read from file... 'directory$'/'fileName$'
insert this
objName$ = selected$ ("Sound")

So now, when you want to manipulate the sound object, you refer to objName$ not fileName$.

Also, change editor 'fileName$' to
editor Sound 'objName$'

Also what does 0 and 5 mean in the Select command (duration of the sound file in msec?)

The Select... command (note that the 3 periods after Select are important) selects a portion of the sound file in the Editor window. The first value is the beginning of the selection, the second value is the end of the selection, and both are measured in seconds. Typically, individual stimulus tokens are less than 5 seconds in duration, so the Select... 0 5 command in your script is essentially acting as a "Select All".

Unknown said...

Hi Mark, a bunch of thanks for sharing scripts. They are really useful indeed! However, I've tried many scripts, and they don't work. Don't know why. Maybe I misunderstand something.

rashmi verma said...

do you have any praat script for modifying pitch,intensity...