Less unix, more linguistic and phonetics: a script to automate praat

Praat (the home page at http://www.praat.org/ and http://www.fon.hum.uva.nl/praat/):

I needed a simple script to quickly change the input data for the command line execution. The interesting part is at the end. It is an initial script to handle big data.

So this is a first attempt (lets call the script: run_praat.sh):

#!/bin/sh
#
# We need a script to run: first parameter is compulsory
if [ -z $1 ];
then
echo "# please give a script";
exit;
fi
#
# We make sure we have the .praat at end
scrt=`basename $1 .praat`
echo "# Given, Script: $scrt"
screxe=${scrt}.praat
#
# Do we have an input?
if [ -z $2 ];
then
scrinput=${scrt}.input
echo "# Got input from command line ${scrinput}";
else
scrinput=${2}
scrinput=`basename ${scrinput} .praat`
scrinput=${scrinput}.input
fi

echo "# Searching for script: ${screxe}"
echo "# Getting input from: ${scrinput}"
#
if [ ! -f $screxe ];
then
echo "Script not found! Name: ${screxe}"
echo "Please give a valid praat script."
exit 1;
fi
#
if [ ! -f $scrinput ];
then
echo "Input not found! Name: ${scrinput}"
echo "Please give a valid input file for ${screxe}. It should be named: ${scrinput}"
exit 1;
fi
#
echo "Using this input:"
cat ${scrinput} | awk -F ":" '{print $1, "\t","=", $2;}'
cmdlinepars=`cat ${scrinput} | awk -F ":" '{printf("%s ",$2);}'`
echo "Executing with there params ${cmdlinepars}"
echo ${cmdlinepars} | xargs praat ${screxe} ${cmslinepars}
#

Now the input file looks like this:

workdir:/home/mariotti/data/
logfile:createdataplot.log
vlogfile:"create a full log file"
remfile:"Remove Files"
doplot:"Just produce data files"
runon:"Run on sound files (and TextGrid) on a directory"
numtier:"1"
run_dir:/home/mariotti/data/
terms:all
Regex:0
Maximum_formant_female_male:5500
data_format:"gnuplot"
segment_margin:1.0

This input is required for this script (I only give the head):

 

########################################################################
# Intro form
########################################################################
form Produce data files for plotting and Analysis
comment Files work directory (All files created here)
text workdir /home/mariotti/data/
sentence logfile createdataplot.log
optionmenu vlogfile 2
option log only activity
option create a full log file
optionmenu remfile 1
option Remove Files
option Append to files
optionmenu doplot 1
option Just produce data files
option Do draw tracks
optionmenu runon 1
option Run on Selected
option Run on sound files (and TextGrid) on a directory
option Run on sound files (and TextGrid) on a directory and subdirs
optionmenu numtier 1
option 1
option 2
option 3
option 4

comment Direcory to search for Sound files (if required)
text run_dir /home/mariotti/data/
comment Term in the name of the segment to analyse or "all" for all
sentence terms all
boolean Regex 0
## Use this default for generic vowels match
## sentence terms "^'?(a|e|i|o|u|A|E|I|O|U):?"
## boolean Regex 0
comment Formant data (F:5500/M:5000)
positive Maximum_formant_female_male 5500
comment Output format
optionmenu data_format 1
option gnuplot
option raw text
comment advanced options (Use 1.0 now)
real segment_margin 1.0
endform
#

So…

What is going on: Now I can do this:

./run_praat.sh <myScript.praat> [<myALTinput.input>]

I did this because I needed to run the script multiple times with different inputs, like changing the tier and/or the MaxFormant.

Please note that the input is strictly “positional”/”sequence based” and it will ignore anything before the “:”. That is used only as a placeholder.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.