-
Notifications
You must be signed in to change notification settings - Fork 6
/
lexconvert.py
executable file
·3731 lines (3623 loc) · 204 KB
/
lexconvert.py
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# May be run with either Python 2 or Python 3
"""lexconvert v0.42 - convert phonemes between English speech synthesizers etc
(c) 2007-24 Silas S. Brown. License: Apache 2"""
# Run without arguments for usage information
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Old versions of this code are being kept in the E-GuideDog SVN repository at
# http://svn.code.sf.net/p/e-guidedog/code/ssb22/lexconvert
# and on GitHub at https://github.com/ssb22/lexconvert
# and on GitLab at https://gitlab.com/ssb22/lexconvert
# and on Bitbucket https://bitbucket.org/ssb22/lexconvert
# and at https://gitlab.developers.cam.ac.uk/ssb22/lexconvert
# and in China: https://gitee.com/ssb22/lexconvert
# although some early ones are missing.
def Phonemes():
"""Create phonemes by calling vowel(), consonant(),
variant() and other().
For the variants, if a particular variant does not
exist in the destination format then we will treat it
as equivalent to the last non-variant we created.
For anything else that does not exist in the
destination format, we will first try to break the
source's phoneme into parts (e.g. see the treatment
of opt_ol_as_in_gold by eSpeak and bbcmicro), and if
that still doesn't work then we drop a character
(warning depending on the source format's setting of
safe_to_drop_characters). makeDic does however warn
about any non-variant consonants, or non-variant
vowels that weren't marked optional, missing from a
format. """
a_as_in_ah = vowel()
_, var1_a_as_in_ah = variant()
_, var3_a_as_in_ah = variant()
_, var4_a_as_in_ah = variant()
_, var5_a_as_in_ah = variant()
a_as_in_apple = vowel()
_, var1_a_as_in_apple = variant()
u_as_in_but = vowel() # or the first part of un as in hunt
_, var1_u_as_in_but = variant()
o_as_in_orange = vowel()
_, var1_o_as_in_orange = variant()
_, var2_o_as_in_orange = variant()
o_as_in_now = vowel()
_, var1_o_as_in_now = variant()
a_as_in_ago = vowel()
_, var1_a_as_in_ago = variant()
e_as_in_herd = vowel()
_, ar_as_in_year = variant()
eye = vowel()
_, var1_eye = variant()
b = consonant()
ch = consonant()
d = consonant()
th_as_in_them = consonant()
e_as_in_them = vowel()
_, var1_e_as_in_them = variant()
a_as_in_air = vowel()
_, var1_a_as_in_air = variant()
_, var2_a_as_in_air = variant()
_, var3_a_as_in_air = variant()
_, var4_a_as_in_air = variant()
a_as_in_ate = vowel()
_, var1_a_as_in_ate = variant()
f = consonant()
g = consonant()
h = consonant()
i_as_in_it = vowel()
_, var1_i_as_in_it = variant()
_, var2_i_as_in_it = variant()
ear = vowel()
_, var1_ear = variant()
_, var2_ear = variant()
e_as_in_eat = vowel()
_, var1_e_as_in_eat = variant()
j_as_in_jump = consonant()
k = consonant()
_, opt_scottish_loch = variant()
l = consonant()
_, var1_l = variant()
m = consonant()
n = consonant()
ng = consonant()
o_as_in_go = vowel()
_, var1_o_as_in_go = variant()
_, var2_o_as_in_go = variant()
opt_ol_as_in_gold = opt_vowel() # see eSpeak / bbcmicro
oy_as_in_toy = vowel()
_, var1_oy_as_in_toy = variant()
p = consonant()
r = consonant()
_, var1_r = variant()
s = consonant()
sh = consonant()
t = consonant()
_, var1_t = variant()
th_as_in_think = consonant()
oor_as_in_poor = vowel()
_, var1_oor_as_in_poor = variant()
_, opt_u_as_in_pull = variant()
opt_ul_as_in_pull = opt_vowel() # see eSpeak / bbcmicro
oo_as_in_food = vowel()
_, var1_oo_as_in_food = variant()
_, var2_oo_as_in_food = variant()
close_to_or = vowel()
_, var1_close_to_or = variant()
_, var2_close_to_or = variant()
_, var3_close_to_or = variant()
v = consonant()
w = consonant()
_, var1_w = variant()
y = consonant()
z = consonant()
ge_of_blige_etc = consonant()
glottal_stop = other()
syllable_separator = other()
_, primary_stress = variant()
_, secondary_stress = variant()
text_sharp = other()
text_underline = other()
text_question = other()
text_exclamation = other()
text_comma = other()
ipa_colon = other() # for catching missed cases
del _ ; return locals()
def LexFormats():
"""Makes the phoneme conversion tables of each format.
Each table has string to phoneme entries and phoneme
to string entries. The string to phoneme entries are
used when converting OUT of that format, and the
phoneme to string entries are used when converting IN
(so you can recognise phonemes you don't support and
convert them to something else). By default, a tuple
of the form (string,phoneme) will create entries in
BOTH directions; one-directional entries are created
via (string,phoneme,False) or (phoneme,string,False).
The makeDic function checks the keys are unique.
First parameter is always a description of the
format, then come the phoneme entries as described
above, then any additional settings:
stress_comes_before_vowel (default False means any
stress mark goes AFTER the affected vowel; set to
True if the format requires stress placed before)
word_separator (default same as phoneme_separator)
phoneme_separator (default " ")
clause_separator (default newline)
(For a special case, clause_separator can also be
set to a function. If that happens, the function
will be called whenever lexconvert needs to output
a list of (lists of words) in this format. See
bbcmicro for an example function clause_separator)
safe_to_drop_characters (default False, can be a
string of safe characters or True = all; controls
warnings when unrecognised characters are found)
approximate_missing (default False) - if True,
makeDic will attempt to compensate for missing
phonemes by approximating them to others, instead of
warning about them. This is useful for American codes
that can't cope with all the British English phonemes.
(Approximation is done automatically anyway in the
case of variant phonemes; approximate_missing adds in
some additional approximations - see comments in code)
cleanup_regexps (default none) - optional list of
(search,replace) regular expressions to "clean up"
after converting each word INTO this format
cleanup_func (default none) - optional special-case
function to pass result through after cleanup_regexps
cvtOut_regexps (default none) - optional list of
(search,replace) regular expressions to "clean up"
before starting to convert OUT of this format
cvtOut_func (default none) - optional special-case
function to pass through before any cvtOut_regexps
inline_format (default "%s") the format string for
printing a word with --phones or --phones2phones
(can be used to put markup around each word)
(can also be a function taking the phonetic word
and returning the resulting string, e.g. bbcmicro)
output_is_binary (default False) - True if the output
is almost certainly unsuitable for a terminal; will
cause lexconvert to refuse to print phonemes unless
its standard output is redirected to a file or pipe
(affects the --phones and --phones2phones options)
inline_header (default none) text to print first
when outputting from --phones or --phones2phones
inline_footer (default none) text to print last
inline_oneoff_header (default none) text to print
before inline_header on the first time only
lex_filename - filename of a lexicon file. If this
is not specified, there is no support for writing a
lexicon in this format: there can still be READ
support if you define lex_read_function to open the
lexicon by itself, but otherwise the format can be
used only with --phones and --phones2phones.
lex_entry_format - format string for writing each
(word, pronunciation) entry to the lexicon file.
This is also needed for lexicon-write support.
lex_header, lex_footer - optional strings to write
at the beginning and at the end of the lexicon file
(can also be functions that take the open file as a
parameter, e.g. for bbcmicro; lex_footer is
allowed to close the file if it needs to do
something with it afterwards)
lex_word_case - optional "upper" or "lower" to
force a particular case for lexicon words (not
pronunciations - they're determined by the table).
The default is to allow words to be in either case.
lex_type (default "") - used by the --formats
option when summarising the support for each format
lex_read_function - Python function to READ the
lexicon file and return a (word,phonemes) list.
If this is not specified, there's no read support
for lexicons in this format (but there can still be
write support - see above - and you can still use
--phones and --phones2phones). If lex_filename is
specified then this function will be given the open
file as a parameter. """
phonemes = Phonemes() ; globals().update(phonemes)
return { "festival" : makeDic(
"Festival's British voice",
('0',syllable_separator),
('1',primary_stress),
('2',secondary_stress),
('aa',a_as_in_ah),
('a',a_as_in_apple),
('uh',u_as_in_but),
('o',o_as_in_orange),
('au',o_as_in_now),
('@',a_as_in_ago),
('@@',e_as_in_herd),
('ai',eye),
('b',b),
('ch',ch),
('d',d),
('dh',th_as_in_them),
('e',e_as_in_them),
(ar_as_in_year,'@@',False),
('e@',a_as_in_air),
('ei',a_as_in_ate),
('f',f),
('g',g),
('h',h),
('i',i_as_in_it),
('i@',ear),
('ii',e_as_in_eat),
('jh',j_as_in_jump),
('k',k),
('l',l),
('m',m),
('n',n),
('ng',ng),
('ou',o_as_in_go),
('oi',oy_as_in_toy),
('p',p),
('r',r),
('s',s),
('sh',sh),
('t',t),
('th',th_as_in_think),
('u@',oor_as_in_poor),
('u',opt_u_as_in_pull),
('uu',oo_as_in_food),
('oo',close_to_or),
('v',v),
('w',w),
('y',y),
('z',z),
('zh',ge_of_blige_etc),
lex_filename=ifset("HOME",os.environ.get("HOME","")+os.sep)+".festivalrc",
lex_entry_format="(lex.add.entry '( \"%s\" n %s))\n",
lex_header=";; -*- mode: lisp -*-\n(eval (list voice_default))\n",
lex_read_function = lambda *args:eval('['+getoutput("grep -vi parameter.set < ~/.festivalrc | grep -v '(eval' | sed -e 's/;.*//' -e 's/.lex.add.entry//' -e s/\"'\"'[(] *\"/[\"/' -e 's/\" [^ ]* /\",(\"/' -e 's/\".*$/&\"],/' -e 's/[()]/ /g' -e 's/ */ /g'")+']'),
safe_to_drop_characters=True, # TODO: really? (could instead give a string of known-safe characters)
cleanup_func = festival_group_stress,
),
"example" : makeVariantDic(
"A small built-in example lexicon for testing when you don't have your full custom lexicon to hand. Use --convert to write it in one of the other formats and see if a synth can import it.",
lex_read_function = lambda *args: [
("Shadrach","shei1drak"),
("Meshach","mii1shak"),
("Abednego","@be1dniigou"),
], cleanup_func = None,
lex_filename=None, lex_entry_format=None, noInherit=True),
"festival-cmu" : makeVariantDic(
"American CMU version of Festival",
('ae',a_as_in_apple),
('ah',u_as_in_but),
('ax',a_as_in_ago),
(o_as_in_orange,'aa',False),
('aw',o_as_in_now),
('er',e_as_in_herd), # TODO: check this one
('ay',eye),
('eh',e_as_in_them),
(ar_as_in_year,'er',False),
(a_as_in_air,'er',False),
('ey',a_as_in_ate),
('hh',h),
('ih',i_as_in_it),
('ey ah',ear),
('iy',e_as_in_eat),
('ow',o_as_in_go),
('oy',oy_as_in_toy),
('uh',oor_as_in_poor),
('uw',oo_as_in_food),
('ao',close_to_or),
),
"espeak" : makeDic(
"eSpeak's default British voice", # but eSpeak's phoneme representation isn't always that simple, hence the regexps at the end
('%',syllable_separator),
("'",primary_stress),
(',',secondary_stress),
# TODO: glottal_stop? (in regional pronunciations etc)
('A:',a_as_in_ah),
('A@',a_as_in_ah,False),
('A',var1_a_as_in_ah),
('a',a_as_in_apple),
('aa',a_as_in_apple,False),
('a2',a_as_in_apple,False), # TODO: this is actually an a_as_in_apple variant in espeak; festival @1 is not in mrpa PhoneSet
('&',a_as_in_apple,False),
('V',u_as_in_but),
('0',o_as_in_orange),
('aU',o_as_in_now),
('@',a_as_in_ago),
('a#',a_as_in_ago,False), # (TODO: eSpeak sometimes uses a# in 'had' when in a sentence, and this doesn't always sound good on other synths; might sometimes want to convert it to a_as_in_apple; not sure what contexts would call for this though)
('3:',e_as_in_herd),
('3',var1_a_as_in_ago),
('@2',a_as_in_ago,False),
('@-',a_as_in_ago,False), # (eSpeak @- sounds to me like a shorter version of @, TODO: double-check the relationship between @ and @2 in Festival)
('aI',eye),
('aI2',eye,False),
('aI;',eye,False),
('aI2;',eye,False),
('b',b),
('tS',ch),
('d',d),
('D',th_as_in_them),
('E',e_as_in_them),
(ar_as_in_year,'3:',False),
('e@',a_as_in_air),
('eI',a_as_in_ate),
('f',f),
('g',g),
('h',h),
('I',i_as_in_it),
('I;',i_as_in_it,False),
('i',i_as_in_it,False),
('I2',var2_i_as_in_it,False),
('I2;',var2_i_as_in_it,False),
('i@',ear),
('i@3',var2_ear),
('i:',e_as_in_eat),
('i:;',e_as_in_eat,False),
('dZ',j_as_in_jump),
('k',k),
('x',opt_scottish_loch),
('l',l),
('L',l,False),
('m',m),
('n',n),
('N',ng),
('oU',o_as_in_go),
('oUl',opt_ol_as_in_gold), # (espeak says "gold" in a slightly 'posh' way though) (if dest format doesn't have opt_ol_as_in_gold, it'll get o_as_in_go + the l)
('OI',oy_as_in_toy),
('p',p),
('r',r),
('r-',r,False),
('s',s),
('S',sh),
('t',t),
('T',th_as_in_think),
('U@',oor_as_in_poor),
('U',opt_u_as_in_pull),
('@5',opt_u_as_in_pull,False),
('Ul',opt_ul_as_in_pull), # if dest format doesn't have this, it'll get opt_u_as_in_pull from the U, then the l
('u:',oo_as_in_food),
('O:',close_to_or),
('O@',var3_close_to_or),
('o@',var3_close_to_or,False),
('O',var3_close_to_or,False),
('v',v),
('w',w),
('j',y),
('z',z),
('Z',ge_of_blige_etc),
lex_filename = "en_extra",
lex_entry_format = "%s %s\n",
lex_read_function = lambda lexfile: [x for x in [l.split()[:2] for l in lexfile.readlines()] if len(x)==2 and not '//' in x[0]],
lex_footer=lambda f:(f.close(),os.system("espeak --compile=en")), # see also a bit of special-case code in mainopt_convert
inline_format = "[[%s]]",
word_separator=" ",phoneme_separator="",
stress_comes_before_vowel=True,
safe_to_drop_characters="_: !",
cleanup_regexps=[
("k'a2n","k'@n"),
("ka2n","k@n"),
("gg","g"),
("@U","oU"), # (eSpeak uses oU to represent @U; difference is given by its accent parameters)
("([iU]|([AO]:))@r$","\1@"),
("([^e])@r",r"\1_remove_3"),("_remove_",""),
# (r"([^iU]@)l",r"\1L") # only in older versions of espeak (not valid in more recent versions)
("rr$","r"),
("3:r$","3:"),
("%%+","%"),("^%",""),("%$",""),
# TODO: 'declared' & 'declare' the 'r' after the 'E' sounds a bit 'regional' (but pretty). but sounds incomplete w/out 'r', and there doesn't seem to be an E2 or E@
# TODO: consider adding 'g' to words ending in 'N' (if want the 'g' pronounced in '-ng' words) (however, careful of words like 'yankee' where the 'g' would be followed by a 'k'; this may also be a problem going into the next word)
],
cvtOut_regexps = [
("e@r$","e@"), ("e@r([bdDfghklmnNprsStTvwjzZ])",r"e@\1"), # because the 'r' is implicit in other synths (but DO have it if there's another vowel to follow)
],
),
"sapi" : makeDic(
"Microsoft Speech API (American English)",
('-',syllable_separator),
('1',primary_stress),
('2',secondary_stress),
('aa',a_as_in_ah),
('ae',a_as_in_apple),
('ah',u_as_in_but),
('ao',o_as_in_orange),
('aw',o_as_in_now),
('ax',a_as_in_ago),
('er',e_as_in_herd),
('ay',eye),
('b',b),
('ch',ch),
('d',d),
('dh',th_as_in_them),
('eh',e_as_in_them),
('ey',var1_e_as_in_them),
(a_as_in_ate,'ey',False),
('f',f),
('g',g),
('h',h), # Jan suggested 'hh', but I can't get this to work on Windows XP (TODO: try newer versions of Windows)
('ih',i_as_in_it),
('iy',e_as_in_eat),
('jh',j_as_in_jump),
('k',k),
('l',l),
('m',m),
('n',n),
('ng',ng),
('ow',o_as_in_go),
('oy',oy_as_in_toy),
('p',p),
('r',r),
('s',s),
('sh',sh),
('t',t),
('th',th_as_in_think),
('uh',oor_as_in_poor),
('uw',oo_as_in_food),
('AO',close_to_or),
('v',v),
('w',w),
# ('x',var1_w), # suggested by Jan, but I can't get this to work on Windows XP (TODO: try newer versions of Windows)
('y',y),
('z',z),
('zh',ge_of_blige_etc),
approximate_missing=True,
lex_filename="run-ptts.bat", # write-only for now
lex_header = "rem You have to run this file\nrem with ptts.exe in the same directory\nrem to add these words to the SAPI lexicon\n\n",
lex_entry_format='ptts -la %s "%s"\n',
inline_format = '<pron sym="%s"/>',
safe_to_drop_characters=True, # TODO: really?
),
"cepstral" : makeDic(
"Cepstral's British English SSML phoneset",
('0',syllable_separator),
('1',primary_stress),
('a',a_as_in_ah),
('ae',a_as_in_apple),
('ah',u_as_in_but),
('oa',o_as_in_orange),
('aw',o_as_in_now),
('er',e_as_in_herd),
('ay',eye),
('b',b),
('ch',ch),
('d',d),
('dh',th_as_in_them),
('eh',e_as_in_them),
('e@',a_as_in_air),
('ey',a_as_in_ate),
('f',f),
('g',g),
('h',h),
('ih',i_as_in_it),
('i',e_as_in_eat),
('jh',j_as_in_jump),
('k',k),
('l',l),
('m',m),
('n',n),
('ng',ng),
('ow',o_as_in_go),
('oy',oy_as_in_toy),
('p',p),
('r',r),
('s',s),
('sh',sh),
('t',t),
('th',th_as_in_think),
('uh',oor_as_in_poor),
('uw',oo_as_in_food),
('ao',close_to_or),
('v',v),
('w',w),
('j',y),
('z',z),
('zh',ge_of_blige_etc),
approximate_missing=True,
lex_filename="lexicon.txt",
lex_entry_format = "%s 0 %s\n",
lex_read_function = lambda lexfile: [(word,pronunc) for word, ignore, pronunc in [l.split(None,2) for l in lexfile.readlines()]],
lex_word_case = "lower",
inline_format = "<phoneme ph='%s'>p</phoneme>",
safe_to_drop_characters=True, # TODO: really?
cleanup_regexps=[(" 1","1"),(" 0","0")],
),
"mac" : makeDic(
"approximation in American English using the [[inpt PHON]] notation of Apple's US voices",
('=',syllable_separator),
('1',primary_stress),
('2',secondary_stress),
('AA',a_as_in_ah),
('aa',var5_a_as_in_ah),
('AE',a_as_in_apple),
('UX',u_as_in_but),
(o_as_in_orange,'AA',False),
('AW',o_as_in_now),
('AX',a_as_in_ago),
(e_as_in_herd,'AX',False), # TODO: is this really the best approximation?
('AY',eye),
('b',b),
('C',ch),
('d',d),
('D',th_as_in_them),
('EH',e_as_in_them),
('EY',a_as_in_ate),
('f',f),
('g',g),
('h',h),
('IH',i_as_in_it),
('IX',var2_i_as_in_it),
('IY',e_as_in_eat),
('J',j_as_in_jump),
('k',k),
('l',l),
('m',m),
('n',n),
('N',ng),
('OW',o_as_in_go),
('OY',oy_as_in_toy),
('p',p),
('r',r),
('s',s),
('S',sh),
('t',t),
('T',th_as_in_think),
('UH',oor_as_in_poor),
('UW',oo_as_in_food),
('AO',close_to_or),
('v',v),
('w',w),
('y',y),
('z',z),
('Z',ge_of_blige_etc),
approximate_missing=True,
lex_filename="substitute.sh", # write-only for now
lex_type = "substitution script",
lex_header = "#!/bin/bash\n\n# I don't yet know how to add to the Apple US lexicon,\n# so here is a 'sed' command you can run on your text\n# to put the pronunciation inline:\n\nsed -E -e :S \\\n",
lex_entry_format=r" -e 's/(^|[^A-Za-z])%s($|[^A-Za-z[12=])/\1[[inpt PHON]]%s[[inpt TEXT]]\2/g'"+" \\\n",
# but /g is non-overlapping matches and won't catch 2 words in the lex right next to each other with only one non-alpha in between, so we put :S at start and tS at end to make the whole operation repeat until it hasn't done any more substitutions (hence also the exclusion of [, 1, 2 or = following a word so it doesn't try to substitute stuff inside the phonemes; TODO: assert the lexicon does not contain "inpt", "PHON" or "TEXT")
lex_footer = lambda f:(f.write(" -e tS\n"),f.close(),os.chmod("substitute.sh",493)), # 493 = 0755, but no way to specify octal that works on both Python 2.5 and Python 3 (0o works on 2.6+)
inline_format = "[[inpt PHON]]%s[[inpt TEXT]]",
word_separator=" ",phoneme_separator="",
safe_to_drop_characters=True, # TODO: really?
),
"mac-uk" : makeDic(
"Scansoft/Nuance British voices in Mac OS 10.7+ (system lexicon editing required, see --mac-uk option)",
('.',syllable_separator),
("'",primary_stress),
(secondary_stress,'',False),
('A',a_as_in_ah),
('@',a_as_in_apple),
('$',u_as_in_but),
(a_as_in_ago,'$',False),
('A+',o_as_in_orange),
('a&U',o_as_in_now),
('E0',e_as_in_herd),
('a&I',eye),
('b',b),
('t&S',ch),
('d',d),
('D',th_as_in_them),
('E',e_as_in_them),
('0',ar_as_in_year),
('E&$',a_as_in_air),
('e&I',a_as_in_ate),
('f',f),
('g',g),
('h',h),
('I',i_as_in_it),
('I&$',ear),
('i',e_as_in_eat),
('d&Z',j_as_in_jump),
('k',k),
('l',l),
('m',m),
('n',n),
('nK',ng),
('o&U',o_as_in_go),
('O&I',oy_as_in_toy),
('p',p),
('R+',r),
('s',s),
('S',sh),
('t',t),
('T',th_as_in_think),
('O',oor_as_in_poor),
('U',opt_u_as_in_pull),
('u',oo_as_in_food),
(close_to_or,'O',False),
('v',v),
('w',w),
('j',y),
('z',z),
('Z',ge_of_blige_etc),
# lex_filename not set (mac-uk code does not permanently save the lexicon; see --mac-uk option to read text)
lex_read_function = lambda *args:[(w,p) for w,_,p in MacBritish_System_Lexicon(False,os.environ.get("MACUK_VOICE","Daniel")).usable_words()],
inline_oneoff_header = "(mac-uk phonemes output is for information only; you'll need the --mac-uk or --trymac-uk options to use it)\n",
word_separator=" ",phoneme_separator="",
stress_comes_before_vowel=True,
safe_to_drop_characters=True, # TODO: really?
cleanup_regexps=[(r'o\&U\.Ol', r'o\&Ul')],
),
"x-sampa" : makeDic(
"General X-SAMPA notation, contributed by Jan Weiss",
('.',syllable_separator),
('"',primary_stress),
('%',secondary_stress),
('A',a_as_in_ah),
(':',ipa_colon),
('A:',var3_a_as_in_ah),
('Ar\\',var4_a_as_in_ah),
('a:',var5_a_as_in_ah),
('{',a_as_in_apple),
('V',u_as_in_but),
('Q',o_as_in_orange),
(var1_o_as_in_orange,'A',False),
('O',var2_o_as_in_orange),
('aU',o_as_in_now),
('{O',var1_o_as_in_now),
('@',a_as_in_ago),
('3:',e_as_in_herd),
('aI',eye),
('Ae',var1_eye),
('b',b),
('tS',ch),
('d',d),
('D',th_as_in_them),
('E',e_as_in_them),
('e',var1_e_as_in_them),
(ar_as_in_year,'3:',False),
('E@',a_as_in_air),
('Er\\',var1_a_as_in_air),
('e:',var2_a_as_in_air),
('E:',var3_a_as_in_air),
('e@',var4_a_as_in_air),
('eI',a_as_in_ate),
('{I',var1_a_as_in_ate),
('f',f),
('g',g),
('h',h),
('I',i_as_in_it),
('1',var1_i_as_in_it),
('I@',ear),
('Ir\\',var1_ear),
('i',e_as_in_eat),
('i:',var1_e_as_in_eat),
('dZ',j_as_in_jump),
('k',k),
('x',opt_scottish_loch),
('l',l),
('m',m),
('n',n),
('N',ng),
('@U',o_as_in_go),
('oU',var2_o_as_in_go),
('@}',var1_u_as_in_but),
('OI',oy_as_in_toy),
('oI',var1_oy_as_in_toy),
('p',p),
('r\\',r),
(var1_r,'r',False),
('s',s),
('S',sh),
('t',t),
('T',th_as_in_think),
('U@',oor_as_in_poor),
('Ur\\',var1_oor_as_in_poor),
('U',opt_u_as_in_pull),
('}:',oo_as_in_food),
('u:',var1_oo_as_in_food),
(var2_oo_as_in_food,'u:',False),
('O:',close_to_or),
(var1_close_to_or,'O',False),
('o:',var2_close_to_or),
('v',v),
('w',w),
('W',var1_w),
('j',y),
('z',z),
('Z',ge_of_blige_etc),
lex_filename="acapela.txt",
lex_entry_format = "%s\t#%s\tUNKNOWN\n", # TODO: may be able to convert part-of-speech (NOUN etc) to/from some other formats e.g. Festival
lex_read_function=lambda lexfile:[(word,pronunc.lstrip("#")) for word, pronunc, ignore in [l.split(None,2) for l in lexfile.readlines()]],
# TODO: inline_format ?
word_separator=" ",phoneme_separator="",
safe_to_drop_characters=True, # TODO: really?
),
"x-sampa-strict" : makeVariantDic(
"A stricter version of X-SAMPA, which can distinguish between sounds not distinct in British English when converting to/from IPA, but might not work on all voices",
('a',var1_a_as_in_apple),
('r',var1_r),
noInherit=True),
"vocaloid" : makeVariantDic(
"X-SAMPA phonemes for Yamaha's Vocaloid singing synthesizer. Contributed by Lorenzo Gatti, who tested in Vocaloid 4 using two American English voices.",
('-',syllable_separator),
(primary_stress,'',False), # not used by Vocaloid
(secondary_stress,'',False),
('Q',a_as_in_ah),
(var3_a_as_in_ah,'Q',False),
(var4_a_as_in_ah,'Q',False),
(var5_a_as_in_ah,'Q',False),
('O@',o_as_in_orange),
(var1_o_as_in_orange,'O@',False),
(var2_o_as_in_orange, 'O@',False),
('@U',o_as_in_now),
('@r',e_as_in_herd),
(var1_eye, 'aI',False),
('e',e_as_in_them),
('I@',ar_as_in_year),
('e@',a_as_in_air),
(var1_a_as_in_air, 'e@',False),
(var2_a_as_in_air, 'e@',False),
(var3_a_as_in_air, 'e@',False),
(var4_a_as_in_air, 'e@',False),
(var1_a_as_in_ate, 'eI', False),
(var1_i_as_in_it, 'I',False),
(var1_ear, 'I@',False),
('i:',e_as_in_eat),
(var1_e_as_in_eat, 'i:',False),
(var2_o_as_in_go, '@U', False),
('V', var1_u_as_in_but),
(var1_oy_as_in_toy, 'OI',False),
('r',r),
('th',t),
(var1_oor_as_in_poor, '@U',False),
('u:',oo_as_in_food),
(var1_oo_as_in_food, 'u:',False),
(var1_close_to_or,'O:',False),
(var2_close_to_or,'O:',False),
(var1_w, 'w', False),
lex_filename="vocaloid.txt",
phoneme_separator=" ",
noInherit=True
),
"android-pico" : makeVariantDic(
'X-SAMPA phonemes for the default \"Pico\" voice in Android 1.6+ (American), wrapped in Java code', # you could put en-GB instead of en-US, but it must be installed on the phone
('A:',a_as_in_ah), # won't sound without the :
(var5_a_as_in_ah,'A:',False), # a: won't sound
('@U:',o_as_in_go),
('I',var1_i_as_in_it), # '1' won't sound
('i:',e_as_in_eat), # 'i' won't sound
('u:',oo_as_in_food), # }: won't sound
('a_I',eye),('a_U',o_as_in_now),('e_I',a_as_in_ate),('O_I',oy_as_in_toy),(var1_oy_as_in_toy,'O_I',False),('o_U',var2_o_as_in_go),
cleanup_regexps=[(r'\\',r'\\\\'),('"','"'),('::',':')],
lex_filename="",lex_entry_format="",
lex_read_function=None,
inline_oneoff_header=r'class Speak { public static void speak(android.app.Activity a,String s) { class OnInit implements android.speech.tts.TextToSpeech.OnInitListener { public OnInit(String s) { this.s = s; } public void onInit(int i) { mTts.speak(this.s, android.speech.tts.TextToSpeech.QUEUE_ADD, null); } private String s; }; if(mTts==null) mTts=new android.speech.tts.TextToSpeech(a,new OnInit(s),"com.svox.pico"); else mTts.speak(s, android.speech.tts.TextToSpeech.QUEUE_ADD, null); } private static android.speech.tts.TextToSpeech mTts = null; };'+'\n',
inline_header=r'Speak.speak(this,"<speak xml:lang=\"en-US\">',
inline_format=r'<phoneme alphabet=\"xsampa\" ph=\"%s\"/>',
clause_separator=r".\n", # note r"\n" != "\n"
inline_footer='</speak>");',
),
"acapela-uk" : makeDic(
'Acapela-optimised X-SAMPA for UK English voices (e.g. "Peter"), contributed by Jan Weiss',
('.',syllable_separator),('"',primary_stress),('%',secondary_stress), # copied from "x-sampa", not tested
('A:',a_as_in_ah),
('{',a_as_in_apple),
('V',u_as_in_but),
('Q',o_as_in_orange),
('A',var1_o_as_in_orange),
('O',var2_o_as_in_orange),
('aU',o_as_in_now),
('{O',var1_o_as_in_now),
('@',a_as_in_ago),
('3:',e_as_in_herd),
('aI',eye),
('A e',var1_eye),
('b',b),
('t S',ch),
('d',d),
('D',th_as_in_them),
('e',e_as_in_them),
(ar_as_in_year,'3:',False),
('e @',a_as_in_air),
('e r',var1_a_as_in_air),
('e :',var2_a_as_in_air),
(var3_a_as_in_air,'e :',False),
('eI',a_as_in_ate),
('{I',var1_a_as_in_ate),
('f',f),
('g',g),
('h',h),
('I',i_as_in_it),
('1',var1_i_as_in_it),
('I@',ear),
('I r',var1_ear),
('i',e_as_in_eat),
('i:',var1_e_as_in_eat),
('dZ',j_as_in_jump),
('k',k),
('x',opt_scottish_loch),
('l',l),
('m',m),
('n',n),
('N',ng),
('@U',o_as_in_go),
('o U',var2_o_as_in_go),
('@ }',var1_u_as_in_but),
('OI',oy_as_in_toy),
('o I',var1_oy_as_in_toy),
('p',p),
('r',r),
('s',s),
('S',sh),
('t',t),
('T',th_as_in_think),
('U@',oor_as_in_poor),
('U r',var1_oor_as_in_poor),
('U',opt_u_as_in_pull),
('u:',oo_as_in_food),
('O:',close_to_or),
(var1_close_to_or,'O',False),
('v',v),
('w',w),
('j',y),
('z',z),
('Z',ge_of_blige_etc),
lex_filename="acapela.txt",
lex_entry_format = "%s\t#%s\tUNKNOWN\n", # TODO: part-of-speech (as above)
lex_read_function=lambda lexfile:[(word,pronunc.lstrip("#")) for word, pronunc, ignore in [l.split(None,2) for l in lexfile.readlines()]],
inline_format = "\\Prn=%s\\",
safe_to_drop_characters=True, # TODO: really?
),
"cmu" : makeDic(
'format of the US-English Carnegie Mellon University Pronouncing Dictionary, contributed by Jan Weiss', # http://www.speech.cs.cmu.edu/cgi-bin/cmudict
('0',syllable_separator),
('1',primary_stress),
('2',secondary_stress),
('AA',a_as_in_ah),
(var1_a_as_in_ah,'2',False),
(ipa_colon,'1',False),
('AE',a_as_in_apple),
('AH',u_as_in_but),
(o_as_in_orange,'AA',False),
('AW',o_as_in_now),
(a_as_in_ago,'AH',False), # seems they don't use AX as festival-cmu does
('ER',e_as_in_herd), # TODO: check this one
('AY',eye),
('B',b),
('CH',ch),
('D',d),
('DH',th_as_in_them),
('EH',e_as_in_them),
(ar_as_in_year,'ER',False),
(a_as_in_air,'ER',False),
('EY',a_as_in_ate),
('F',f),
('G',g),
('HH',h),
('IH',i_as_in_it),
('EY AH',ear),
('IY',e_as_in_eat),
('JH',j_as_in_jump),
('K',k),
('L',l),
('M',m),
('N',n),
('NG',ng),
('OW',o_as_in_go),
('OY',oy_as_in_toy),
('P',p),
('R',r),
('S',s),
('SH',sh),
('T',t),
('TH',th_as_in_think),
('UH',oor_as_in_poor),
('UW',oo_as_in_food),
('AO',close_to_or),
('V',v),
('W',w),
('Y',y),
('Z',z),
('ZH',ge_of_blige_etc),
# lex_filename not set (does CMU have a lex file?)
safe_to_drop_characters=True, # TODO: really?
),
# BEGIN PRE-32bit ERA SYNTHS (TODO: add an attribute to JS-hide them by default in HTML? what about the SpeakJet which probably isn't a 32-bit chip but is post 32-bit era? and then what about the 'approximation' formats - kana etc - would they need hiding by default also? maybe best to just leave it)
"apollo" : makeDic(
'Dolphin Apollo 2 serial-port and parallel-port hardware synthesizers (in case anybody still uses those)',
(syllable_separator,'',False), # I don't think the Apollo had anything to mark stress; TODO: control the pitch instead like bbcmicro ?
('_QQ',syllable_separator,False), # a slight pause
('_AA',a_as_in_apple),
('_AI',a_as_in_ate),
('_AR',a_as_in_ah),
('_AW',close_to_or),
('_A',a_as_in_ago),
('_B',b),
('_CH',ch),
('_D',d),
('_DH',th_as_in_them),
('_EE',e_as_in_eat),
('_EI',a_as_in_air),
('_ER',e_as_in_herd),
('_E',e_as_in_them),
('_F',f),
('_G',g),
('_H',h),
('_IA',ear),
('_IE',eye),
('_I',i_as_in_it),
('_J',j_as_in_jump),
('_K',k),
('_KK',k,False), # sCHool
('_L',l),
('_M',m),
('_NG',ng),
('_N',n),
('_OA',o_as_in_go),
('_OO',opt_u_as_in_pull),
('_OR',var3_close_to_or),
('_OW',o_as_in_now),
('_OY',oy_as_in_toy),
('_O',o_as_in_orange),
('_P',p),
('_PP',p,False), # sPeech (a stronger P ?)
# _Q = k w - done by cleanup_regexps below
('_R',r),
('_SH',sh),
('_S',s),
('_TH',th_as_in_think),