Debian Codegraph @

test/fon/data.praat

raw
1 # data.praat
2 # Paul Boersma, 31 December 2025
3 # Checks Copy, Equal, Read, Save.
4
5 tracing$ = "no"
6
7 writeInfoLine: "Data test"
8 stopwatch
9
10 appendInfoLine: "Sound"
11 sound = Create Sound from formula: "kanweg", 1, 0, 1.2345, 44100, ~ 1/2 * sin(2*pi*377*x) + randomGauss (0, 0.1)
12 @test (sound)
13 Remove
14
15 appendInfoLine: "Pitch"
16 sound = Read from file: "test.wav"
17 pitch = To Pitch: 0, 75, 600
18 @test (pitch)
19
20 appendInfoLine: "Formant"
21 selectObject: sound
22 formant = To Formant (burg): 0, 5, 5000, 0.025, 50
23 @test (formant)
24
25 appendInfoLine: "Spectrogram"
26 selectObject: sound
27 spectrogram = To Spectrogram: 0.005, 5000.0, 0.002, 20.0, "gaussian"
28 @test (spectrogram)
29
30 appendInfoLine: "Cochleagram"
31 selectObject: sound
32 cochleagram = To Cochleagram: 0.01, 0.1, 0.03, 0.03
33 @test (cochleagram)
34
35 appendInfoLine: "MelSpectrogram"
36 selectObject: sound
37 melSpectrogram = To MelSpectrogram: 0.015, 0.005, 100.0, 100.0, 0.0
38 @test (melSpectrogram)
39
40 appendInfoLine: "BarkSpectrogram"
41 selectObject: sound
42 barkSpectrogram = To BarkSpectrogram: 0.015, 0.005, 1.0, 1.0, 0.0
43 @test (barkSpectrogram)
44
45 appendInfoLine: "PointProcess"
46 selectObject: sound, pitch
47 pulses = To PointProcess (cc)
48 @test (pulses)
49
50 appendInfoLine: "PitchTier"
51 pitchTier = To PitchTier: 0.02
52 @test (pitchTier)
53
54 appendInfoLine: "Manipulation"
55 selectObject: sound
56 manipulation = To Manipulation: 0.01, 75, 600
57 @test (manipulation)
58
59 appendInfoLine: "Matrix"
60 matrix = Create simple Matrix: "xy2", 10, 20, ~ x * y^2
61 @test (matrix)
62 Save as matrix text file: "kanweg.txt"
63 matrix2 = Read from file: "kanweg.txt"
64 assert objectsAreIdentical: matrix, matrix2
65 Remove
66 selectObject: matrix
67 Save as headerless spreadsheet file: "kanweg.txt"
68 matrix3 = Read Matrix from raw text file: "kanweg.txt"
69 assert objectsAreIdentical: matrix, matrix3
70 Remove
71
72 appendInfoLine: "Speaker"
73 speaker = Create Speaker: "man", "male", "2"
74 @test (speaker)
75
76 appendInfoLine: "OTGrammar"
77 grammar = Create metrics grammar: "equal", "FtNonfinal", "no", "no", "no", "Nonfinal", "yes", "no", "no"
78 @test (grammar)
79
80 appendInfoLine: "Table"
81 table = Create formant table (Peterson & Barney 1952)
82 @test (table)
83 Save as tab-separated file: "kanweg.txt"
84 table2 = Read Table from tab-separated file: "kanweg.txt"
85 assert objectsAreIdentical: table, table2
86 Remove
87 table3 = Read Table from tab-separated file: "kanweg.txt"
88 assert objectsAreIdentical: table, table3
89 Remove
90
91 appendInfoLine: "TableOfReal"
92 tableOfReal = Create TableOfReal (Pols 1973): "no"
93 @test (tableOfReal)
94 Save as headerless spreadsheet file: "kanweg.txt"
95 tableOfReal2 = Read TableOfReal from headerless spreadsheet file: "kanweg.txt"
96 assert objectsAreIdentical: tableOfReal, tableOfReal2
97 Remove
98
99 appendInfoLine: "EditDistanceTable"
100 intentionStrings = Create Strings as characters: "intention"
101 executionStrings = Create Strings as characters: "execution"
102 selectObject: intentionStrings, executionStrings
103 editDistanceTable = To EditDistanceTable
104 @test (editDistanceTable)
105 removeObject: intentionStrings, executionStrings
106
107 appendInfoLine: "FFNet"
108 Create iris example: 0, 0
109 ffnet = selected: "FFNet"
110 pattern = selected: "Pattern"
111 categories = selected: "Categories"
112 @test (ffnet)
113 @test (pattern)
114 @test (categories)
115
116 appendInfoLine: "Discriminant"
117 selectObject: pattern, categories
118 discriminant = To Discriminant
119 @test (discriminant)
120
121 appendInfoLine: "DTW"
122 selectObject: sound
123 soundCopy = Copy: "soundCopy"
124 plusObject: sound
125 dtw = To DTW: 0.015, 0.005, 0.1, "1/2 < slope < 2"
126 removeObject: soundCopy
127 @test (dtw)
128
129 appendInfoLine: "TextGrid"
130 textgrid = Create TextGrid: 0, 1, "tier", ""
131 Set interval text: 1, 1, "hup åçé pořád 𝄐𝄑 𐌀𐌁𐌂"
132 @test (textgrid)
133
134 appendInfoLine: "Network"
135 instar = 0.5
136 outstar = 0.5
137 weight_leak = 0
138 hasToBeWorkingAlways = 0
139 audf.numberOfNodes = if hasToBeWorkingAlways then 20 else 30 fi
140 sf.numberOfNodes = 10
141 inhibitionAtSF = if hasToBeWorkingAlways then -0.5 else -0.1 fi ; -0.2
142 shunting = if hasToBeWorkingAlways then 0 else 0.0 fi ; 0
143 net.spreadingRate = 0.01
144 net.activityLeak = 1
145 net.amin = 0
146 net.amax = 10
147 net.wmin = -10 ; minimum weight of a connection (negative to allow inhibition)
148 net.wmax = 10 ; maximum weight of a connection (positive to allow excitation)
149 net.learningRate = 0.01 ; how much do the connection weights change as a function of the product of the two activities?
150 net.xmin = 0 ; for drawing
151 net.xmax = 10 ; for drawing
152 net.ymin = 0 ; for drawing
153 net.ymax = 10 ; for drawing
154 net.initialWmin = 0
155 net.initialWmax = 0.1
156 audf.y = 4.0
157 sf.y = 9.0
158 audf.offsetNode = 0
159 sf.offsetNode = audf.offsetNode + audf.numberOfNodes
160 network = Create empty Network... integration
161 ... net.spreadingRate Linear net.amin net.amax net.activityLeak
162 ... net.learningRate net.wmin net.wmax weight_leak
163 ... net.xmin net.xmax net.ymin net.ymax
164 for .i to audf.numberOfNodes
165 Add node... net.xmin+(net.xmax-net.xmin)/audf.numberOfNodes*(.i-0.5) audf.y 0 yes
166 endfor
167 for .i to sf.numberOfNodes
168 Add node... net.xmin+(net.xmax-net.xmin)/sf.numberOfNodes*(.i-0.5) sf.y 0 no
169 endfor
170 for .i to audf.numberOfNodes
171 for .j to sf.numberOfNodes
172 Add connection... audf.offsetNode+.i sf.offsetNode+.j randomUniform(net.initialWmin,net.initialWmax) 1.0
173 endfor
174 endfor
175 for .i to sf.numberOfNodes - 1
176 for .j from .i + 1 to sf.numberOfNodes
177 Add connection... sf.offsetNode+.i sf.offsetNode+.j inhibitionAtSF 0.0
178 endfor
179 endfor
180 Set instar... instar
181 Set outstar... outstar
182 Set shunting... shunting
183 @test (network)
184
185 procedure selectAll ( )
186 selectObject: sound, pitch, formant, spectrogram, cochleagram, melSpectrogram, barkSpectrogram,
187 ... pulses, pitchTier, manipulation, matrix, speaker, grammar, table, tableOfReal, editDistanceTable,
188 ... ffnet, pattern, categories, discriminant, dtw, textgrid, network
189 endproc
190 procedure readCheckCollectionFile ( )
191 Read from file: "kanweg.Collection"
192 sound2 = selected: "Sound"
193 assert objectsAreIdentical: sound, sound2
194 pitch2 = selected: "Pitch"
195 assert objectsAreIdentical: pitch, pitch2
196 formant2 = selected: "Formant"
197 assert objectsAreIdentical: formant, formant2
198 spectrogram2 = selected: "Spectrogram"
199 assert objectsAreIdentical: spectrogram, spectrogram2
200 cochleagram2 = selected: "Cochleagram"
201 assert objectsAreIdentical: cochleagram, cochleagram2
202 melSpectrogram2 = selected: "MelSpectrogram"
203 assert objectsAreIdentical: melSpectrogram, melSpectrogram2
204 barkSpectrogram2 = selected: "BarkSpectrogram"
205 assert objectsAreIdentical: barkSpectrogram, barkSpectrogram2
206 pulses2 = selected: "PointProcess"
207 assert objectsAreIdentical: pulses, pulses2
208 pitchTier2 = selected: "PitchTier"
209 assert objectsAreIdentical: pitchTier, pitchTier2
210 manipulation2 = selected: "Manipulation"
211 assert objectsAreIdentical: manipulation, manipulation2
212 matrix2 = selected: "Matrix"
213 assert objectsAreIdentical: matrix, matrix2
214 speaker2 = selected: "Speaker"
215 assert objectsAreIdentical: speaker, speaker2
216 grammar2 = selected: "OTGrammar"
217 assert objectsAreIdentical: grammar, grammar2
218 table2 = selected: "Table"
219 assert objectsAreIdentical: table, table2
220 tableOfReal2 = selected: "TableOfReal"
221 assert objectsAreIdentical: tableOfReal, tableOfReal2
222 editDistanceTable2 = selected: "EditDistanceTable"
223 assert objectsAreIdentical: editDistanceTable, editDistanceTable2
224 ffnet2 = selected: "FFNet"
225 assert objectsAreIdentical: ffnet, ffnet2
226 pattern2 = selected: "Pattern"
227 assert objectsAreIdentical: pattern, pattern2
228 categories2 = selected: "Categories"
229 assert objectsAreIdentical: categories, categories2
230 discriminant2 = selected: "Discriminant"
231 assert objectsAreIdentical: discriminant, discriminant2
232 dtw2 = selected: "DTW"
233 assert objectsAreIdentical: dtw, dtw2
234 textgrid2 = selected: "TextGrid"
235 assert objectsAreIdentical: textgrid, textgrid2
236 network2 = selected: "Network"
237 assert objectsAreIdentical: network, network2
238 removeObject: sound2, pitch2, formant2,
239 ... spectrogram2, cochleagram2, melSpectrogram2, barkSpectrogram2,
240 ... pulses2, pitchTier2,
241 ... manipulation2, matrix2, speaker2, grammar2, table2, tableOfReal2, editDistanceTable2,
242 ... ffnet2, pattern2, categories2, discriminant2, dtw2, textgrid2, network2
243 endproc
244
245 appendInfoLine: "text Collection"
246 @selectAll ( )
247 Save as text file: "kanweg.Collection"
248 @readCheckCollectionFile ( )
249
250 appendInfoLine: "short text Collection"
251 @selectAll ( )
252 Save as short text file: "kanweg.Collection"
253 @readCheckCollectionFile ( )
254
255 appendInfoLine: "binary Collection"
256 @selectAll ( )
257 Save as binary file: "kanweg.Collection"
258 @readCheckCollectionFile ( )
259
260 removeObject: sound, pitch, formant,
261 ... spectrogram, cochleagram, melSpectrogram, barkSpectrogram,
262 ... pulses, pitchTier,
263 ... manipulation, matrix, speaker, grammar, table, tableOfReal, editDistanceTable,
264 ... ffnet, pattern, categories, discriminant, dtw, textgrid, network
265 deleteFile: "kanweg.Object"
266 deleteFile: "kanweg.Collection"
267
268 t = stopwatch
269 appendInfoLine: "OK (", fixed$ (t, 3), " seconds)"
270
271 procedure test (.object1)
272 selectObject: .object1
273 .object2 = Copy: "kanweg2"
274 assert objectsAreIdentical: .object1, .object2
275 Remove
276 selectObject: .object1
277 .object2 = Copy: "kanweg2"
278 assert objectsAreIdentical: .object1, .object2
279 Remove
280 # Test verbose Unicode text writing (for correct data).
281 selectObject: .object1
282 Save as text file: "kanweg.Object"
283 .object2 = Read from file: "kanweg.Object"
284 assert objectsAreIdentical: .object1, .object2 ; verbose Unicode write and read
285 Remove
286 # Test concise Unicode text writing (for correct data).
287 selectObject: .object1
288 Save as short text file: "kanweg.Object"
289 .object2 = Read from file: "kanweg.Object"
290 assert objectsAreIdentical: .object1, .object2 ; concise Unicode write and read
291 Remove
292 # Test binary writing.
293 selectObject: .object1
294 Save as binary file: "kanweg.Object"
295 .object2 = Read from file: "kanweg.Object"
296 assert objectsAreIdentical: .object1, .object2 ; binary write and read (1)
297 Remove
298 # Test binary writing.
299 selectObject: .object1
300 Save as binary file: "kanweg.Object"
301 Debug: tracing$, 18
302 .object2 = Read from file: "kanweg.Object"
303 Debug: tracing$, 0
304 assert objectsAreIdentical: .object1, .object2 ; binary write and read (2)
305 Remove
306 # Test binary writing.
307 selectObject: .object1
308 Debug: tracing$, 18
309 Save as binary file: "kanweg.Object"
310 Debug: tracing$, 0
311 .object2 = Read from file: "kanweg.Object"
312 assert objectsAreIdentical: .object1, .object2 ; binary write and read (3)
313 Remove
314 # Good neighbour.
315 selectObject: .object1
316 endproc