如何将 Praat 脚本应用于音频文件?

How to apply Praat script to an audio file?

我正在尝试改变 formants of the audio file with praat in Colab. I found the script that does that, it's code and the code for calculating formants。我安装了 praat:

!sudo apt-get update -y -qqq --fix-missing && apt-get install -y -qqq praat > /dev/null
!wget -qqq http://www.praatvocaltoolkit.com/downloads/plugin_VocalToolkit.zip
!unzip -qqq /content/plugin_VocalToolkit.zip > /dev/null

with open('/content/script.praat', 'w') as f:
  f.write(r"""writeInfoLine: preferencesDirectory$""")

!praat /content/script.praat
/root/.praat-dir

!mv /content/plugin_VocalToolkit/* /root/.praat-dir

!praat --version
Praat 6.0.37 (February 3 2018)

如何在不使用 UI、使用 linux 命令行或 python 的情况下将此脚本应用于多个 wav 文件?

一般答案

你不知道。你 运行 一个脚本,这完全取决于脚本如何工作,它在什么对象上工作,这些对象是在哪里获取的,它们是如何获取的,等等。

因此,您始终需要研究如何应用 特定的 脚本,这总是需要弄清楚该脚本需要其输入的方式,以及如何达到这一点。

具体答案

你想要的脚本页面显示

This command [does something on] each selected Sound

所以第一件事就是打开你想要的文件并select它们。

让我们假设您将使用足够少的声音来一次性打开它们。如果您正在处理大量声音文件,或者文件太大而无法保存在内存中,则必须将作业分批处理成更小的块。

一种方法是使用包装脚本打开您的文件,select编辑它们,然后执行您想要的其他脚本:

# Get a list of all your files
files = Create Strings as file list: "list", "/some/path/*.wav"
total_files = Get number of strings

# Open each of them
for i to total_files
    selectObject: files
    filename$ = Get string: i
    sounds[i] = Read from file: "/some/path/" + filename$    
endfor

# Clear the selection
nocheck selectObject(undefined)

# Add each sound to your selection
for i to total_files
    plusObject: sounds[i]
endfor

# Run your script
runScript: path_to_script$, ...
# where the ... is the list of arguments your script expects

# In your specific case, it would be something like
runScript: preferencesDirectory$ + "/plugin_VocalToolkit/changeformants.praat",
    ... 500, 1500, 2500, 0,     0,    5500, "yes", "yes"
#      ,-´  ,-´  ,--´ ,--´    ,-´       ^     ^      ^
# New F1,  F2,  F3,  F4, and F5 means   |     |      |
#                               Max formant   |      |
#                       Process only voiced parts    |
#                             Retrieve intensity contour

# Do something with whatever the script gives you

我的 Praat 很生疏,但这至少应该让你知道该怎么做(免责声明:我没有 运行 以上任何一项,但概念应该没问题)。

将 "wrapper" 脚本存储在某处,然后您可以从命令行执行它:

$ praat /path/to/wrapper.praat