How can I cut several sound files using a script?

377 Views Asked by At

I am new to Praat and wondering, if someone can help me to find out, how I can cut all my sound files with a script or anything. I have like 100 sound files I need for my research. They all have a different length, some are 1 min and others are 3 min long. I would like to have only the first 22 sec from each sound file.

Thanks in advance! Kind regards Olga

1

There are 1 best solutions below

2
user6726 On

The first step is to construct a script that extracts the initial 22 seconds of some specific sound object that is already open. In general, the easiest way to at least start a script is to do a thing manually once, and after you've done that, in a Praat script window, copy the command history (with ctrl-h) to see what the underlying commands are. The manual approach is to look for "Extract part" under "Convert", which corresponds to the command

Extract part: 0, 22, "rectangular", 1, "no"

There is also a command to save a file as a wav file, so you would add that to the core of the script.

Then you need to add a loop that does this a number of times, to different files. You will (probably) need a file with wav file names, and some system for naming the output files, for example if you have "input1.wav", you might want to call the cut-down version "output1.wav". This implies some computation of the output file name based on the input file name, so you need to get familiar with how string manipulation works in Praat.

If you have that much sorted out, then the basic logic is

get next input file name file
compute output name
open the input file
extract from that file
save the extracted file
remove the extract
remove the original
loop until no more files

I would plan on spending a lot of time trying to understand simple things like string variables, or object selection. I left out explicitly selecting objects since it is not necessarily required, but every command works on "the selected object" and it's easy to lose track of what is selected.

Another common approach is to beg a colleague to write it for you.