下午好🌅🌅🌅
本答案参考ChatGPT-3.5
对于此问题,您遇到了两个错误。第一个是删除文件夹命令的错误,第二个是判断新建文件夹是否为空的错误。
针对这两个问题,您可以按照以下步骤进行修改:
-
将deleteDirectory(new_dir$)替换为removeDirectory(new_dir$)或dropDirectory(new_dir$),这两个命令是删除文件夹的有效命令。
-
在判断新建文件夹是否为空时,您可以使用创建一个字符串列表,然后通过获取列表中的字符串数量来判断文件夹是否为空。如果数量为0,则表示文件夹为空,可以调用removeDirectory(new_dir$)或dropDirectory(new_dir$)删除文件夹。如果数量不为0,则表示文件夹中有文件,可以继续操作。
根据上述修改,您的修改后的代码如下:
form Extract smaller files from large file
sentence Directory: D:\Praat\Testing_data
sentence File_prefix: phoneme_
positive Tier_number: 1
endform
clearinfo
string = Create Strings as file list: "filelist", directory$ + "\*.wav"
select 'string'
num_file = Get number of strings
for i_file to num_file
select 'string'
file_name$ = Get string: i_file
Read from file: directory$ + "\" + file_name$
sound_file = selected("Sound")
sound_name$ = selected$("Sound")
new_dir$ = directory$ + "\" + sound_name$
createDirectory(new_dir$)
printline New directory "'new_dir$'" has created.
Read from file: directory$ + "\" + sound_name$ + ".TextGrid"
textgrid_file = selected("TextGrid")
select 'textgrid_file'
num_intvl = Get number of intervals: tier_number
printline Totally 'num_intvl' intervals in tier 'tier_number'.
for i_intvl to num_intvl
select 'textgrid_file'
lab$ = Get label of interval: tier_number, i_intvl
if lab$ = "t"
printline Start working on interval No.'i_intvl', "'lab$'".
start = Get start time of interval: tier_number, i_intvl
end = Get end time of interval: tier_number, i_intvl
select 'textgrid_file'
textgrid_chunk = Extract part: start, end, "no"
select 'sound_file'
Extract part: start, end, "rectangular", 1, "no"
Write to WAV file: new_dir$ + "\" + file_prefix$ + lab$ + ".wav"
select 'textgrid_chunk'
Save as text file: new_dir$ + "\" + file_prefix$ + lab$ + ".TextGrid"
else
endif
endfor
new_string = Create Strings as file list: "list", new_dir$
num_string = Get number of strings
if num_string = 0
printline No files found in the directory.
removeDirectory(new_dir$) ; 或 dropDirectory(new_dir$)
printline 'new_dir$' has been removed
else
printline Directory contains files
endif
endfor
select all
Remove
printline already!
希望这些修改可以解决您的问题。如果还有其他问题,请随时向我咨询。
