|
Sendpraat can be a subroutine for sending messages to a running Praat program.
sendpraat (void *display, const char *program, long timeOut, char *text);
display
program
timeOut
(MacOS and Linux only)
sendpraat
will wait for an answer before writing an error message. A timeOut
of 0 means that the message will be sent asynchronously, i.e., that sendpraat will return immediately without issuing any error message.text
char message [100], *errorMessage;
strcpy (message, "Quit");
errorMessage = sendpraat (NULL, "praat", 0, message);
if (errorMessage) fprintf (stderr, "%s", errorMessage);
This causes the program Praat to quit (gracefully), because Quit is a fixed command in one of the menus of that program. On MacOS and Linux, sendpraat returns immediately; on Windows, the timeOut argument is ignored. The return value errorMessage is a statically allocated string internal to sendpraat, and is overwritten by the next call to sendpraat.
Suppose you have a sound file whose name is in the variable fileName
, and you want the program Praat, which can play sounds, to play this sound backwards.
char message [1000], *errorMessage;
snprintf (message,1000, "Read from file: ~%s\nPlay reverse\nRemove", fileName);
errorMessage = sendpraat (NULL, "praat", 3000, message);
This will work because Play reverse is an action command that becomes available in the dynamic menu when a Sound is selected. On Linux, sendpraat will allow Praat at most 3000 seconds to perform this.
Sometimes, it may be unpractical to send a large script directly to sendpraat. Fortunately, the receiving program knows runScript:
char message [100], *errorMessage;
strcpy (message, "runScript: \"doAll.praat\", 20");
errorMessage = sendpraat (NULL, "praat", 0, message);
This causes the program Praat to run the script doAll.praat
with an argument of "20".
You can download the source code of the sendpraat subroutine via www.praat.org or from http://www.fon.hum.uva.nl/praat/sendpraat.html.
Instead of using sendpraat
, you can also just take the following simple steps in your program:
~/.praat-dir/message
;~/.praat-dir/pid
;kill -USR1 1178
If the first line of your script is the comment “# 999
”, where 999 stands for the process id of your program, Praat will send your program a SIGUSR2 signal back when it finishes handling the script. If you do not want to receive such a message (if your program has no handler for it, the SIGUSR2 signal will kill your program), then do not include such a line.
To start a program from the command line instead and sending it a message, you would not use sendpraat, but instead run the program with a script file as an argument. See Scripting 6.9. Calling from the command line.
© Paul Boersma 2002,2003,2005,2009,2014,2015,2021,2023