在计算点或边界处提取 Praat 音高(不是平均音程)
Praat pitch extraction at calculated points or boundaries (not mean pitch in intervals)
我正在调整一个脚本,其中对于文件夹中的每个声音文件和文本网格,我遍历每个音节标签,将标签分成三个相等的部分,然后在每个部分的中点提取音高并保存有关信息中点和相应的音高到一个文本文件,我将其保存在同一目录中。当我运行脚本生成的文本文件只包含header。您能找出阻止我访问 and/or 保存我试图提取的信息的错误吗?下面我粘贴了我计算中点并在这些点提取音高的代码。
# Write a row with column titles to the result file:
titleline$ = "Filename Syllable Midpoint1 Midpoint2 Midpoint3 Pitch1 Pitch2 Pitch3'newline$'"
fileappend "'resultfile$'" 'titleline$'
# Go through all the sound files, one by one:
for i from 1 to numberOfFiles
filename$ = Get string... ifile
# A sound file is opened from the listing:
Read from file: 'sound_directory$''filename$'
# Starting from here, you can add everything that should be
# repeated for every sound file that was opened:
soundname$ = selected$ ("Sound", 1)
To Pitch... Time_step Minimum_pitch Maximum_pitch
# Open a TextGrid by the same name:
gridfile$ = "'textGrid_directory$''soundname$''textGrid_file_extension$'"
if fileReadable (gridfile$)
Read from file... 'gridfile$'
# Find the tier number that has the label given in the form:
call GetTier 'tier$' tier
numberOfIntervals = Get number of intervals... tier
# Pass through all intervals in the selected tier:
for interval to numberOfIntervals
label$ = Get label of interval... tier interval
if label$ <> ""
# if the interval has an unempty label, get its start and end:
start = Get starting point... tier interval
end = Get end point... tier interval
dur = end - start
# divide interval into 3 segments
segdur = dur/3
midpoint1 = start + (segdur/2)
midpoint2 = start + segdur + (segdur/2)
midpoint3 = start + (segdur*2) + (segdur/2)
# get pitch at each midpoint
Move cursor to: midpoint1
pitch1 = Get pitch... midpoint1
Move cursor to: midpoint2
pitch1 = Get pitch... midpoint2
Move cursor to: midpoint3
pitch1 = Get pitch... midpoint3
# Save result to text file:
resultline$ = "'soundname$' 'label$' 'midpoint1' 'midpoint2' 'midpoint3' 'pitch1' 'pitch2' 'pitch3''newline$'"
fileappend "'resultfile$'" 'resultline$'
select TextGrid 'soundname$'
endif
endfor
# Remove the TextGrid object from the object list
select TextGrid 'soundname$'
Remove
endif
# Remove the temporary objects from the object list
select Sound 'soundname$'
plus Pitch 'soundname$'
Remove
select Strings list
endfor
Remove
感谢您的指教!在与代码搏斗了几个小时之后,我设法让脚本工作了。几天过去了,还没有人 post 给出完整的答案,我想我会 post 我的,尽管它是值得的。
问题是我没有 select 将音高作为一个对象,同时想要提取音高。所以先select pitch select Pitch 'soundname$'
然后获取指定时间的pitch值pitch1 = Get value at time... time_point Hertz linear
。希望这对其他人有帮助。
为了全面披露,此脚本改编自 Mietta Lennes 的 Github 网站,其中包含 Praat 脚本模板 (https://github.com/lennes)。
# Write a row with column titles to the result file:
titleline$ = "Filename Syllable Midpoint1 Midpoint2 Midpoint3 Pitch1 Pitch2 Pitch3'newline$'"
fileappend "'resultfile$'" 'titleline$'
fileappend "'resultfile$'" "'numberOfFiles'"
# Go through all the sound files, one by one:
for ifile to numberOfFiles
filename$ = Get string... ifile
fileappend "'resultfile$'" 'sound_directory$''filename$'
# A sound file is opened from the listing:
Read from file... 'sound_directory$''filename$'
# Starting from here, you can add everything that should be
# repeated for every sound file that was opened:
soundname$ = selected$ ("Sound", 1)
To Pitch... time_step minimum_pitch maximum_pitch
# Open a TextGrid by the same name:
gridfile$ = "'textGrid_directory$''soundname$''textGrid_file_extension$'"
if fileReadable (gridfile$)
Read from file... 'gridfile$'
# Find the tier number that has the label given in the form:
call GetTier 'tier$' tier
numberOfIntervals = Get number of intervals... tier
# Pass through all intervals in the selected tier:
for interval to numberOfIntervals
label$ = Get label of interval... tier interval
if label$ <> ""
# if the interval has an unempty label, get its start and end:
start = Get starting point... tier interval
end = Get end point... tier interval
dur = end - start
# divide interval into 3 segments
segdur = dur/3
midpoint1 = start + (segdur/2)
midpoint2 = start + segdur + (segdur/2)
midpoint3 = start + (segdur*2) + (segdur/2)
# get pitch at each midpoint
select Pitch 'soundname$'
pitch1 = Get value at time... midpoint1 Hertz linear
pitch2 = Get value at time... midpoint2 Hertz linear
pitch3 = Get value at time... midpoint3 Hertz linear
# Save result to text file:
resultline$ = "'soundname$' 'label$' 'midpoint1' 'midpoint2' 'midpoint3' 'pitch1' 'pitch2' 'pitch3''newline$'"
fileappend "'resultfile$'" 'resultline$'
select TextGrid 'soundname$'
endif
endfor
# Remove the TextGrid object from the object list
select TextGrid 'soundname$'
Remove
endif
# Remove the temporary objects from the object list
select Sound 'soundname$'
plus Pitch 'soundname$'
Remove
select Strings list
endfor
我正在调整一个脚本,其中对于文件夹中的每个声音文件和文本网格,我遍历每个音节标签,将标签分成三个相等的部分,然后在每个部分的中点提取音高并保存有关信息中点和相应的音高到一个文本文件,我将其保存在同一目录中。当我运行脚本生成的文本文件只包含header。您能找出阻止我访问 and/or 保存我试图提取的信息的错误吗?下面我粘贴了我计算中点并在这些点提取音高的代码。
# Write a row with column titles to the result file:
titleline$ = "Filename Syllable Midpoint1 Midpoint2 Midpoint3 Pitch1 Pitch2 Pitch3'newline$'"
fileappend "'resultfile$'" 'titleline$'
# Go through all the sound files, one by one:
for i from 1 to numberOfFiles
filename$ = Get string... ifile
# A sound file is opened from the listing:
Read from file: 'sound_directory$''filename$'
# Starting from here, you can add everything that should be
# repeated for every sound file that was opened:
soundname$ = selected$ ("Sound", 1)
To Pitch... Time_step Minimum_pitch Maximum_pitch
# Open a TextGrid by the same name:
gridfile$ = "'textGrid_directory$''soundname$''textGrid_file_extension$'"
if fileReadable (gridfile$)
Read from file... 'gridfile$'
# Find the tier number that has the label given in the form:
call GetTier 'tier$' tier
numberOfIntervals = Get number of intervals... tier
# Pass through all intervals in the selected tier:
for interval to numberOfIntervals
label$ = Get label of interval... tier interval
if label$ <> ""
# if the interval has an unempty label, get its start and end:
start = Get starting point... tier interval
end = Get end point... tier interval
dur = end - start
# divide interval into 3 segments
segdur = dur/3
midpoint1 = start + (segdur/2)
midpoint2 = start + segdur + (segdur/2)
midpoint3 = start + (segdur*2) + (segdur/2)
# get pitch at each midpoint
Move cursor to: midpoint1
pitch1 = Get pitch... midpoint1
Move cursor to: midpoint2
pitch1 = Get pitch... midpoint2
Move cursor to: midpoint3
pitch1 = Get pitch... midpoint3
# Save result to text file:
resultline$ = "'soundname$' 'label$' 'midpoint1' 'midpoint2' 'midpoint3' 'pitch1' 'pitch2' 'pitch3''newline$'"
fileappend "'resultfile$'" 'resultline$'
select TextGrid 'soundname$'
endif
endfor
# Remove the TextGrid object from the object list
select TextGrid 'soundname$'
Remove
endif
# Remove the temporary objects from the object list
select Sound 'soundname$'
plus Pitch 'soundname$'
Remove
select Strings list
endfor
Remove
感谢您的指教!在与代码搏斗了几个小时之后,我设法让脚本工作了。几天过去了,还没有人 post 给出完整的答案,我想我会 post 我的,尽管它是值得的。
问题是我没有 select 将音高作为一个对象,同时想要提取音高。所以先select pitch select Pitch 'soundname$'
然后获取指定时间的pitch值pitch1 = Get value at time... time_point Hertz linear
。希望这对其他人有帮助。
为了全面披露,此脚本改编自 Mietta Lennes 的 Github 网站,其中包含 Praat 脚本模板 (https://github.com/lennes)。
# Write a row with column titles to the result file:
titleline$ = "Filename Syllable Midpoint1 Midpoint2 Midpoint3 Pitch1 Pitch2 Pitch3'newline$'"
fileappend "'resultfile$'" 'titleline$'
fileappend "'resultfile$'" "'numberOfFiles'"
# Go through all the sound files, one by one:
for ifile to numberOfFiles
filename$ = Get string... ifile
fileappend "'resultfile$'" 'sound_directory$''filename$'
# A sound file is opened from the listing:
Read from file... 'sound_directory$''filename$'
# Starting from here, you can add everything that should be
# repeated for every sound file that was opened:
soundname$ = selected$ ("Sound", 1)
To Pitch... time_step minimum_pitch maximum_pitch
# Open a TextGrid by the same name:
gridfile$ = "'textGrid_directory$''soundname$''textGrid_file_extension$'"
if fileReadable (gridfile$)
Read from file... 'gridfile$'
# Find the tier number that has the label given in the form:
call GetTier 'tier$' tier
numberOfIntervals = Get number of intervals... tier
# Pass through all intervals in the selected tier:
for interval to numberOfIntervals
label$ = Get label of interval... tier interval
if label$ <> ""
# if the interval has an unempty label, get its start and end:
start = Get starting point... tier interval
end = Get end point... tier interval
dur = end - start
# divide interval into 3 segments
segdur = dur/3
midpoint1 = start + (segdur/2)
midpoint2 = start + segdur + (segdur/2)
midpoint3 = start + (segdur*2) + (segdur/2)
# get pitch at each midpoint
select Pitch 'soundname$'
pitch1 = Get value at time... midpoint1 Hertz linear
pitch2 = Get value at time... midpoint2 Hertz linear
pitch3 = Get value at time... midpoint3 Hertz linear
# Save result to text file:
resultline$ = "'soundname$' 'label$' 'midpoint1' 'midpoint2' 'midpoint3' 'pitch1' 'pitch2' 'pitch3''newline$'"
fileappend "'resultfile$'" 'resultline$'
select TextGrid 'soundname$'
endif
endfor
# Remove the TextGrid object from the object list
select TextGrid 'soundname$'
Remove
endif
# Remove the temporary objects from the object list
select Sound 'soundname$'
plus Pitch 'soundname$'
Remove
select Strings list
endfor