summaryrefslogtreecommitdiff
path: root/lib/voices/finnish/suo_fi_lj_diphone/festvox/finnish_aux_funcs.scm
blob: 4215c0d1a98901a2e6ea2de06cf5fb618def24f0 (plain)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                                                                       ;;
;;;          Department of General Linguistics / Suopuhe project          ;;
;;;                      University of Helsinki, FI                       ;;
;;;                 Copyright (c) 2000, 2001, 2002, 2003                  ;;
;;;                        All Rights Reserved.                           ;;
;;;                                                                       ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                                                                       ;;
;;;  Authors:                                                             ;;
;;;                                                                       ;;
;;;          Martti Vainio                                                ;;
;;;  e-mail: martti.vainio@helsinki.fi                                    ;;
;;; address: Department of General Linguistics                           ;;
;;;          PL 9 (Siltavuorenpenger 20A)                                 ;;
;;;          00014 University of Helsinki                                 ;;
;;;          FINLAND                                                      ;;
;;;                                                                       ;;
;;;          Nicholas Volk                                                ;;
;;;  e-mail: nvolk@ling.helsinki.fi                                       ;;
;;; address: Department of General Linguistics                            ;;
;;;          PL 9 (Siltavuorenpenger 20A)                                 ;;
;;;          00014 University of Helsinki                                 ;;
;;;          FINLAND                                                      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Auxiliary functions for development work; nothing for end users here
;;; 



; This program is distributed under Gnu Lesser General Public License (cf. the
; file LICENSE in distribution).
 
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU Lesser General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
 
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU Lesser General Public License for more details.

(define (phones utt)
  "(phones UTT)
Prints a list of phone names in UTTerance and returns the original utterance
unchanged.."
  (print (utt.features utt 'Segment '(name)))
  utt)




(define (wavesurf utt)
  "(wavesurf UTT)
Saves the utterance UTT as a wav file 
and the creates the corresponding lab file.
The files are placed in the /tmp dir.
Then starts the wavesurfer-program for speech analysis."
;; WISH LIST:
;; 1) optinal file name
;; 2) optional path (compare with SUOPUHE-mode)
  (utt.save.wave utt "/tmp/xxx.wav" "wav")
  (system "chmod a+rw /tmp/xxx.wav") ;; I read&write, other just (over)write


  ;; create the .lab file
;  (let ((file "/tmp/xxx.lab" fp))
  (let ((file "/tmp/xxx.lab")
	fp)
    (set! fp (fopen file "w"))
    (fwrite
     (string-append
      "separator ;\n"
      "nfields 1\n"
      "#\n"  
      (lab_body (utt.relation.first utt 'Segment)))
     fp)
    (fclose fp))
  (system "chmod a+rw /tmp/xxx.lab")
  
  (system "wavesurfer -config WAVES /tmp/xxx.wav &")
  nil)


(define (extract_feats relname feats utt)
 "(extract_feats relname feats utt outfd)
Extract the features and write them to the screen."
  (mapcar
   (lambda (si)
     (mapcar 
      (lambda (f) 
        (format t  "%s " (item.feat si f)))
      feats)
     (format t "\n"))
   (utt.relation.items utt relname)))



;; NV's redefinition of SayText
(define (SayText text)
  "(SayText TEXT)
TEXT, a string, is rendered as speech. (Suopuhe redifinion)"
  (let ((utter (utt.synth (eval (list 'Utterance 'Text text)))))
    (if utter
	(utt.play utter)
	nil)))

	 








(define (lab_header UTT)
  "(lab_header UTT)
Returns the contents for the to-be *.lab file based on the UTTerance.
Saving the output to a file is done somewhere higher."
  (string-append
   "separator ;\n"
   "nfields 1\n"
   "#\n"
   (lab_body (utt.relation.first UTT 'Segment))))

(define (lab_body PHONE)
  "(lab_body PHONE)
Writes the LAB data for a given phone and recursively call
itself while there are phones left (ortographically right:).
The header is done in lab_header procedure which typically
is the caller of this function." 
  (string-append
   ;;(item.features (item.next PHONE)););)
   "\t"
   (item.feat PHONE "end")
   "\t121\t"
   (item.feat PHONE "name") 
   " ;\n"
   (if (item.next PHONE)
       (lab_body (item.next PHONE))
       "")))




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; UNUSED STUFF FROM OTHER DIRECTORIES
;; PLACED HERE SINCE NO BETTER PLACES CAME INTO MIND
(define (one_by_one word)
  "(one_by_one WORD)
Speaks the letters in the given WORD one by one."
  (let ((output "")
	(grapheme nil))
    (while (> (string-length word) 0)
	   (set! grapheme (substring word 0 1) ". ")
	   (cond
	    ((string-equal grapheme ".")
	     (set! output (string-append output "pisteel. ")))
	    ((string-equal grapheme ",")
	     (set! output (string-append output "pilkkuul. ")))
	    
	    (t
	     (set! output (string-append output grapheme ". "))))
	   (set! word (substring word 1 (- (string-length word) 1))))
    ;; (print output)
    (SayText output)))


;;; Martti did this functions. Dunno for what though...
; (define (remove_long_consonants utt)
; "(remove_long_consonants UTT)
; Remove long consonant markers (:) from the segment names"
;    (mapcar
;    (lambda (s)
;      (let ((name (item.name s)))
;        (if (and (string-equal "-" (item.feat s "ph_vc")) ;;; consonant
; 		(string-equal "l" (item.feat s "ph_len")))  ;;; long
; 	   (item.set_name s (substring name 0 1)))
;        ))
;    (utt.relation.items utt 'Segment))
;   utt)

; (define (klusiili phone)
;   (if (string-matches phone "^[bdgkpt]:?$" )
;       t
;       nil))

; (define (konsonantti phone)
;   (if (string-matches phone "^[bdfghjklmnprstvNT]:?$" )
;       t
;       nil))


; (define (lyhyt phone)
;   (if (string-matches phone "^[abdefghijklmnoprstuvy@7NT]$" )
;       t
;       nil))

; (define (nasaali phone)
;   (if (string-matches phone "^[mnN]:?$" )
;       t
;       nil))



; (define (pitka phone)
;   (if (string-matches phone "^[abdefghijklmnoprstuvy@7NT]:$" )
;       t
;       nil))

; (define (vokaali phone)
;   (if (string-matches phone "^[aeiouy@7]:?$" )
;       t
;       nil))


(define (intro-finnish)
  "(intro-finnish)
Synthesize an introduction to the Festival Speech Synthesis System
in Finnish."
  (if (or (string-equal "hy_fi_mv_diphone" current-voice)
	  (string-equal "suo_fi_lj_diphone" current-voice))
      (tts (path-append hy_fi_mv_dir "fi-intro.txt") nil)
      (format stderr "Please set the (hy_fi_mv_diphone) voice first")))


	       
(define (language_finnish)
  "(language_finnish)
Set up language parameters for Finnish."
  (set! male1 hy_fi_mv_diphone)
  (set! female1 suo_fi_lj_diphone)
  ;; LIS�� T�H�N MY�HEMM�N DIFONITIETOKANNAT...
  (set! language "finnish")
  (male1)
  (Parameter.set 'Language 'finnish)
)



;; alla olevaa kamaa k�ytettiin kestomallin opetukseen:

; (define (puhunnoksen_alku phone)
;   (cond
;    ;; on itse tauko
;    ((not (item.relation phone 'SylStructure))
;     0)
;    ;; edellinen on tauko
;    ((not (item.prev
; 	  (item.relation 
; 	   (item.parent
; 	    (item.parent
; 	     (item.relation phone 'SylStructure)))
; 	   'Word)))
;     1)
;    ((not (item.prev
; 	  (item.prev
; 	   (item.relation 
; 	    (item.parent
; 	     (item.parent
; 	      (item.relation phone 'SylStructure)))
; 	    'Word))))
;     2)
;    (t
;     0)))

; (define (puhunnoksen_loppu phone)
;   (cond
;    ;; on itse tauko
;    ((not (item.relation phone 'SylStructure))
;     0)
;    ;; seuraava on tauko
;    ((not (item.next
; 	  (item.relation 
; 	   (item.parent
; 	    (item.parent
; 	     (item.relation phone 'SylStructure)))
; 	   'Word)))
;     1)
;    ((not (item.next
; 	  (item.next
; 	   (item.relation 
; 	    (item.parent
; 	     (item.parent
; 	      (item.relation phone 'SylStructure)))
; 	    'Word))))
;     2)
;    (t
;     0)))

; (define (painotettu_eka_tavu phone)
;   (if (and (= (item.feat phone 'R:SylStructure.parent.pos_in_word) 0)
; 	   (not (string-equal (item.name phone) "#"))
; 	   (string-equal (item.feat phone 'R:SylStructure.parent.parent.gpos)
; 			 "content"))
;       (begin 
; ;;	(print (string-append (item.name phone) " 1")) 
; 	1)
;       (begin 
; ;;	(print (string-append (item.name phone) " 0")) 
; 	0)))

; (define (eka_tavu phone)
;   (if (and  (= (item.feat phone 'R:SylStructure.parent.pos_in_word) 0)
; 	    (not (string-equal (item.name phone) "#")))
;       (begin 
; ;;	(print (string-append (item.name phone) " 1")) 
; 	1)
;       (begin 
; ;;	(print (string-append (item.name phone) " 0")) 
; 	0)))




; (define (fraasin_alku phone)
;   (cond
;    ;; on itse tauko
;    ((or (not (item.relation phone 'SylStructure)))
;     0)
;    ;; seuraava on tauko
;    ((or 
; 	(not (item.prev
; 	      (item.relation 
; 	       (item.parent
; 		(item.parent
; 		 (item.relation phone 'SylStructure)))
; 	       'Word)))
; 	(string-matches (item.name
; 			 (item.prev
; 			  (item.relation
; 			   (item.first_leaf
; 			    (item.parent
; 			     (item.parent
; 			      (item.relation phone 'SylStructure))))
; 			   'Segment)))
; 			"^#+$"))
;     1)
;    ((or 
; 	(not (item.prev
; 	      (item.prev
; 	       (item.relation 
; 		(item.parent
; 		 (item.parent
; 		  (item.relation phone 'SylStructure)))
; 		'Word))))
; 	(string-matches (item.name
; 			 (item.prev
; 			  (item.relation
; 			   (item.first_leaf
; 			    (item.relation
; 			     (item.prev
; 			      (item.relation
; 			       (item.parent
; 				(item.parent
; 				 (item.relation phone 'SylStructure)))
; 			       'Word))
; 			     'SylStructure))
; 			   'Segment)))
; 			"^#+"))
;     2)
;    (t
;     0)))




;  (item.prev
;   (item.relation
;    (item.parent
;     (item.parent
;      (item.relation phone 
;		     'SylStructure)))
;    'Word)))



; (define (round number)
;   "(round number)
; Removes some \"extra\" decimals from floats...
; Keeps log decimals manageable..."
;   (let ((pos 1)
; 	(koko 0))
;     (if (< number 0)
; 	(begin 
; 	  (set! number (* -1 number))
; 	  (set! pos -1)))
   
;     (while (> number 1)
; 	   (set! koko (+ koko 1))
; 	   (set! number (- number 1)))
;     ;; (print pos) (print koko) (print number)
;     (* pos (+ koko (read-from-string (format nil "%.2f" number))))))

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(provide 'finnish_aux_funcs)