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.

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.

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.

30 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.

Unknown said...

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

Unknown said...

Hello Mark,

Thank you for posting these scripts! I've found some of them very helpful. One I've been using is the sound mixer, step maker. It normally works really well, but I run into an issue sometimes where it's noticeable that there are two files mixed together even after I've controlled for consonant and vowel durations. It usually happens when I try to mix something like 'bake' with 'back' or 'bock'. Have you ever come across this? Or do you have any ideas on how to address this?

Thank you in advance for any insight you can provide,

David

Mark Antoniou said...

David, I have had great success mixing fricatives (e.g., /s/-/f/), but haven't really used this particular script for creating vowel continua. If I had to guess, I would say that the issue that you are experiencing is that of trying to mix a diphthong with a monophthong. One thing to try would be to normalise the intensity of the vowels first so that they are of equal intensity, and thus contribute equally at the continuum midpoint (50%) step, but I suspect that there will still be some weirdness due to the differences in vowel quality and formant transitions in the diphthong.

Failing that, you may wish to try using Straight, a Matlab-based tool that morphs one stimulus into another in a series of discreet steps http://www.wakayama-u.ac.jp/~kawahara/STRAIGHTadv/index_e.html. It's hard to say exactly what it does, for example, to describe it in a Method section of a manuscript. From what I understand, it decomposes a sound file into a series of objects (pitch, voicing, duration, etc.) and then manipulates these objects to resynthesise a series of sound files varying between two points. The reason why I do not use it for my purposes is because it is not clear exactly what it is doing, and it is not symmetrical. For example, if you were to create a 11-step bake-back continuum and then reversed the endpoints and created a 11-step back-bake continuum, the two continua would not be the same 11 steps but in reverse order. The stimulus tokens would actually be (sometimes very) different and the 50% midpoints would not be identical either.

Unknown said...

Thank you! This was very helpful.

Sarah said...

Hi, Mark. I'm using your "get measurements" script for my acoustic phonetics course. The whole class has been having a strange problem where the script runs, but on some of our computers there is no output anywhere that we can find. Some of us get the resulting measurements.txt file but for others it doesn't show up in any folder on the computer. We're all using the same script and not getting errors. Any idea what could be going wrong? It doesn't seem to be a OSX v. Windows problem, because it didn't work on one Windows laptop but did work on another.

Mark Antoniou said...

It's hard to say what problem some of you are experiencing, Sarah, particularly since it works for some but not others. It probably has something to do with the directory not being specified correctly.

On Windows, it is a good idea to use a directory with a simple path such as C:/Praat/ so that there aren't any spaces in the folder names.

Another tip is to make sure that you include the final slash, in the above example, after Praat.

Praat recognises blank spaces as characters, so go through each line of code in the script and make sure that you don't have any spaces (or tabs) at the end of each line of code.

Finally, make sure that the filetype matches your sound files, e.g., wav vs. aiff.

astraea said...

Hi Mark I need your help.
would u please share ur email id?

Unknown said...

Thank you for your sharing your scripts.

As you know, we can easily create a file list using "Create Strings as file list",but can you tell me how to create a directory list because I want to handle many sound and textgrid files in many different folders using one Praat script.

Mark Antoniou said...

LIU Lei, I don't work like that, so I can't give you a tried and tested solution. One solution might be to use a 'working' directory where you dump all your files and output them to other directories. Another solution would be to specify multiple input directories, although this can get messy.

brak czegoś said...

Hello Mark!

Can you please advise if it is available to compare two spectrograms with the use of PRAAT and how to do it? I have a 'model' recording and the recordings of students and I would like to compare them with the use of PRAAT, however...I don't know why. Can you please give me a piece of advice how to start and where I should look to find the answer?

Mark Antoniou said...

Hi brak czegoś,

I guess that depends on what exactly you mean by compare. With Praat, you may make various acoustic measurements and compare the values at various timepoints or within a specified window. Praat will not allow you to create a new spectrogram that shows the differences between the model spectrogram and the student's spectrogram. For that you would need to use a more sophisticated signal processing software package such as Matlab or Sigview etc. This discussion might prove useful https://www.researchgate.net/post/How_can_I_compare_the_frequency_spectra_of_two_different_audio_signals

Gazz said...

Hi Mark

How do I do this on PRAAT

1) synthesize vowels (/i, u/) with custom fundamental and formant values?


2) what method do I use to include a cosine squared 10msec ramp

3) how can I low pass filter the stimuli using PRAAT

Highly appreciate if you could help me with this

Mark Antoniou said...

Here you go, Gazz.

1. I haven't done this. Take a look at this http://www.fon.hum.uva.nl/rob/VocalTractExamples/

2. I have scripts on this blog that ramp in and out. Just modify those.

3. Objects → Filter → Filter (Pass Hann Band)

Unknown said...

Hi Mark!
How can I cite you if I am using your scripts in my work?
Thanks!
Kris

Mark Antoniou said...

No need to cite, Kris. I guess you could put a few words in the Acknowledgements. No pressure from me though. Glad that you found the scripts useful. Reach out if you need anything. Kind regards, Mark