您的位置:首页 > 编程语言 > Python开发

使用Perl或者Python加载Praat脚本在DOS命令窗口直接执行

2014-07-24 14:56 1046 查看
通常一个完整的项目过程中,使用了多个Praat脚本,这时候如果频繁通过打开Praat,再打开脚本去执行,非常麻烦,如果这样的过程过于重复,可以考虑通过使用Perl或者Python写一个流程,把脚本都放到这个流程里,执行,不需要去打开Praat。Praat提供了这样的方便,它有一个Command窗口执行的文件,叫praatcon.exe,这个文件也可以在官方网站下载到。

下载地址:

5. The console Praat (for experienced Praat script writers only!)

There is also a special program called Praatcon, which you run from a console window (the "command prompt"). Download the following zip folder:

64-bit edition: praatcon5381_win64.zip (3 July 2014; 5.7 MB)
32-bit edition: praatcon5381_win32.zip (3 July 2014; 5.4 MB)

This zip folder contains Praatcon(.exe), which is the Praat console application. You should not double-click it. To run it, write a Praat script and specify that script on the command line, optionally with arguments, e.g.:

praatcon playsinewave.praat 377 0.9




可以根据自己的计算机操作系统位数选择相应的下载包。



下载了之后放在计算机的某个位置,比如放在E:\praatcon.exe



在这里给出一个测试脚本,脚本的目的是获取某个文件夹内某种文件的文件名列表,请注意如果这样的脚本是针对不同目录进行操作的,需要在脚本里使用form对话框给出参数,从而这样的参数也可以在调用这个脚本的时候给出。

form test
	sentence openPath E:\TranWav\
	sentence savePath E:\dir.txt
	sentence extName .wav
endform

Create Strings as file list: "fileList", openPath$+extName$
fileNum=Get number of strings
for ifile from 1 to fileNum
	selectObject: "Strings fileList"
	fileName$=Get string: ifile
	appendFileLine: savePath$, fileName$
endfor

脚本需要三个参数,第一个是原来的文件所在的目录,第二个参数是产生的列表所在的路径,第三个参数是指过滤什么类型的文件。

使用Perl调用这个脚本的方法是:

$commandline=sprintf("E:\\praatcon.exe E:\\GetFileNames.Praat E:\\wav\\ E:\\dir.txt .wav");
system($commandline);

第一个是Praatcon.exe所在的路径,第二个是脚本所在的路径,第三个是脚本里的第一个参数,后面两个同理。



而使用Python也同样:

import os
os.system('E:\\praatcon.exe E:\\GetFileNames.Praat E:\\wav\\ E:\\dir.txt .wav')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐