我有一个脚本,其中我有多个文件夹,每个文件夹中都有三个音频文件-- ID#_1、ID#_2和ID#_3。用户可以一个接一个地输入不同的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循环似乎不能很好地工作,但是代码在第一次运行时确实工作得很好。
我将非常感谢任何帮助!
发布于 2015-04-03 23:59:34
我不知道我是否理解你的脚本试图做什么,因为你粘贴的片段是不完整的。最好是提供可执行的代码。在这种情况下,您丢失了关闭的endfor,并且调用了一些在代码段中没有定义的过程(甚至不是占位符)。为了让它运行,我不得不编写一些虚拟的程序。
由于您也没有说明您的脚本是如何失败的,所以还不清楚需要修复什么。所以我试着让它发挥作用。
听起来好像你的ID分裂代码给你带来了一些问题。我将 procedure从通过CPrAN提供的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如果这不是你遇到问题的地方,你必须更加具体。
https://stackoverflow.com/questions/29418909
复制相似问题