2

I would like to allow a praatscript to open the the praat object line. This would allow me to open praat and then automatically allow the script to load objects into the object window.

for example the script

run_something.praat 1.wav 1.TextGrid 0.1 0.2

could open praat and then open the editor to 0.1 and 0.2 in the audio file "1.wav" < this is easy for me to do

I just can't get praat open beforehand to insert what I need.

right now my script looks like this:

form Info
    text Sound
    text Textgrid
    real Start
    real End
endform


if sound$ != "" and textgrid$ != ""
     Read from file: sound$
     Read Strings from raw text file: textgrid$
     @read_lab()

selectObject: 1, 3
View & Edit
editor = 3
editor: editor
Select: start , end
Zoom to selection
endeditor

endif

of course it will tell me that View and Edit does not work because the GUI is not open. I cannot use environments because it has to work on windows and linux

badner
  • 768
  • 2
  • 10
  • 31
  • I don't think you can open Praat from within a script, but you can open it from the terminal before running the script. – Stefano Jun 28 '17 at 15:25
  • it still gives me the same error if I open praat in one terminal and runt the script in another – badner Jun 28 '17 at 15:51
  • Error: Command "View & Edit" not available for current selection. Script line 245 not performed or completed: « View & Edit » – badner Jun 28 '17 at 15:51

2 Answers2

3

You can start Praat using the --open option to ... open the files you want. This will start Praat in GUI mode, with the specified files (and/or scripts) open:

praat --open sound.wav annotation.TextGrid script.praat

But if you want to issue commands to that instance of Praat programmatically (= without you clicking on anything), you'll likely have to use sendpraat, which should be usable in all the platforms where Praat runs.

Note that the compilation instructions in that page are a bit outdated for Linux at least: I was able to compile on my machine with

gcc -std=gnu99 -o sendpraat -DSTAND_ALONE -DUNIX \
  `pkg-config --cflags gtk+-2.0 glib-2.0` \
  sendpraat.c \
  `pkg-config --libs   gtk+-2.0 glib-2.0`

With sendpraat available, you'll have to start a GUI instance of Praat however you prefer, and then, in a separate statement, send the execution of your script:

sendpraat 0 praat \
  'runScript: "path/to/your/script", "1.wav", "1.TextGrid", 0.1, 0.2'

Instructions for using sendpraat are available on the Praat manual. The first argument is a timeout in seconds (=die if action is not completed by then), then the name of the program, and then a list of commands to run sequentially.

As far as I know, there is no straightforward way to run a single script that will, in one step, open a GUI version of Praat and make that instance of Praat execute a command. But I might be wrong.

jja
  • 2,058
  • 14
  • 27
  • It gives me an error in the form. I am assuming that there must be a specific way to pass arguments with sendpraat, but I cannot find any documentation on this. – badner Jun 29 '17 at 14:06
  • Unknown variable: « selective_revision.praat Script line 1 not performed or completed: « selective_revision.praat » Script “/home/cshulby/.praat-dir/message” not completed. Praat: message not completely handled. – badner Jun 29 '17 at 14:06
  • I also tried this: sendpraat praat "runScript: \"plugin_htklabel/selective_revision.praat\"" "/home/cshulby/Desktop/rf_selecionadas/wav/rf_selecionadas0001.wav" "/home/cshulby/Desktop/rf_selecionadas/lab/rf_selecionadas0001.lab" "0.1" "0.2" – badner Jun 29 '17 at 14:41
  • This is more promising and gave me the error: Found 0 arguments but expected more. Script “/home/cshulby/.praat-dir/plugin_htklabel/selective_revision.praat” not completed. Formula not run. Script line 2 not performed or completed: « runScript: "plugin_htklabel/selective_revision.praat" » Script “/home/cshulby/.praat-dir/message” not completed. Praat: message not completely handled. – badner Jun 29 '17 at 14:41
  • @badner My answer has an example of how to pass arguments to a script called with `sendpraat`. Each string passed to `sendpraat` is a different command (= a different line in a script), so you need to have `runScript: "script.praat", "arg1", "etc"`. Also, don't forget about the timeout argument, which is missing in your last comment. – jja Jun 29 '17 at 14:46
  • perfect, the syntax with simple and double quotes plus commas was missing. worked like a charm. – badner Jun 29 '17 at 15:20
0

For those who are struggling with sendpraat :

try:

sendpraat praat 'execute "pathtoyourscript"'