praat 中带有 for 循环的多个输出

Multiple outputs with a for loop in praat

我有一个脚本,其中有多个文件夹,每个文件夹中包含三个音频文件 ID#_1、ID#_2 和 ID#_3。用户可以一个接一个地输入一串不同的 ID#,然后脚本会识别不同的 ID 并 运行s 每个 ID 的代码。

我为此设置了一个 for 循环 -

form Settings comment Enter the IDs of the different subjects sentence subjectIDs endform

numOfSubjects = length(subjectIDs$)/4

for i from 0 to (numOfSubjects - 1)
    subjectID$ = mid$(subjectIDs$, 1 + 4*i, 4 + 4*i)
    outFile$ = subjectID$ + "/SubjectResponseOnsets" + subjectID$ + ".txt"
    path$ = subjectID$ + "/" + subjectID$
    @firstOutput
    @secondOutput
    @thirdOutput'

这些过程中的每一个都是先前在代码中定义的,它们基本上将特定范围的音频文件输出到文本文件。

代码似乎工作正常并在给出一个 ID 时正确生成输出文件,但是当我尝试 运行 它一次使用多个 ID 时,只有第一个的文本文件输出ID。

for 循环似乎运行不佳,但代码在第一个 运行 中运行良好。

如有任何帮助,我将不胜感激!

我不知道我是否理解你的脚本试图做什么,因为你粘贴的片段不完整。最好提供可按原样执行的代码。在这种情况下,您错过了结束 endfor,并且您正在调用一些未在您的代码段中定义的过程(甚至不是占位符)。我不得不写一些虚拟程序才能做到 运行。

由于您也没有说 您的脚本是如何失败的,所以不清楚需要修复什么。所以我努力让它发挥作用。

听起来好像您的 ID 拆分代码给您带来了一些问题。我通过 CPrAN 使用了 split procedure from the utils 插件,这使得输入 ID 更容易(完全披露:我写了那个插件)。

form Settings
  comment Enter the IDs of the different subjects
  sentence subjectIDs 01 02 03
endform

@split: " ", subjectIDs$
numOfSubjects = split.length

for i to numOfSubjects
  subjectID$ = split.return$[i]
  path$ = subjectID$
  outFile$ = path$ + "/SubjectResponseOnsets" + subjectID$ + ".txt"

  # Make sure output directory exists
  createDirectory: path$

  @firstOutput
  @secondOutput
  @thirdOutput
endfor

procedure firstOutput ()
  appendFileLine: outFile$, "First"
endproc

procedure secondOutput ()
  appendFileLine: outFile$, "Second"
endproc

procedure thirdOutput ()
  appendFileLine: outFile$, "Third"
endproc

# split procedure from the utils CPrAN plugin
# http://cpran.net/plugins/utils
procedure split (.sep$, .str$)
  .seplen = length(.sep$)
  .length = 0
  repeat
    .strlen = length(.str$)
    .sep = index(.str$, .sep$)
    if .sep > 0
      .part$ = left$(.str$, .sep-1)
      .str$ = mid$(.str$, .sep+.seplen, .strlen)
    else
      .part$ = .str$
    endif
    .length = .length+1
    .return$[.length] = .part$
  until .sep = 0
endproc

如果这不是您遇到的问题,您必须更具体一些。