-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetF0.praat
129 lines (101 loc) · 3.5 KB
/
getF0.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
# getF0.praat
# Get f0 at predefined points in the vowel: quartiles and deciles
# Get information about the file, vowel, and duration
# Written by Eleanor Chodroff
# 31 Oct 2020
#################
# where is the directory w/ TextGrids and wavs located? make sure the TextGrids and wav files have the same name and are in this same directory
dir$ = "/Users/xxx/xxx/Phonological Trains data/wav/male/"
# where should I write the file with the formants?
outfile$ = "/Users/eleanorchodroff/Desktop/trains_f0_male50-300.csv"
# hate csv files? fine, you can change that here
sep$ = ","
# female 100-500, male 50-300
minf0 = 50
maxf0 = 300
#################
# create header
appendFile: outfile$, "file", sep$, "vowel", sep$, "prec", sep$, "foll", sep$
appendFile: outfile$, "start", sep$, "end", sep$, "dur", sep$
appendFile: outfile$, "word", sep$
appendFile: outfile$, "f0_max", sep$, "f0_max_time", sep$, "f0_min", sep$, "f0_min_time", sep$
appendFile: outfile$, "f0_start", sep$, "f0_q1", sep$, "f0_mid", sep$, "f0_q3", sep$, "f0_end", sep$
appendFile: outfile$, "f0_t0", sep$, "f0_t1", sep$, "f0_t2", sep$, "f0_t3", sep$, "f0_t4", sep$, "f0_t5", sep$, "f0_t6", sep$, "f0_t7", sep$, "f0_t8", sep$, "f0_t9", sep$, "f0_t10", newline$
# loop through individual TextGrid files within the language directory
Create Strings as file list: "files", dir$ + "*.wav"
nFiles = Get number of strings
for i from 1 to nFiles
selectObject: "Strings files"
filename$ = Get string: i
basename$ = filename$ - ".wav"
Read from file: dir$ + basename$ + ".TextGrid"
Read from file: dir$ + basename$ + ".wav"
# convert wav files to pitch objects
To Pitch: 0, minf0, maxf0
# loop through TextGrid to find vowels
selectObject: "TextGrid " + basename$
nInt = Get number of intervals: 2
for j from 1 to nInt
selectObject: "TextGrid " + basename$
label$ = Get label of interval: 2, j
# do stuff if label is a vowel
if index_regex(label$, "^[AEIOULRWYMN]")
@getLabels
@getTime
@getWord
@getF0
appendFile: outfile$, newline$
endif
endfor
# do some clean up
select all
minusObject: "Strings files"
Remove
endfor
procedure getLabels
if j > 1
prec$ = Get label of interval: 2, j-1
else
prec$ = "NA"
endif
if j < nInt
foll$ = Get label of interval: 2, j+1
else
foll$ = "NA"
endif
appendFile: outfile$, basename$, sep$, label$, sep$, prec$, sep$, foll$, sep$
endproc
procedure getTime
start = Get start time of interval: 2, j
end = Get end time of interval: 2, j
dur = end - start
appendFile: outfile$, start, sep$, end, sep$, dur, sep$
endproc
procedure getWord
wordInt = Get interval at time: 1, start+0.01
word$ = Get label of interval: 1, wordInt
appendFile: outfile$, word$, sep$
endproc
procedure getF0
selectObject: "Pitch " + basename$
# get max and min f0
f0_max = Get maximum: start, end, "Hertz", "Parabolic"
f0_max_time = Get time of maximum: start, end, "Hertz", "Parabolic"
f0_min = Get minimum: start, end, "Hertz", "Parabolic"
f0_min_time = Get time of minimum: start, end, "Hertz", "Parabolic"
appendFile: outfile$, f0_max, sep$, f0_max_time, sep$, f0_min, sep$, f0_min_time, sep$
# get f0 at each quartile (including start and end)
for f from 0 to 4
f_time4 = Get value at time: start + f*(dur/4), "Hertz", "Linear"
appendFile: outfile$, f_time4, sep$
endfor
# get formats at each decile
for t from 0 to 10
f_timex = Get value at time: start + t*(dur/10), "Hertz", "Linear"
if t = 10
appendFile: outfile$, f_timex
else
appendFile: outfile$, f_timex, sep$
endif
endfor
endproc