-
Notifications
You must be signed in to change notification settings - Fork 24
/
save_tier_text_to_file.praat
76 lines (51 loc) · 1.74 KB
/
save_tier_text_to_file.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
form Write tier text to text file
comment Which tier do you want to write out?
integer Tier 1
comment Where do you want to save the file?
sentence Folder /home/lennes/read_text/
comment Criterion to be fulfilled:
sentence Criterion_text ok
integer In_tier 3
endform
filename$ = selected$ ("TextGrid", 1)
folder$ = "'folder$'" + "'filename$'" + ".txt"
numberOfIntervals = Get number of intervals... tier
for interval from 1 to numberOfIntervals
line$ = ""
line$ = Get label of interval... tier interval
call FulfilsCriterion tier interval in_tier 'criterion_text$'
if line$ <> "" and left$ (line$, 1) <> "." and line$ <> "xxx" and fulfils = 1
# add this to the end of the previous line to exclude .-beginning labels:
# and left$ (line$, 1) <> "."
line$ = "'line$'" + "'newline$'"
fileappend "'folder$'" 'line$'
endif
line$ = ""
endfor
#------------------------
procedure FulfilsCriterion sel_tier sel_interval crittier crittext$
in_interval = 0
if crittier <> 0
tempstart1 = Get starting point... sel_tier sel_interval
tempend1 = Get end point... sel_tier sel_interval
midtime1 = (tempstart1 + tempend1) / 2
tempcriterion = Get interval at time... crittier midtime1
tempstart2 = Get starting point... crittier tempcriterion
tempend2 = Get end point... crittier tempcriterion
temp_label2$ = Get label of interval... crittier tempcriterion
# if criterion text is empty, any interval label other than "" will be accepted
if crittext$ = "" and temp_label2$ <> ""
crittext$ = temp_label2$
endif
if tempstart2 <= tempstart1 and tempend2 >= tempend1
in_interval = tempcriterion
endif
if temp_label2$ = crittext$ and tempstart2 <= tempstart1 and tempend2 >= tempend1
fulfils = 1
else
fulfils = 0
endif
else
fulfils = 1
endif
endproc