An aid to scripting.
The ScriptEditor is a text editor that allows you to edit, save, and run any Praat script. You can type such a script from scratch, but it is sometimes easier to use the History mechanism, which automatically records all your commands and mouse clicks, and which can paste these directly into a ScriptEditor.
To add a script as a button to a fixed or dynamic menu, use Add to fixed menu... or Add to dynamic menu... from the File menu.
In this example, we create a fixed button that will play a 0.4-second sine wave with a specified frequency.
First, we create a ScriptEditor by choosing New Praat script from the Praat menu. Then, we choose Clear history from the Edit menu in the ScriptEditor. We then perform some actions that will create a sine wave, play it, and remove it:
We then choose Paste history from the Edit menu in the ScriptEditor (or type Command-H). The text will now contain at least the following lines (delete any other lines):
Create Sound as pure tone: "tone", 1, 0, 0.4, 44100, 440, 0.2, 0.01, 0.01
We can run this script again by choosing Run from the Run menu (or typing Command-R). However, this always plays a sine with a frequency of 440 Hz, so we will add the variable "Frequency" to the script, which then looks like:
form Play a sine wave
Create Sound as pure tone: "tone", 1, 0, 0.4, 44100, frequency, 0.2, 0.01, 0.01
When we choose Run, the ScriptEditor will ask us to supply a value for the "Frequency" variable. We can now play 1-second sine waves with any frequency.
It is advisable to supply a standard value for each argument in your script. If the duration should be variable, too, the final script could look like:
form Play a sine wave
positive Frequency 440
positive Duration 1.0
Create Sound as pure tone: "tone", 1, 0, duration, 44100, frequency, 0.2, 0.01, 0.01
When you run this script, the ScriptEditor will ask you to supply values for the two variables, but the values "440" and "1.0" are already visible in the form window, so that you will get a sensible result if you just click OK.
If this script is useful to you, you may want to put a button for it in the New menu, in the Sound submenu:
In this example, we will create a shortcut for the usual complex pitch-analysis command.
First, we perform the required actions:
We then paste the history into the ScriptEditor, after which this will contain at least a line like (delete all the other lines):
To Pitch: 0.01, 150, 900
You can run this script only after selecting one or more Sound objects.
If this script is useful to you, you may want to put a button for it in the dynamic menu:
© ppgb, January 7, 2014