### Create new file ###
#if fileReadable ("L:\Korpus\vokaler\statistik\'file$'_'variable$'.csv")
# deleteFile ("L:\Korpus\vokaler\statistik\'file$'_'variable$'.csv")
#endif
if fileReadable ("L:\Korpus\vokaler\statistik\AllFiles.csv")
deleteFile ("L:\Korpus\vokaler\statistik\AllFiles.csv")
endif
### Header ###
#fileappend L:\Korpus\vokaler\statistik\'file$'_'variable$'.csv File;Year;Decade;Speaker;Variable;PreWord;TargetWord;ProWord;PreSound;ProSound;Timing;MaxFreq;BW1;BW2;BW3;F1;F2;F3;DefaultFreq;BW1d;BW2d;BW3d;F1d;F2d;F3d'newline$'
fileappend L:\Korpus\vokaler\statistik\AllFiles.csv File;Year;Decade;Speaker;Sex;Variable;PreWord;TargetWord;ProWord;PreSound;ProSound;Timing;MaxFreq;BW1;BW2;BW3;F1;F2;F3;DefaultFreq;BW1d;BW2d;BW3d;F1d;F2d;F3d'newline$'
Create Strings as file list... filesShort L:\Korpus\vokaler\*Short*F.TextGrid
Create Strings as file list... filesLong L:\Korpus\vokaler\*Long*F.TextGrid
plus Strings filesShort
Append
select Strings filesShort
Remove
select Strings filesLong
Remove
Read Strings from raw text file... L:\Korpus\femaleSpeakers.txt
females = Get number of strings
select Strings appended
strings = Get number of strings
for string to strings
select Strings appended
string$ = Get string... string
filename$ = replace$ ("'string$'", ".TextGrid", "", 1)
### Select files ###
variable$ = replace_regex$ ("'filename$'", "([0-9]+_)?([0-9]_)?[0-9]{8}_", "", 1)
variable$ = replace_regex$ ("'variable$'", "_?F", "", 1)
file$ = replace_regex$ ("'filename$'", "_'variable$'_?F", "", 1)
file2$ = replace_regex$ ("'file$'", "^([0-9]+_)?([0-9]_)?([0-9]_)*", "", 1)
year$ = replace_regex$ ("'file2$'", "[0-9]{4}$", "", 1)
decade$ = replace_regex$ ("'year$'", "[0-9]$", "0", 1)
#decade = 'decade$'
decade$ = "'decade$'s"
Read from file... L:\Korpus\vokaler\'string$'
Open long sound file... L:\Korpus\lydfiler\'file$'.wav
Read from file... L:\Korpus\textgrids\'file$'.TextGrid
ortointervals = Get number of intervals... 1
### Default speaker ###
speakersegment$ = "XXX"
### Loop ###
select TextGrid 'filename$'
vowels = Get number of points... 4
for vowel to vowels
select TextGrid 'filename$'
time = Get time of point... 4 vowel
### Orthography ###
ortointerval = Get interval at time... 1 time
word$ = Get label of interval... 1 ortointerval
if ortointerval > 1
preword$ = Get label of interval... 1 ortointerval-1
else
preword$ = ""
endif
if ortointerval < ortointervals
proword$ = Get label of interval... 1 ortointerval+1
else
proword$ = ""
endif
### Find speaker ###
select TextGrid 'file$'
segment = Get interval at time... 2 time
speaker$ = Get label of interval... 2 segment
speaker$ = replace_regex$ ("'speaker$'", ".+\(", "", 1)
speaker$ = replace_regex$ ("'speaker$'", "\)$", "", 1)
if speaker$ <> speakersegment$
sex = 1
select Strings femaleSpeakers
for speaker to females
taler$ = Get string... speaker
if startsWith (speaker$, taler$) > 0
sex = 2
endif
endfor
if sex = 1
defaultfreq = 5000
sex$ = "M"
elsif sex = 2
defaultfreq = 5500
sex$ = "F"
endif
speakersegment$ = speaker$
endif
### Vowel timing ###
select TextGrid 'filename$'
vowelinterval = Get interval at time... 3 time
vowelstart = Get start point... 3 vowelinterval
vowelend = Get end point... 3 vowelinterval
voweltime = vowelend-vowelstart
voweltime = voweltime*1000
### Phonological context ###
phoninterval = Get interval at time... 2 time
phon$ = Get label of interval... 2 phoninterval
### Index depends on variable ###
if variable$ = "ANLong"
place = index (phon$, "2z:")
elsif variable$ = "ANShort"
place = index (phon$, "2a")
elsif variable$ = "AMLong"
place = index (phon$, "2A:")
elsif variable$ = "AMShort"
place = index (phon$, "2A")
endif
### Preceeding vowel (may be in preceeding interval, if that is not empty) ###
preceeding$ = mid$ (phon$, place-1, 1)
if preceeding$ = "["
phon2$ = Get label of interval... 2 phoninterval-1
if phon2$ = ""
preceeding$ = "Ø"
else
length = length (phon2$)
preceeding$ = mid$ (phon2$, length-1, 1)
endif
endif
### Proceeding vowel (may be in proceeding interval, if that is not empty) ###
if endsWith (variable$, "Long")
proceeding$ = mid$ (phon$, place+3, 1)
### If the vowel has stød, the stød is not considered context ###
if proceeding$ = "!"
proceeding$ = mid$ (phon$, place+4, 1)
endif
if proceeding$ = "]"
phon2$ = Get label of interval... 2 phoninterval+1
if phon2$ = ""
proceeding$ = "Ø"
else
proceeding$ = mid$ (phon2$, 2, 1)
if proceeding$ = "2"
proceeding$ = mid$ (phon2$, 3, 1)
endif
endif
endif
elsif endsWith (variable$, "Short")
proceeding$ = mid$ (phon$, place+2, 1)
### If the vowel has stød, the stød is not considered context ###
if proceeding$ = "!"
proceeding$ = mid$ (phon$, place+3, 1)
endif
if proceeding$ = "]"
phon2$ = Get label of interval... 2 phoninterval+1
if phon2$ = ""
proceeding$ = "Ø"
else
proceeding$ = mid$ (phon2$, 2, 1)
if proceeding$ = "2"
proceeding$ = mid$ (phon2$, 3, 1)
endif
endif
endif
endif
### Formant extraction ###
select LongSound 'file$'
Extract part... time-0.1 time+0.1 yes
maxfreq = 4500
bw = 1000
### Evaluate BandWidth of f1 and select candidate MaxFreq setting ###
while maxfreq < 6000
To Formant (burg)... 0 5 maxfreq 0.03 50
bw1'maxfreq' = Get bandwidth at time... 1 time Hertz Linear
bw2'maxfreq' = Get bandwidth at time... 2 time Hertz Linear
bw'maxfreq' = bw1'maxfreq'+bw2'maxfreq'
if bw'maxfreq' < bw
bw = bw'maxfreq'
freq = maxfreq
endif
Remove
maxfreq = maxfreq + 100
select Sound 'file$'
endwhile
### Formant extraction - best candidate ###
To Formant (burg)... 0 5 freq 0.03 50
f1 = Get value at time... 1 time Hertz Linear
f2 = Get value at time... 2 time Hertz Linear
f3 = Get value at time... 3 time Hertz Linear
bw1 = Get bandwidth at time... 1 time Hertz Linear
bw2 = Get bandwidth at time... 2 time Hertz Linear
bw3 = Get bandwidth at time... 3 time Hertz Linear
Remove
### Formant extraction - default ###
select Sound 'file$'
To Formant (burg)... 0 5 defaultfreq 0.03 50
f1d = Get value at time... 1 time Hertz Linear
f2d = Get value at time... 2 time Hertz Linear
f3d = Get value at time... 3 time Hertz Linear
bw1d = Get bandwidth at time... 1 time Hertz Linear
bw2d = Get bandwidth at time... 2 time Hertz Linear
bw3d = Get bandwidth at time... 3 time Hertz Linear
Remove
select Sound 'file$'
Remove
### Printout ###
#fileappend L:\Korpus\vokaler\statistik\'file$'_'variable$'.csv 'file$';'year$';'decade$';'speaker$';'sex';'variable$';'preword$';'word$';'proword$';'preceeding$';'proceeding$';'voweltime:0';'freq';'bw1:0';'bw2:0';'bw3:0';'f1:0';'f2:0';'f3:0';'defaultfreq';'bw1d:0';'bw2d:0';'bw3d:0';'f1d:0';'f2d:0';'f3d:0''newline$'
fileappend L:\Korpus\vokaler\statistik\AllFiles.csv 'file$';'year$';'decade$';'speaker$';'sex$';'variable$';'preword$';'word$';'proword$';'preceeding$';'proceeding$';'voweltime:0';'freq';'bw1:0';'bw2:0';'bw3:0';'f1:0';'f2:0';'f3:0';'defaultfreq';'bw1d:0';'bw2d:0';'bw3d:0';'f1d:0';'f2d:0';'f3d:0''newline$'
endfor
select LongSound 'file$'
Remove
select TextGrid 'file$'
Remove
select TextGrid 'filename$'
Remove
endfor