-
Notifications
You must be signed in to change notification settings - Fork 64
/
Get_Duration_and_Intensity.Praat
78 lines (68 loc) · 2.79 KB
/
Get_Duration_and_Intensity.Praat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This Praat script will extract duration and intensity of One particular Tier based on the TextGrid file and sound file
# and save result to a TXT file.
# 提取某一层的Interval的时长及名称(空白标注忽略),以及根据标注的时间段的音强的平均值, 需要提供标注TextGrid和sound
#
# This script is distributed under the GNU General Public License.
# Copyright 2021.04.25 feelins[[email protected]]
form Information
comment Directory path of input wav files:
text input_wav_directory input_wav\
comment Directory path of input TextGrid files:
text input_directory input_TextGrid\
comment Target Tier:
positive reference_tier 2
comment Path of output result file:
text save_result result_duration_intensity.txt
endform
if (praatVersion < 6001)
printline Requires Praat version 6.0 or higher. Please upgrade your Praat version
exit
endif
writeFileLine: save_result$, "fileName" + tab$ + "name" + tab$ + "duration" + tab$ + "intensity1" + tab$ + "intensity2" + tab$ + "intensity3" + tab$ + "intensity4" + tab$ + "intensity5" + tab$ + "intensity6" + tab$ + "intensity7" + tab$ + "intensity8" + tab$ + "intensity9" + tab$ + "intensity10" + tab$ + "meanIntensity"
Create Strings as file list: "fileList", input_directory$ + "*.TextGrid"
numberOfFiles = Get number of strings
for iFile from 1 to numberOfFiles
selectObject: "Strings fileList"
fileName$ = Get string: iFile
textGridFileName$ = input_directory$ + fileName$
Read from file: textGridFileName$
objectName$ = selected$ ("TextGrid", 1)
wavFileName$ = input_wav_directory$ + objectName$ + ".wav"
Read from file: wavFileName$
To Intensity: 100, 0, "yes"
selectObject: "TextGrid " + objectName$
numberOfIntervals = Get number of intervals: reference_tier
for iInterval from 1 to numberOfIntervals
selectObject: "TextGrid " + objectName$
sTime = Get start point: reference_tier, iInterval
eTime = Get end point: reference_tier, iInterval
duration = eTime-sTime
labelOfInterval$ = Get label of interval: reference_tier, iInterval
output$ = fileName$ + tab$ + labelOfInterval$ + tab$ + fixed$(duration, 3) + tab$
stepTime = duration / 9
if labelOfInterval$ <> ""
for i from 1 to 10
selectObject: "Intensity " + objectName$
tmpTime = sTime + stepTime * (i - 1)
#pause 'tmpTime'
intensityValue = Get value at time: tmpTime, "cubic"
output$ = output$ + fixed$(intensityValue, 0)
if i <> 10
output$ = output$ + tab$
endif
endfor
meanValue = Get mean: sTime, eTime, "dB"
output$ = output$ + tab$ + fixed$(meanValue, 3)
appendFileLine: save_result$, output$
endif
endfor
selectObject: "TextGrid " + objectName$
Remove
selectObject: "Sound " + objectName$
Remove
selectObject: "Intensity " + objectName$
Remove
endfor
selectObject: "Strings fileList"
Remove
exit Done!Thank you!-shaopf