-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvq_script_2.praat
More file actions
149 lines (135 loc) · 4.23 KB
/
vq_script_2.praat
File metadata and controls
149 lines (135 loc) · 4.23 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
form Variables
sentence filename
endform
# Constants
sex = 1
chunk = 1 ; Divide segment into 3 chunks
length = 0.005 ; Length of window for spectrogram
f1ref = 500 ; Reference F1 frequency for males
f2ref = 1485 ; Reference F2 frequency for males
f3ref = 2475 ; Reference F3 frequency for males
freqcost = 1 ; Frequency cost
bwcost = 1 ; Bandwidth cost
transcost = 1 ; Transition cost
# Initialize output variable with column titles
output$ = "time" + tab$ + "H1_H2" + tab$ + "H1_A1" + tab$ + "H1_A2" + tab$+ "H1_A3" + newline$
# Load the specified sound file:
Read from file... 'filename$'
soundname$ = selected$ ("Sound", 1)
sound = selected("Sound")
# Set parameters based on sex
maxf = 5000 ; Maximum frequency for formant calculation (male)
select 'sound'
begin = Get start time
end = Get end time
Resample... 16000 50
sound_16khz = selected("Sound")
To Formant (burg)... 0.01 5 'maxf' 0.025 50
Rename... 'soundname$_beforetracking'
formant_beforetracking = selected("Formant")
xx = Get minimum number of formants
if xx > 2
Track... 3 'f1ref' 'f2ref' 'f3ref' 3465 4455 'freqcost' 'bwcost' 'transcost'
else
Track... 2 'f1ref' 'f2ref' 'f3ref' 3465 4455 'freqcost' 'bwcost' 'transcost'
endif
Rename... 'soundname$_aftertracking'
formant_aftertracking = selected("Formant")
select 'sound'
To Spectrogram... 'length' 4000 0.002 20 Gaussian
spectrogram = selected("Spectrogram")
select 'sound'
To Pitch... 0 60 350
pitch = selected("Pitch")
Interpolate
Rename... 'soundname$_interpolated'
pitch_interpolated = selected("Pitch")
# Divide the interval into chunks:
n_d = end - begin
for kounter from 1 to chunk
n_seg = n_d / chunk
n_md = begin + ((kounter - 1) * n_seg) + (n_seg / 2)
# Get F1, F2, and F3 measurements
select 'formant_aftertracking'
f1hzpt = Get value at time... 1 n_md Hertz Linear
f2hzpt = Get value at time... 2 n_md Hertz Linear
if xx > 2
f3hzpt = Get value at time... 3 n_md Hertz Linear
else
f3hzpt = 0
endif
# Extract sound for spectral analysis
select 'sound_16khz'
spectrum_begin = begin + ((kounter - 1) * n_seg)
spectrum_end = begin + (kounter * n_seg)
Extract part... 'spectrum_begin' 'spectrum_end' Hanning 1 no
Rename... 'soundname$_slice'
To Spectrum (fft)
To Ltas (1-to-1)
ltas = selected("Ltas")
select 'pitch_interpolated'
n_f0md = Get value at time... n_md Hertz Linear
if n_f0md <> undefined
# Calculate H1 and H2
h1db = undefined
h2db = undefined
select 'ltas'
lowerbh1 = n_f0md - (n_f0md / 10)
upperbh1 = n_f0md + (n_f0md / 10)
lowerbh2 = (n_f0md * 2) - ((n_f0md * 2) / 10)
upperbh2 = (n_f0md * 2) + ((n_f0md * 2) / 10)
h1db = Get maximum... lowerbh1 upperbh1 None
h2db = Get maximum... lowerbh2 upperbh2 None
if h1db = undefined
h1db = 0
endif
if h2db = undefined
h2db = 0
endif
# Calculate A1, A2, and A3
a1db = undefined
a2db = undefined
a3db = undefined
if f1hzpt <> undefined
lowerba1 = f1hzpt - (f1hzpt / 10)
upperba1 = f1hzpt + (f1hzpt / 10)
a1db = Get maximum... lowerba1 upperba1 None
endif
if f2hzpt <> undefined
lowerba2 = f2hzpt - (f2hzpt / 10)
upperba2 = f2hzpt + (f2hzpt / 10)
a2db = Get maximum... lowerba2 upperba2 None
endif
if f3hzpt <> undefined
lowerba3 = f3hzpt - (f3hzpt / 10)
upperba3 = f3hzpt + (f3hzpt / 10)
a3db = Get maximum... lowerba3 upperba3 None
endif
if a1db = undefined
a1db = 0
endif
if a2db = undefined
a2db = 0
endif
if a3db = undefined
a3db = 0
endif
# Calculate differences
h1mnh2 = h1db - h2db
h1mna1 = h1db - a1db
h1mna2 = h1db - a2db
h1mna3 = h1db - a3db
else
h1mnh2 = 0
h1mna1 = 0
h1mna2 = 0
h1mna3 = 0
endif
# Append result line
spectrum_mid = ( spectrum_end + spectrum_begin ) /2
output$ = output$ + string$(spectrum_mid) + tab$ + string$(h1mnh2) + tab$ + string$(h1mna1) + tab$ + string$(h1mna2) + tab$ + string$(h1mna3) + newline$
endfor
# Print all results at once
echo 'output$'
select all
Remove