在提取基频值的时候有一些值是没有定义的,输出窗口显示undefinded,如果单纯把这个当成一个字符串是行不通的,比如pitchvalue="--undefined--",这是不可能的。字符串不可能等于数值,实现的方式是直接用pitchvalue=undefined,在这里的undefined相当于一个预定义常量。
例:声音文件和标注文件有一些偏差,比如标注文件都要比声音文件提前0.1-0.5秒,在实现的时候是通过声音的Pitch文件找到Pitch值不为undefined的第一个值,然后再将这个时长偏差减小0.3,作为起始的清音段,这样通过针对TextGrid的Shift操作就可以了。代码如下:
path$="\old\"
savePath$="\new\"
Create Strings as file list... fileList 'path$'*.wav
fileNumber=Get number of strings
for iFile from 1 to fileNumber
select Strings fileList
fileName$=Get string... 'iFile'
simpleName$=fileName$-".wav"
wavFileName$=simpleName$+".wav"
textGridName$=simpleName$+".TextGrid"
Read from file... 'path$''textGridName$'
labsil$=Get label of interval... 1 1
if labsil$<>"sil"
pause The first interval lab is NOT sil.
else
timeEnd=Get end point... 1 1
endif
Read from file... 'path$''wavFileName$'
To Pitch... 0 60 600
numberOfFrames=Get number of frames
iFrame=0
repeat
iFrame=iFrame+1
pitchValue=Get value in frame... 'iFrame' Hertz
until pitchValue<>undefined
time2=Get time from frame number... 'iFrame'
if time2>timeEnd
select TextGrid 'simpleName$'
temp=time2-timeEnd-0.03
Shift times by... temp
endif
select TextGrid 'simpleName$'
Save as text file... 'savePath$''textGridName$'
select Sound 'simpleName$'
Save as WAV file... 'savePath$''fileName$'
select TextGrid 'simpleName$'
plus Sound 'simpleName$'
plus Pitch 'simpleName$'
Remove
endfor
select Strings fileList
Remove
exit over!