Praat 脚本:创建文本文件 [英] Praat scripting: creating a text file

查看:88
本文介绍了Praat 脚本:创建文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在与 Praat 合作,我正在尝试编写一个脚本来使用 3 个声音(叙述)文件的集合执行以下操作.我已经做到了 c),脚本部分相对容易.我不明白的是如何将它写入包含这些列的文本文件.任何帮助都会很棒!

just working with Praat at the moment, and I'm trying to write a script to do the following with a collection of 3 Sound (narrative) files. I've managed as far as c), the scripting part is relatively easy. What I don't get is how to write it to a text file with those columns. Any help would be great!

a) 创建一个程序,提取每个 Narratives 1-3 的音素层上的所有间隔,这些间隔代表元音,其标签是单个字母,并保持时间.我需要每个产生的声音都有一个适当的标签来识别相关的元音

a) create a program that extracts all intervals on the phone tier of each of Narratives 1–3 which represent vowels whose label is a single letter, keeping times. I need each resulting Sound to have an appropriate label which identifies the vowel concerned

b) 创建对应于每个间隔的共振峰 (burg) 对象

b) creates a Formant (burg) object corresponding to each of those intervals

c) 计算每个共振峰对象的中点

c) calculates the midpoint of each Formant object

c) 在每个中点处获取共振峰 1、2 和 3 的值

c) gets the values of formants 1, 2 and 3 at each of those midpoints

d) 写入具有以下标题的文本文件:

d) writes a text file with the following heading:

Narrative# Label Midpoint Time F1 F2 F3

然后是每个元音的适当信息

and under that, the appropriate information for each vowel

推荐答案

简单的方法

最简单的方法是将输出写入 Table 对象,然后使用 Praat 的 保存到逗号分隔文件 命令将其保存到外部文件.下面的示例使用新的(稍微更合理的)新语法,因此请确保在尝试之前更新 Praat(或尝试此答案编辑历史中的速记版本).

The easy way

The easiest way to do this would be to write your output to a Table object and then use Praat's Save to comma-separated file command to save it to an external file. Examples below use the new (slightly more reasonable) new syntax, so make sure to update Praat before trying them out (or try the shorthand versions in this answer's edit history).

这是一个例子:

# Create a Table with no rows
table = Create Table with column names:
..."table", 0, "Narrative Label Midpoint Time F1 F2 F3"

for i to number_of_intervals
  # Assuming you have your Formant objects in an array named "burg"
  selectObject(burg[i])
  # Run your analysis here
  # For this example, I'm assuming values for the columns are in
  # variables called narrative$, label$, midpoint, time, f1, f2 and f3

  selectObject(table)
  Append row
  current_row = Get number of rows
  # Insert your values
  Set string value:  current_row, "Narrative", narrative$
  Set string value:  current_row, "Label", label$
  Set numeric value: current_row, "Midpoint", midpoint 
  Set numeric value: current_row, "Time", time
  Set numeric value: current_row, "F1", f1 
  Set numeric value: current_row, "F2", f2
  Set numeric value: current_row, "F3", f3
endfor

# Save it!
# Remember to select it if the table is not the active selection at
# the end of the loop
Save to comma-separated file: /path/to/file
# And then you can get rid of it
removeObject(table)

或者你可以使用,如果你喜欢标签

Or you could use, if you prefer tabs

Save to tab-separated file: /path/to/file

请注意,此方法不允许您将Narrative#"作为列名.

Note that this method won't allow you to have "Narrative#" as a column name.

或者,您可以使用 Praat 的文件指令直接写入文件,如 文档:

Alternatively, you could use Praat's file directives write directly to the file as explained in the documentation:

sep$ = ","
# sep$ = tab$

# Create / overwrite file and write header
writeFileLine: "/path/to/file",
  ..."Narrative#" + sep$ +
  ..."Label"      + sep$ + 
  ..."Midpoint"   + sep$ +
  ..."Time"       + sep$ +
  ..."F1"         + sep$ +
  ..."F2"         + sep$ +
  ..."F3"

for i to number_of_intervals
  selectObject(burg[i])
  # Run your analysis here

  appendFileLine: "/path/to/file",
    ...narrative$        + sep$ +
    ...label$            + sep$ +
    ...string$(midpoint) + sep$ +
    ...string$(time)     + sep$ + 
    ...string$(f1)       + sep$ +
    ...string$(f2)       + sep$ +
    ...string$(f3)

endfor

这篇关于Praat 脚本:创建文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆