-
Notifications
You must be signed in to change notification settings - Fork 36
/
demo_formant_script.praat
68 lines (58 loc) · 2.27 KB
/
demo_formant_script.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
# Simple Formant Script!
#
# Will Styler, 5/24/14
# Written as a demo for a lecture on Praat Scripting for LING 7030: Phonetic Theory. Designed to provide a basis for creating other scripts.
#
# This part presents a form to the user
form Measure Formants and Duration
comment Sound file extension:
optionmenu file_type: 2
option .aiff
option .wav
endform
directory$ = chooseDirectory$ ("Choose the directory containing sound files and textgrids")
# This will need to be changed to \ below for PC users
directory$ = "'directory$'" + "/"
resultfile$ = "'directory$'"+"formantlog.txt"
header_row$ = "filename" + tab$ + "vowel" + tab$ + "Duration" + tab$ + "F1" + tab$ + "F2" + tab$ + "F3" + newline$
fileappend "'resultfile$'" 'header_row$'
# List of all the sound files in the specified directory:
Create Strings as file list... list 'directory$'*'file_type$'
number_files = Get number of strings
# This opens all the files one by one
for j from 1 to number_files
select Strings list
filename$ = Get string... 'j'
Read from file... 'directory$''filename$'
soundname$ = selected$ ("Sound")
filedur = Get total duration
# identify associated TextGrid
gridfile$ = "'directory$''soundname$'.TextGrid"
if fileReadable (gridfile$)
Read from file... 'gridfile$'
select TextGrid 'soundname$'
number_intervals = Get number of intervals... 1
# Go through each item
for k from 1 to number_intervals
select TextGrid 'soundname$'
int_label$ = Get label of interval... 1 'k'
#checks if interval has a label
if int_label$ <> ""
# Calc start, end, and duration of interval
intstart = Get starting point... 1 'k'
intend = Get end point... 1 'k'
intdur = intend - intstart
intmid = intstart + (intdur / 2)
# Get all the formants!
select Sound 'soundname$'
noprogress To Formant (burg)... 0 5 5500 0.025 50
intf1 = Get value at time... 1 'intmid' Hertz Linear
intf2 = Get value at time... 2 'intmid' Hertz Linear
intf3 = Get value at time... 3 'intmid' Hertz Linear
# Dump results into a file.
result_row$ = "'filename$'" + tab$ + "'int_label$'" + tab$ + "'intdur'" + tab$ + "'intf1'" + tab$ + "'intf2'" + tab$ + "'intf3'" + newline$
fileappend "'resultfile$'" 'result_row$'
endif
endfor
endif
endfor