-
Notifications
You must be signed in to change notification settings - Fork 24
/
collect_data_from_two_tiers_in_files.praat
140 lines (126 loc) · 5.23 KB
/
collect_data_from_two_tiers_in_files.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
134
135
136
137
138
139
140
# This script goes through sound and TextGrid files in a directory,
# opens each pair of Sound and TextGrid, calculates the duration
# of each labeled interval in the phone tier,
# the pitch maximum at the center of the phone, and
# the duration of the corresponding interval in the syllable tier,
# and then saves the results to a text file.
#
# To make some other or additional analyses, you can modify the script
# yourself... it should be reasonably well commented! ;)
#
# This script is distributed under the GNU General Public License.
# Copyright 25.11.2004 Mietta Lennes
form Analyze durations of phones and the corresponding syllables
comment Directory of sound files
text sound_directory /home/lennes/kysymykset/
sentence Sound_file_extension .aif
comment Directory of TextGrid files
text textGrid_directory /home/lennes/kysymykset/
sentence TextGrid_file_extension .TextGrid
comment Full path of the resulting text file:
text resultfile /home/lennes/kysymykset/pitchresults.txt
comment Which tier contains the speech sound segments?
sentence Phone_tier phone
comment Which tier contains the syllable segments?
sentence Syllable_tier syllable
comment Pitch analysis parameters
real Time_step 0.0 (=auto)
positive Minimum_pitch 75
positive Maximum_pitch 500
endform
# Here, you make a listing of all the sound files in a directory.
# The example gets file names ending with ".aif" from C:\kysymykset\
Create Strings as file list... list 'sound_directory$'*'sound_file_extension$'
numberOfFiles = Get number of strings
# Check if the result file exists:
if fileReadable (resultfile$)
pause The result file 'resultfile$' already exists! Do you want to overwrite it?
filedelete "'resultfile$'"
endif
# Write a row with column titles to the result file:
# (remember to edit this if you add or change the analyses!)
titleline$ = "Filename Preceding phone Phone label Starting point Phone duration Pitch max in phone Syllable label Syllable duration'newline$'"
fileappend "'resultfile$'" 'titleline$'
# Go through all the sound files, one by one:
for ifile to numberOfFiles
filename$ = Get string... ifile
# A sound file is opened from the listing:
Read from file... 'sound_directory$''filename$'
# Starting from here, you can add everything that should be
# repeated for every sound file that was opened:
soundname$ = selected$ ("Sound", 1)
# Open a TextGrid by the same name:
gridfile$ = "'textGrid_directory$''soundname$''textGrid_file_extension$'"
if fileReadable (gridfile$)
Read from file... 'gridfile$'
# Find the tier number that has the label given in the form:
call GetTier 'phone_tier$' phone_tier
call GetTier 'syllable_tier$' syllable_tier
if phone_tier > 0 and syllable_tier > 0
numberOfIntervals = Get number of intervals... phone_tier
preceding_label$ = ""
select Sound 'soundname$'
To Pitch... time_step minimum_pitch maximum_pitch
select TextGrid 'soundname$'
# Pass through all intervals in the selected phone tier:
for interval to numberOfIntervals
label$ = Get label of interval... phone_tier interval
if label$ <> ""
# if the interval has an unempty label, get its start and end:
start = Get starting point... phone_tier interval
end = Get end point... phone_tier interval
# get the duration of the phone segment
phonedur = end - start
# get the time at the middle of the phone:
phonecenter = (start + end) / 2
select Pitch 'soundname$'
pitchmax = Get maximum... start end Hertz Parabolic
select TextGrid 'soundname$'
# get the syllable interval number at the phone center:
syllable = Get interval at time... syllable_tier phonecenter
# get the label of that syllable:
syllable_label$ = Get label of interval... syllable_tier syllable
syllstart = Get starting point... syllable_tier syllable
syllend = Get end point... syllable_tier syllable
# get the duration of the syllable segment:
syllabledur = syllend - syllstart
# Save result to text file:
resultline$ = "'soundname$' 'preceding_label$' 'label$' 'start' 'phonedur' 'pitchmax' 'syllable_label$' 'syllabledur''newline$'"
fileappend "'resultfile$'" 'resultline$'
select TextGrid 'soundname$'
endif
preceding_label$ = label$
endfor
# Remove the Pitch object
select Pitch 'soundname$'
Remove
endif
# Remove the TextGrid object from the object list
select TextGrid 'soundname$'
Remove
endif
# Remove the sound object from the object list
select Sound 'soundname$'
Remove
select Strings list
# and go on with the next sound file!
endfor
Remove
#-------------
# This procedure finds the number of a tier that has a given label.
procedure GetTier name$ variable$
numberOfTiers = Get number of tiers
itier = 1
repeat
tier$ = Get tier name... itier
itier = itier + 1
until tier$ = name$ or itier > numberOfTiers
if tier$ <> name$
'variable$' = 0
else
'variable$' = itier - 1
endif
if 'variable$' = 0
printline The tier called 'name$' is missing from the file 'soundname$'!
endif
endproc