-
Notifications
You must be signed in to change notification settings - Fork 24
/
save_Finnish_tier_to_phoneme_string.praat
173 lines (155 loc) · 4.11 KB
/
save_Finnish_tier_to_phoneme_string.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# This script will convert the text in an orthographically labeled tier into Finnish
# phonemes and save the phonemes to a text file, one phoneme per line.
# Word boundaries will be marked as _ and utterance boundaries as __.
# Phoneme set is ABDEFGHIJKLMNOPRSTUVÄÖ or any of these doubled;
# NG is &
# (the above system correspond to the automatic segmentation tool in Helsinki University of Technology)
#
# Copyright 17.4.2002 Mietta Lennes
form Convert Finnish tier text to phonemes and save to text file
comment Which tier do you want to convert?
integer Tier 4
comment Where do you want to save the file?
sentence Folder ../../tmp/
endform
filename$ = selected$ ("TextGrid", 1)
folder$ = "'folder$'" + "'filename$'" + ".txt"
if fileReadable (folder$)
pause Overwrite old file 'folder$'?
endif
filedelete 'folder$'
numberOfIntervals = Get number of intervals... tier
for interval from 1 to numberOfIntervals
label$ = Get label of interval... tier interval
if label$ <> "" and label$ <> "xxx" and left$ (label$, 1) <> "."
for character from 1 to length (label$)
phoneme$ = right$ (left$ (label$, character), 1)
if character = length (label$)
if phoneme$ <> "-"
call ConvertToUppercase
phoneme$ = "'phoneme$''newline$'"
fileappend "'folder$'" 'phoneme$'
endif
phoneme$ = "__'newline$'"
fileappend "'folder$'" 'phoneme$'
elsif phoneme$ = " "
phoneme$ = "_'newline$'"
fileappend "'folder$'" 'phoneme$'
else
next = character + 1
nextphoneme$ = right$ (left$ (label$, next), 1)
if nextphoneme$ = " "
next = next + 1
if next <= length (label$)
nextphoneme$ = right$ (left$ (label$, next), 1)
if phoneme$ = "n"
if nextphoneme$ = "p"
phoneme$ = "M"
elsif nextphoneme$ = "k" or nextphoneme$ = "g"
phoneme$ = "&"
else
phoneme$ = "N"
endif
endif
if phoneme$ <> "-"
call ConvertToUppercase
fileappend "'folder$'" 'phoneme$''newline$'
endif
phoneme$ = "_'newline$'"
fileappend "'folder$'" 'phoneme$'
character = character + 1
else
call ConvertToUppercase
phoneme$ = "'phoneme$''newline$'"
phoneme$ = "'phoneme$'__'newline$'"
fileappend "'folder$'" 'phoneme$'
character = length (label$)
endif
elsif phoneme$ = "n"
if nextphoneme$ = "p"
phoneme$ = "M"
elsif nextphoneme$ = "k"
phoneme$ = "&"
elsif nextphoneme$ = "g"
phoneme$ = "&&"
character = character + 1
else
phoneme$ = "N"
endif
phoneme$ = phoneme$ + newline$
fileappend "'folder$'" 'phoneme$'
elsif phoneme$ = nextphoneme$
call ConvertToUppercase
phoneme$ = phoneme$ + phoneme$ + newline$
fileappend "'folder$'" 'phoneme$'
if next = length (label$)
phoneme$ = "__'newline$'"
fileappend "'folder$'" 'phoneme$'
character = length (label$)
else
character = character + 1
endif
elsif phoneme$ = " "
phoneme$ = "_'newline$'"
fileappend "'folder$'" 'phoneme$'
elsif phoneme$ = "-"
else
call ConvertToUppercase
phoneme$ = phoneme$ + newline$
fileappend "'folder$'" 'phoneme$'
endif
endif
endfor
endif
endfor
procedure ConvertToUppercase
if phoneme$ = "a"
phoneme$ = "A"
elsif phoneme$ = "b"
phoneme$ = "B"
elsif phoneme$ = "c"
phoneme$ = "C"
elsif phoneme$ = "d"
phoneme$ = "D"
elsif phoneme$ = "e"
phoneme$ = "E"
elsif phoneme$ = "f"
phoneme$ = "F"
elsif phoneme$ = "g"
phoneme$ = "G"
elsif phoneme$ = "h"
phoneme$ = "H"
elsif phoneme$ = "i"
phoneme$ = "I"
elsif phoneme$ = "j"
phoneme$ = "J"
elsif phoneme$ = "k"
phoneme$ = "K"
elsif phoneme$ = "l"
phoneme$ = "L"
elsif phoneme$ = "m"
phoneme$ = "M"
elsif phoneme$ = "n"
phoneme$ = "N"
elsif phoneme$ = "o"
phoneme$ = "O"
elsif phoneme$ = "p"
phoneme$ = "P"
elsif phoneme$ = "r"
phoneme$ = "R"
elsif phoneme$ = "s"
phoneme$ = "S"
elsif phoneme$ = "t"
phoneme$ = "T"
elsif phoneme$ = "u"
phoneme$ = "U"
elsif phoneme$ = "v"
phoneme$ = "V"
elsif phoneme$ = "y"
phoneme$ = "Y"
elsif phoneme$ = "ä"
phoneme$ = "Ä"
elsif phoneme$ = "ö"
phoneme$ = "Ö"
endif
endproc