how to open praat from a praatscript

随声附和 提交于 2020-01-03 02:56:13

问题


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


回答1:


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.




回答2:


For those who are struggling with sendpraat :

try:

sendpraat praat 'execute "pathtoyourscript"'


来源:https://stackoverflow.com/questions/44804843/how-to-open-praat-from-a-praatscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!