-
Notifications
You must be signed in to change notification settings - Fork 64
/
Compute_Rythms_By_VC.Praat
133 lines (129 loc) · 4.41 KB
/
Compute_Rythms_By_VC.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# This Praat script will compute some rhythm measures.
#
# This script is distributed under the GNU General Public License.
# 博客说明:https://blog.csdn.net/shaopengfei/article/details/112298818
# Copyright 2020.05.09 feelins[[email protected]]
form Dialogue
comment 请输入标注文件目录:
text read_path data\
comment 结果文件:
text save_path result.txt
comment
comment VC所在的层级:
positive vc_tier 1
endform
if (praatVersion < 6113)
clearinfo
appendInfoLine: "Requires Praat version 6.1.13 or higher."
appendInfoLine: "Please upgrade your Praat version."
exit
endif
Create Strings as file list: "fileList", read_path$ + "\*.TextGrid"
deleteFile: save_path$
appendFileLine: save_path$, "fileName" + tab$ + "sum_V" + tab$ + "sum_C" + tab$ + "mean_V" + tab$ + "mean_C" + tab$ + "delta_V" + tab$ + "delta_C" + tab$ + "percent_V" + tab$ + "varco_V" + tab$ + "varco_C" + tab$ + "nPVI_V" + tab$ + "nPVI_C" + tab$ + "rPVI_V" + tab$ + "rPVI_C"
numOfFiles = Get number of strings
for ifile from 1 to numOfFiles
selectObject: "Strings fileList"
fileName$ = Get string: ifile
Read from file: read_path$ + "\" + fileName$
simpleName$ = selected$("TextGrid")
selectObject: "TextGrid " + simpleName$
totalDuration = Get total duration
Down to Table: "no", 6, "no", "no"
Append difference column: "tmax", "tmin", "duration"
totalNumRows = Get number of rows
firstLabel$ = Get value: 1, "text"
if firstLabel$ = "sil"
firstDuration = Get value: 1, "duration"
totalDuration = totalDuration - firstDuration
endif
lastLabel$ = Get value: totalNumRows, "text"
if lastLabel$ = "sil"
lastDuration = Get value: totalNumRows, "duration"
totalDuration = totalDuration - lastDuration
endif
selectObject: "Table " + simpleName$
Extract rows where column (text): "text", "is equal to", "V"
selectObject: "Table " + simpleName$ + "_V"
numRows = Get number of rows
for iRow from 1 to numRows
durationV[iRow] = Get value: iRow, "duration"
endfor
# mean
meanV = Get mean: "duration"
# sum
sumV = numRows * meanV
# percent
percentV = sumV / totalDuration
# standard deviation
stdV = Get standard deviation: "duration"
# varco
varcoV = 100 * (stdV / meanV)
# rPVI_V
tmpPVI_V = 0
for iRow from 1 to numRows - 1
curDurationV = durationV[iRow]
nextDurationV = durationV[iRow + 1]
tmpPVI_V = tmpPVI_V + abs(curDurationV - nextDurationV)
endfor
rPVI_V = tmpPVI_V / (numRows - 1) * 100
# nPVI_V
tmpPVI_V = 0
for iRow from 1 to numRows - 1
curDurationV = durationV[iRow]
nextDurationV = durationV[iRow + 1]
if curDurationV = 0 and nextDurationV = 0
tmpPVI_V = tmpPVI_V
else
tmpPVI_V = tmpPVI_V + abs((abs(curDurationV - nextDurationV)) / ((curDurationV + nextDurationV) / 2))
endif
endfor
nPVI_V = tmpPVI_V / (numRows - 1) * 100
Save as tab-separated file: read_path$ + "\" + fileName$ + "_V.Table"
Remove
selectObject: "Table " + simpleName$
Extract rows where column (text): "text", "is equal to", "C"
selectObject: "Table " + simpleName$ + "_C"
numRows = Get number of rows
for iRow from 1 to numRows
durationC[iRow] = Get value: iRow, "duration"
endfor
# meanC
meanC = Get mean: "duration"
# sumC
sumC = numRows * meanC
# stdC
stdC = Get standard deviation: "duration"
# varcoC
varcoC = 100 * (stdC / meanC)
# rPVI_C
tmpPVI_C = 0
for iRow from 1 to numRows - 1
curDurationC = durationC[iRow]
nextDurationC = durationC[iRow + 1]
tmpPVI_C = tmpPVI_C + abs(curDurationC - nextDurationC)
endfor
rPVI_C = tmpPVI_C / (numRows - 1) * 100
# nPVI_C
tmpPVI_C = 0
for iRow from 1 to numRows - 1
curDurationC = durationC[iRow]
nextDurationC = durationC[iRow + 1]
if curDurationC = 0 and nextDurationC = 0
tmpPVI_C = tmpPVI_C
else
tmpPVI_C = tmpPVI_C + abs((abs(curDurationC - nextDurationC)) / ((curDurationC + nextDurationC) / 2))
endif
endfor
nPVI_C = tmpPVI_C / (numRows - 1) * 100
Save as tab-separated file: read_path$ + "\" + fileName$ + "_C.Table"
Remove
appendFileLine: save_path$, fileName$ + tab$ + fixed$(sumV, 3) + tab$ + fixed$(sumC, 3) + tab$ + fixed$(meanV, 3) + tab$ + fixed$(meanC, 3) + tab$ + fixed$(stdV, 3) + tab$ + fixed$(stdC, 3) + tab$ + fixed$(percentV, 3) + tab$ + fixed$(varcoV, 3) + tab$ + fixed$(varcoC, 3) + tab$ + fixed$(nPVI_V, 3) + tab$ + fixed$(nPVI_C, 3) + tab$ + fixed$(rPVI_V, 3) + tab$ + fixed$(rPVI_C, 3)
selectObject: "Table " + simpleName$
Remove
selectObject: "TextGrid " + simpleName$
Remove
endfor
selectObject: "Strings fileList"
Remove
exit Done!