Menu

[r391]: / trunk / src / extras.cpp  Maximize  Restore  History

Download this file

2418 lines (2036 with data), 50.9 kB

   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
/***************************************************************************
* Copyright (C) 2006 to 2011 by Jonathan Duddington *
* email: jonsd@users.sourceforge.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write see: *
* <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "wx/wx.h"
#include <wx/dirdlg.h>
#include "wx/filename.h"
#include "wx/sound.h"
#include "wx/dir.h"
#include <sys/stat.h>
#include "speak_lib.h"
#include "main.h"
#include "speech.h"
#include "phoneme.h"
#include "synthesize.h"
#include "voice.h"
#include "spect.h"
#include "translate.h"
#include "options.h"
extern char word_phonemes[N_WORD_PHONEMES]; // a word translated into phoneme codes
extern int __cdecl string_sorter(char **a, char **b);
//******************************************************************************************************
FILE *f_wavtest = NULL;
FILE *f_events = NULL;
FILE *OpenWaveFile3(const char *path)
/***********************************/
{
int *p;
FILE *f;
static unsigned char wave_hdr[44] = {
'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',
0x10,0,0,0,1,0,1,0, 9,0x3d,0,0,0x12,0x7a,0,0,
2,0,0x10,0,'d','a','t','a', 0,0,0,0 };
if(path == NULL)
return(NULL);
// set the sample rate in the header
p = (int *)(&wave_hdr[24]);
p[0] = samplerate;
p[1] = samplerate * 2;
f = fopen(path,"wb");
if(f != NULL)
{
fwrite(wave_hdr,1,sizeof(wave_hdr),f);
}
return(f);
} // end of OpenWaveFile
void CloseWaveFile3(FILE *f)
/*************************/
{
unsigned int pos;
static int value;
if(f == NULL)
return;
fflush(f);
pos = ftell(f);
value = pos - 8;
fseek(f,4,SEEK_SET);
fwrite(&value,4,1,f);
value = samplerate;
fseek(f,24,SEEK_SET);
fwrite(&value,4,1,f);
value = samplerate*2;
fseek(f,28,SEEK_SET);
fwrite(&value,4,1,f);
value = pos - 44;
fseek(f,40,SEEK_SET);
fwrite(&value,4,1,f);
fclose(f);
} // end of CloseWaveFile3
int TestUriCallback(int type, const char *uri, const char *base)
{//=============================================================
if(strcmp(uri,"hello")==0)
return(1);
return(0);
}
int TestSynthCallback(short *wav, int numsamples, espeak_EVENT *events)
{//====================================================================
int type;
f_events = fopen("/home/jsd1/speechdata/text/events","a");
fprintf(f_events,"--\n");
while((type = events->type) != 0)
{
fprintf(f_events,"%2d (%4d %4ld) %5d %5d (%3d) ",type,events->unique_identifier,(long)events->user_data,events->audio_position,events->text_position,events->length);
if((type==3) || (type==4))
fprintf(f_events,"'%s'\n",events->id.name);
else
if(type==espeakEVENT_PHONEME)
{
// char buf[10];
fprintf(f_events,"[%s]\n",WordToString(events->id.number)); //old version, only 4 characters bytes
// memcpy(buf, events->id.string, 8);
// buf[8] = 0;
// fprintf(f_events,"[%s]\n", buf);
}
else
fprintf(f_events,"%d\n",events->id.number);
events++;
}
if((wav == NULL) && (f_wavtest != NULL))
{
fprintf(f_events,"Finished\n");
CloseWaveFile3(f_wavtest);
f_wavtest = NULL;
}
fclose(f_events);
if(f_wavtest == NULL) return(0);
fwrite(wav,numsamples*2,1,f_wavtest);
return(0);
}
//******************************************************************************************************
#ifdef deleted
static int RuLex_sorter(char **a, char **b)
{//=======================================
char *pa, *pb;
int xa, xb;
int ix;
pa = *a;
pb = *b;
xa = strlen(pa)-1;
xb = strlen(pb)-1;
while((xa >= 0) && (xb >= 0))
{
if((ix = (pa[xa] - pb[xb])) != 0)
return(ix);
xa--;
xb--;
}
return(pa - pb);
} /* end of strcmp2 */
#endif
static const unsigned short KOI8_R[0x60] = {
0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, // a0
0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x255c, 0x255d, 0x255e, // a8
0x255f, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, // b0
0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b, 0x256c, 0x00a9, // b8
0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, // c0
0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, // c8
0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, // d0
0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, // d8
0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, // e0
0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, // e8
0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, // f0
0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a, // f8
};
#define N_CHARS 34
#define PH(c1,c2) (c2<<8)+c1 // combine two characters into an integer for phoneme name
static void DecodePhonemes2(const char *inptr, char *outptr)
//===================================================
// Translate from internal phoneme codes into phoneme mnemonics
// This version is for Lexicon_De()
{
unsigned char phcode;
unsigned char c;
unsigned int mnem;
PHONEME_TAB *ph;
const char *p;
int ix;
int j;
int start;
static const char *stress_chars = "==,,'* ";
unsigned int replace_ph[] = {',',PH('@','-'),'W','3','y','A',PH('A',':'),'*',PH('_','!'),PH('_','|'),PH('O','I'),PH('Y',':'),PH('p','F'),PH('E','2'),0};
const char *replace_ph2[] = {NULL,NULL,"9","@r","Y","a:", "a:", "r", "?", "?", "OY", "2:", "pf" ,"E",NULL};
start = 1;
for(ix=0; (phcode = inptr[ix]) != 0; ix++)
{
if(phcode == 255)
continue; /* indicates unrecognised phoneme */
if((ph = phoneme_tab[phcode]) == NULL)
continue;
if((ph->type == phSTRESS) && (ph->std_length <= 4) && (ph->program == 0))
{
if(ph->std_length > 2)
*outptr++ = stress_chars[ph->std_length];
}
else
{
mnem = ph->mnemonic;
if(ph->type == phPAUSE)
{
if(start)
continue; // omit initial [?]
if(inptr[ix+1] == phonSCHWA_SHORT)
continue; // omit [?] before [@-*]
}
start = 0;
p = NULL;
for(j=0;;j++)
{
if(replace_ph[j] == 0)
break;
if(mnem == replace_ph[j])
{
p = replace_ph2[j];
if(p == NULL)
mnem = 0;
break;
}
}
if(p != NULL)
{
while((c = *p++) != 0)
{
*outptr++ = c;
}
}
else
if(mnem != 0)
{
while((c = (mnem & 0xff)) != 0)
{
*outptr++ = c;
mnem = mnem >> 8;
}
}
}
}
*outptr = 0; /* string terminator */
} // end of DecodePhonemes2
void Lexicon_It(int pass)
{//======================
// Reads a lexicon of pairs of words: normal spelling and spelling with accents
// Creates file: dictsource/it_listx which includes corrections for stress position and [E]/[e] and [O]/[o] phonemes
// Words which are still in error are listed in file: it_compare (in the directory of the lexicon file).
int count=0;
int matched=0;
int ix;
int c;
char *p, *p2;
int len;
int vowel_ix;
int stress_posn1;
int stress_posn2;
int stress_vowel1;
int stress_vowel2;
int use_phonemes;
FILE *f_in;
FILE *f_out;
FILE *f_listx;
FILE *f_list_in = NULL;
int listx_count;
long int displ;
const char *alt_string;
wxString str;
static wxString fname_lex;
char buf[200];
char word[80];
char word1[80];
char word2[80];
char word_stem[80];
char temp[80];
char phonemes[80];
char phonemes2[80];
char phonemes3[80];
char buf_out[200];
char buf_error[200];
char last_listx[200];
static const char *vowels1 = "aeiou";
static const char *vowels2 = "aeou";
static const char ex1[] = {'a',0xc3,0xac,0}; // aì
static const char ex2[] = {'e',0xc3,0xac,0}; // eì
static const char ex3[] = {0xc3,0xb9,'a',0}; // ùa
static const char ex4[] = {0xc3,0xb9,'e',0}; // ùe
static const char ex5[] = {0xc3,0xb9,'i',0}; // ùi
static const char ex6[] = {0xc3,0xb9,'o',0}; // ùo
static const char ex7[] = {'c',0xc3,0xac,'a',0}; // cìa
static const char ex8[] = {'c',0xc3,0xac,'o',0}; // cìo
static const char ex9[] = {'c',0xc3,0xac,'u',0}; // cìu
static const char ex10[] = {'g','l',0xc3,0xac,0}; // glì
static const char *exceptions[] = {ex1, ex2, ex3, ex4, ex5, ex6, ex7, ex8, ex9, ex10, NULL};
if(pass == 1)
{
fname_lex = wxFileSelector(_T("Italian Lexicon"),path_dir1,_T(""),_T(""),_T("*"),wxOPEN);
}
strcpy(buf,fname_lex.mb_str(wxConvLocal));
if((f_in = fopen(buf,"r")) == NULL)
{
wxLogError(_T("Can't read file ")+fname_lex);
return;
}
path_dir1 = wxFileName(fname_lex).GetPath();
strcpy(buf_out, path_dir1.mb_str(wxConvLocal));
sprintf(buf, "%s/IT_errors", buf_out);
if((f_out = fopen(buf,"w")) == NULL)
{
str = wxString(buf, wxConvLocal);
wxLogError(_T("Can't write file: ") + str);
return;
}
listx_count = 0;
last_listx[0] = 0;
if(pass == 1)
{
sprintf(buf,"%s/it_listx",path_dsource);
remove(buf);
CompileDictionary(path_dsource,"it",NULL,NULL,0);
f_listx = fopen(buf,"w");
wxLogStatus(_T("Pass 1"));
}
else
{
CompileDictionary(path_dsource,"it",NULL,NULL,0);
sprintf(buf,"%s/it_listx2",path_dsource);
f_listx = fopen(buf,"w");
sprintf(buf,"%s/it_listx",path_dsource);
if((f_list_in = fopen(buf,"r")) == NULL)
{
wxLogError(_T("Can't read file: it_listx"));
return;
}
}
if(f_listx == NULL)
{
wxLogError(_T("Can't write file: it_listx"));
return;
}
LoadVoice("it",0);
while(!feof(f_in))
{
count++;
if(fgets(buf,sizeof(buf),f_in) == NULL)
break;
if((p = strstr(buf,"//")) != NULL)
*p = 0;
if((sscanf(buf,"%s %s",word,temp)) < 2)
continue;
if(strlen(word) < 8)
sprintf(buf_error,"%s\t\t%s\t",word,temp);
else
sprintf(buf_error,"%s\t%s",word,temp);
sprintf(word1," %s ",word);
// should we remove a vowel ending to produce a stem ?
strcpy(word_stem, word);
len = strlen(word) - 1;
utf8_in(&c, temp);
// if(iswlower(c))
{
if((word[len] == 'a') && (strchr(vowels1, word[len-1]) == NULL))
word_stem[len] = 0;
else
if((word[len] == 'o') && (strchr(vowels2, word[len-1]) == NULL))
word_stem[len] = 0;
}
// convert word to lower-case
word2[0] = ' ';
for(ix=0, p=&word2[1];;)
{
ix += utf8_in(&c,&temp[ix]);
c = towlower(c);
p += utf8_out(c,p);
if(c == 0)
break;
}
strcat(word2," ");
use_phonemes = 0;
for(ix=0; ; ix++)
{
if(exceptions[ix] == NULL)
break;
if(strstr(word2, exceptions[ix]) != NULL)
{
// the word contains a string for which we must do a complete phoneme translation
use_phonemes = 1;
strcpy(word_stem, word);
break;
}
}
// translate
TranslateWord(translator,&word1[1],0, NULL, NULL);
DecodePhonemes(word_phonemes,phonemes);
stress_posn1 = 0;
stress_posn2 = 0;
stress_vowel1 = 0;
stress_vowel2 = 0;
vowel_ix = 1;
for(ix=0; ;ix++)
{
if((c = word_phonemes[ix]) == 0)
break;
if(c == phonSTRESS_P)
{
stress_posn1 = vowel_ix;
stress_vowel1 = word_phonemes[ix+1];
}
if((c != phonSCHWA_SHORT) && (phoneme_tab[c]->type == phVOWEL))
vowel_ix++;
}
TranslateWord(translator,&word2[1],0, NULL, NULL);
DecodePhonemes(word_phonemes,phonemes2);
vowel_ix = 1;
for(ix=0; ;ix++)
{
if((c = word_phonemes[ix]) == 0)
break;
if(c == phonSTRESS_P)
{
stress_posn2 = vowel_ix;
stress_vowel2 = word_phonemes[ix+1];
}
if((c != phonSCHWA_SHORT) && (phoneme_tab[c]->type == phVOWEL))
vowel_ix++;
}
if(stress_posn2 == (vowel_ix-1))
{
// stress is on the final vowel, don't renove it
strcpy(word_stem, word);
}
if(pass == 1)
{
if(use_phonemes)
{
fprintf(f_listx,"%s ", word_stem);
for(p = phonemes2; *p != 0; p++)
{
if(*p != ',')
fputc(*p, f_listx); // omit secondary stress marks
}
fputc('\n',f_listx);
}
else
if((stress_posn1 != stress_posn2) && (stress_posn1 > 0) && (stress_posn2 > 0))
{
fprintf(f_listx,"%s $%d\n", word_stem, stress_posn2);
}
}
// reduce [E] and [O] to [e] and [o] if not stressed
for(ix=0; phonemes[ix] != 0; ix++)
{
if((phonemes[ix] == 'E') || (phonemes[ix] == 'O'))
{
if((pass == 2) || (ix==0) || (phonemes[ix-1] != '\''))
phonemes[ix] = tolower(phonemes[ix]);
}
}
for(ix=0; phonemes2[ix] != 0; ix++)
{
if((phonemes2[ix] == 'E') || (phonemes2[ix] == 'O'))
{
if((pass == 2) || (ix==0) || (phonemes2[ix-1] != '\''))
phonemes2[ix] = tolower(phonemes2[ix]);
}
}
if(strcmp(phonemes,phonemes2) == 0)
{
alt_string = NULL;
if((pass == 2) && (stress_posn1 > 0) && (stress_posn2 > 0))
{
if(((stress_vowel1 == PhonemeCode('E')) && (stress_vowel2 == PhonemeCode('e'))) ||
((stress_vowel1 == PhonemeCode('O')) && (stress_vowel2 == PhonemeCode('o'))))
{
alt_string = " $alt2";
}
else
if(((stress_vowel1 == PhonemeCode('e')) && (stress_vowel2 == PhonemeCode('E'))) ||
((stress_vowel1 == PhonemeCode('o')) && (stress_vowel2 == PhonemeCode('O'))))
{
alt_string = " $alt";
}
if(alt_string != NULL)
{
while(!feof(f_list_in))
{
displ = ftell(f_list_in);
if(fgets(buf, sizeof(buf), f_list_in) == NULL)
break;
sscanf(buf, "%s", word1);
if(strcmp(word1, word_stem) < 0)
{
sprintf(buf_out,"%s",buf); // copy it_listx from pass 1 until we reach the matching word
}
else
{
if(strcmp(word1, word_stem) == 0)
{
p = buf;
while((*p != '\n') && (*p != 0)) *p++;
*p = 0;
sprintf(buf_out,"%s %s\n",buf,alt_string); // add $alt or $alt2 to the entry
}
else
{
sprintf(buf_out,"%s %s\n", word_stem, alt_string); // add a new word with $alt or $alt2
fseek(f_list_in, displ, SEEK_SET);
}
if(strcmp(buf_out, last_listx) != 0)
{
fprintf(f_listx, "%s", buf_out);
listx_count++;
strcpy(last_listx, buf_out);
}
break;
}
if(strcmp(buf_out, last_listx) != 0)
{
fprintf(f_listx, "%s", buf_out);
listx_count++;
strcpy(last_listx, buf_out);
}
}
}
}
matched++;
}
else
{
// allow if the only difference is no primary stress
p2 = phonemes2;
p = phonemes3;
while(*p2 != 0)
{
*p = *p2++;
if((*p2 == ':') && (strchr("aeiouEO", *p) != NULL)) p2++; // change lone vowels to short by removing ':'
if(*p == '\'') *p = ','; // change primary to secondary stress
p++;
}
*p = 0;
if(strcmp(phonemes, phonemes3) == 0)
{
matched++;
}
else
{
// still doesn't match, report this word
fprintf(f_out,"%s\t%s\t%s\n",buf_error,phonemes,phonemes2);
}
}
}
if(pass == 2)
{
while(fgets(buf, sizeof(buf), f_list_in) != NULL)
{
if(strcmp(buf, last_listx) != 0) // check for duplicate entries
{
fprintf(f_listx, "%s", buf); // copy the remaining entries from pass 1
listx_count++;
strcpy(last_listx, buf);
}
}
fclose(f_list_in);
}
fclose(f_in);
fclose(f_out);
fclose(f_listx);
if(pass == 2)
{
sprintf(buf,"%s/it_listx",path_dsource);
remove(buf);
sprintf(buf_out,"%s/it_listx2",path_dsource);
rename(buf_out, buf);
wxLogStatus(_T("Created file 'it_listx', entries=%d errors=%d total words=%d"),listx_count, count-matched, count);
}
else
{
wxLogStatus(_T("Pass 1, equal=%d different=%d"),matched,count-matched);
}
} // end of Lexicon_It
void Lexicon_De()
{//==============
// Compare eSpeak's translation of German words with a pronunciation lexicon
FILE *f_in;
FILE *f_out;
int ix;
int c;
int c2;
char *p;
int stress;
int count=0;
int start;
int matched=0;
int defer_stress = 0;
char buf[200];
char word[80];
char word2[80];
char type[80];
char pronounce[80];
char pronounce2[80];
char phonemes[80];
char phonemes2[80];
static const char *vowels = "aeiouyAEIOUY29@";
wxString fname = wxFileSelector(_T("German Lexicon"),path_dir1,_T(""),_T(""),_T("*"),wxOPEN);
strcpy(buf,fname.mb_str(wxConvLocal));
if((f_in = fopen(buf,"r")) == NULL)
{
wxLogError(_T("Can't read file ")+fname);
return;
}
path_dir1 = wxFileName(fname).GetPath();
if((f_out = fopen("compare_de","w")) == NULL)
{
wxLogError(_T("Can't write file "));
return;
}
LoadVoice("de",0);
word2[0] = ' ';
while(!feof(f_in))
{
count++;
if(fgets(buf,sizeof(buf),f_in) == NULL)
break;
sscanf(buf,"%s %s %s",word,type,pronounce);
// convert word to lower-case
for(ix=0, p=&word2[1];;)
{
ix += utf8_in(&c,&word[ix]);
c = towlower(c);
p += utf8_out(c,p);
if(c == 0)
break;
}
strcpy(word,&word2[1]);
strcat(&word2[1]," ");
// remove | syllable boundaries
stress=0;
start=1;
for(ix=0, p=pronounce2;;ix++)
{
c = pronounce[ix];
if(c == '\'')
{
stress=4;
continue;
}
if(c == ',')
{
stress=3;
continue;
}
if(c == '|')
continue;
if((c == '?') && start)
continue; // omit initial [?]
if(c == '<')
{
if((c2 = pronounce[ix+1]) == 'i')
{
defer_stress =1;
#ifdef deleted
if(stress == 4)
{
*p++ = 'i';
c =':';
}
else
#endif
{
c = 'I';
}
ix++;
}
}
start =0;
if(defer_stress)
{
defer_stress = 0;
}
else
if(stress && (strchr(vowels,c) != NULL))
{
if(stress == 4)
*p++ = '\'';
if(stress == 3)
*p++ = ',';
stress = 0;
}
*p++ = c;
if(c == 0)
break;
if(strchr("eiouy",c) && pronounce[ix+1] != ':')
*p++ = ':'; // ensure [;] after these vowels
}
// translate
TranslateWord(translator,&word2[1],0, NULL, NULL);
DecodePhonemes2(word_phonemes,phonemes); // also need to change some phoneme names
if(strcmp(phonemes,pronounce2) == 0)
{
matched++;
}
else
{
// remove secondary stress
strcpy(phonemes2,phonemes);
p = phonemes;
for(ix=0; ;ix++)
{
if((c = phonemes2[ix]) != ',')
*p++ = c;
if(c == 0)
break;
}
if(strcmp(phonemes,pronounce2) == 0)
{
matched++;
}
else
{
if(strlen(word) < 8)
strcat(word,"\t");
fprintf(f_out,"%s\t%s\t%s\n",word,phonemes,pronounce2);
}
}
}
fclose(f_in);
fclose(f_out);
wxLogStatus(_T("Completed, equal=%d different=%d"),matched,count-matched);
} // end of Lexicon_De
extern int IsVowel(Translator *tr, int letter);
void Lexicon_Test()
{//================
int c1, c2, c3;
char *p;
int prev_c1=0;
int prev_c2=0;
int prev_c3 = 0;
FILE *f_in;
FILE *f_out;
char buf[200];
wxString s_fname = wxFileSelector(_T("List of UTF-8 words with Combining Grave Accent U+300 to indicate stress"),path_dir1,
_T(""),_T(""),_T("*"),wxOPEN);
if(s_fname.IsEmpty())
return;
strcpy(buf,s_fname.mb_str(wxConvLocal));
path_dir1 = wxFileName(s_fname).GetPath();
if((f_in = fopen(buf,"r")) == NULL)
{
wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal));
return;
}
strcat(buf,"_1");
if((f_out = fopen(buf,"w")) == NULL)
{
wxLogError(_T("Can't write file: ") + wxString(buf,wxConvLocal));
fclose(f_in);
return;
}
while(!feof(f_in))
{
if((p = fgets(buf,sizeof(buf),f_in)) == NULL)
break;
if(buf[0] == 0)
continue;
p += utf8_in(&c1, p);
p += utf8_in(&c2, p);
p += utf8_in(&c3, p);
c1 = towlower(c1);
c2 = towlower(c2);
c3 = towlower(c3);
if(IsVowel(translator, c1))
continue;
if(IsVowel(translator, c2))
continue;
if((prev_c1 != c1) || (prev_c2 != c2) || ((prev_c3 != c3) && !IsVowel(translator,c3)))
fputc('\n',f_out);
prev_c1 = c1;
prev_c2 = c2;
prev_c3 = c3;
fprintf(f_out,"%s",buf);
}
fclose(f_in);
fclose(f_out);
} // end of Lexicon_Test
void Lexicon_Bg()
{//==============
// Bulgarian: compare stress markup in a list of words with lookup using bg_rules
char *p;
char *pw;
char *pw1;
int cc;
int vcount;
int lex_stress;
int input_length;
int n_words=0;
int n_wrong=0;
int n_out=0;
int n_stress;
int max_stress;
int max_stress_posn;
int stress_first;
int done;
PHONEME_TAB *ph;
FILE *f_in;
FILE *f_out;
char word[80];
char word_in[80];
char phonemes[N_WORD_PHONEMES];
char buf[200];
char fname[sizeof(path_dsource)+20];
static unsigned short bg_vowels[] = {0x430, 0x435, 0x438, 0x43e, 0x443, 0x44a, 0x44d, 0x44e, 0x44f, 0x450, 0x451, 0x45d, 0};
if(gui_flag == 0)
return;
wxString s_fname = wxFileSelector(_T("List of UTF-8 words with Combining Grave Accent U+300 to indicate stress"),path_dir1,
_T(""),_T(""),_T("*"),wxOPEN);
if(s_fname.IsEmpty())
return;
strcpy(buf,s_fname.mb_str(wxConvLocal));
path_dir1 = wxFileName(s_fname).GetPath();
if((f_in = fopen(buf,"r")) == NULL)
{
wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal));
return;
}
input_length = GetFileLength(buf);
sprintf(fname,"%s%c%s",path_dsource,PATHSEP,"bg_listx");
remove(fname);
CompileDictionary(path_dsource,"bg",NULL,NULL,0);
if((f_out = fopen(fname,"w")) == NULL)
{
wxLogError(_T("Can't write to: ")+wxString(fname,wxConvLocal));
fclose(f_in);
return;
}
LoadVoice("bg",0);
progress = new wxProgressDialog(_T("Lexicon"),_T(""),input_length);
for(;;)
{
if((n_words & 0x3ff) == 0)
{
progress->Update(ftell(f_in));
}
if(fgets(buf,sizeof(buf),f_in) == NULL)
break;
if(isspace2(buf[0]))
continue;
// convert from UTF-8 to Unicode
word[0] = 0;
word[1] = ' ';
pw = &word[2];
pw1 = word_in;
p = buf;
while(*p == ' ') p++;
vcount = 0;
lex_stress = 0;
n_stress = 0;
stress_first = 0;
// find the marked stress position
for(;;)
{
p += utf8_in(&cc, p);
if(iswspace(cc))
break;
if(cc == 0xfeff)
continue; // ignore UTF-8 indication
if(cc == '`')
cc = '\'';
pw1 += utf8_out(towlower(cc), pw1); // copy UTF-8 to 'word_in'
if(lookupwchar(bg_vowels, cc) != 0)
vcount++;
if((cc == '\'') || (cc == 0x300) || (cc == 0x450) || (cc == 0x45d))
{
// backprime (before the vowel), combining grave accent, or accented vowel character
if(cc == '\'')
lex_stress = vcount+1;
else
lex_stress = vcount;
n_stress++;
if(vcount == 1)
stress_first = 1;
if((cc == '\'') || (cc == 0x300))
continue; // discard backprime or combining accent
if(cc == 0x450)
cc = 0x435; // remove accent from vowel
if(cc == 0x45d)
cc = 0x438;
}
pw += utf8_out(cc, pw); // copy UTF-8 to 'word'
}
*pw++ = ' ';
*pw = 0;
*pw1 = 0;
// translate
TranslateWord(translator, &word[2],0, NULL, NULL);
DecodePhonemes(word_phonemes,phonemes);
// find the stress position in the translation
max_stress = 0;
max_stress_posn = -1;
vcount = 0;
ph = phoneme_tab[phonPAUSE];
for(p=word_phonemes; *p != 0; p++)
{
ph = phoneme_tab[(unsigned int)*p];
if(ph == NULL)
continue;
if(ph->type == phVOWEL)
vcount++;
if(ph->type == phSTRESS)
{
if(ph->std_length > max_stress)
{
max_stress = ph->std_length;
max_stress_posn = vcount+1;
}
}
}
if(n_stress > 1) n_stress = 1;
done = 0;
if(vcount < 2)
{
// don't list words with only one vowel
}
else
if((lex_stress != max_stress_posn) || (n_stress != 1))
{
if((vcount > 0) && (lex_stress > 0) && (lex_stress <= 7))
{
if((n_stress == 2) && (stress_first))
{
done = 1;
fprintf(f_out,"%s\t$%d\n",&word[2],lex_stress);
}
if(n_stress == 1)
{
done = 1;
fprintf(f_out,"%s\t$%d\n",&word[2],lex_stress);
}
}
if(done == 0)
{
n_wrong++;
fprintf(f_out,"// %s\t$text %s\n", &word[2], word_in);
}
if(done)
n_out++;
}
n_words++;
}
fclose(f_in);
fclose(f_out);
CompileDictionary(path_dsource,"bg",NULL,NULL,0);
delete progress;
sprintf(buf,"Lexicon: Input %d, Output %d, $text %d",n_words,n_out,n_wrong);
wxLogStatus(wxString(buf,wxConvLocal));
} // end of Lexicon_Bg
void Lexicon_Ru()
{//==============
// compare stress markings in Russian RuLex file with lookup in ru_rules
// Input file contains a list of Russian words (UTF-8), one per line
// Stress position can be indicated either by:
// A $ sign and syllable number after the word, eg:
// абажура $3
// or by a + sign after the stressed vowel, eg:
// абажу+ра
// espeakedit produces a file: dictsource/ru_listx and a log file dictsource/ru_log
int ix;
char *p;
int c;
FILE *f_in;
FILE *f_out;
FILE *f_log;
PHONEME_TAB *ph;
int ph_code;
int vcount;
int ru_stress;
int max_stress;
int max_stress_posn;
int n_words=0;
int n_wrong=0;
int n_errors=0;
int wlength;
int input_length;
int check_root;
char word[80];
char word2[80];
int counts[20][20][10];
char phonemes[N_WORD_PHONEMES];
char buf[200];
char fname[sizeof(path_dsource)+20];
// character codes for Russian vowels
static unsigned short ru_vowels[] = {0x430,0x435,0x438,0x439,0x43e,0x443,0x44d,0x44e,0x44f,0x450,0x451,0};
typedef struct {
const char *suffix;
int syllables;
} SUFFIX;
#ifdef deleted
FILE *f_roots;
int sfx;
const char *suffix;
int wlen;
int len;
static SUFFIX suffixes[] = {
{NULL,0},
{"ичу",2},
{"ского",2},
{"ская",2},
{"ски",1},
{"ские",2},
{"ский",1},
{"ским",1},
{"ское",2},
{"ской",1},
{"ском",1},
{"скую",2},
{"а",1},
{"е",1},
{"и",1},
{NULL,0}};
#endif
memset(counts,0,sizeof(counts));
if(gui_flag)
{
wxString fname = wxFileSelector(_T("Read lexicon.dict"),path_dictsource,
_T(""),_T(""),_T("*"),wxOPEN);
if(fname.IsEmpty())
return;
strcpy(buf,fname.mb_str(wxConvLocal));
}
else
{
strcpy(buf,"lexicon.dict");
}
if((f_in = fopen(buf,"r")) == NULL)
{
if(gui_flag)
wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal));
else
fprintf(stderr,"Can't read file: %s\n",buf);
return;
}
input_length = GetFileLength(buf);
sprintf(fname,"%s%c%s",path_dsource,PATHSEP,"ru_listx");
remove(fname);
// compile ru_dict without ru_listx
CompileDictionary(path_dsource,"ru",NULL,NULL,0);
if((f_out = fopen(fname,"w")) == NULL)
{
wxLogError(_T("Can't write to: ")+wxString(fname,wxConvLocal));
fclose(f_in);
return;
}
sprintf(fname,"%s%c%s",path_dsource,PATHSEP,"ru_log");
f_log = fopen(fname,"w");
sprintf(fname,"%s%c%s",path_dsource,PATHSEP,"ru_roots_1");
// f_roots = fopen(fname,"w");
LoadVoice("ru",0);
if(gui_flag)
progress = new wxProgressDialog(_T("Lexicon"),_T(""),input_length);
else
fprintf(stderr,"Processing lexicon.dict\n");
for(;;)
{
if(((n_words & 0x3ff) == 0) && gui_flag)
{
progress->Update(ftell(f_in));
}
if(fgets(buf,sizeof(buf),f_in) == NULL)
break;
if((p = strstr(buf,"//")) != NULL)
*p = '\n'; // truncate at comment
p = buf;
while((*p == ' ') || (*p == '\t')) p++;
if(*p == '\n')
continue; // blank line
ix = 0;
wlength = 0;
vcount = 0;
ru_stress = -1;
for(;;)
{
p += utf8_in(&c, p);
if(isspace(c))
break;
if(lookupwchar(ru_vowels, c))
vcount++;
if(c == '+')
ru_stress = vcount;
else
ix += utf8_out(c, &word[ix]);
}
word[ix] = 0;
sprintf(word2," %s ",word); // surround word by spaces before calling TranslateWord()
// find the marked stress position, if it has not been marked by a + after the stressed vowel
if(ru_stress == -1)
{
while((*p == ' ') || (*p == '\t')) p++;
sscanf(p,"$%d",&ru_stress);
if(ru_stress == -1)
{
n_errors++;
fprintf(f_log,"%s",buf);
continue; // stress position not found
}
}
// translate
TranslateWord(translator, &word2[1],0, NULL, NULL);
DecodePhonemes(word_phonemes,phonemes);
// find the stress position in the translation
max_stress = 0;
max_stress_posn = -1;
vcount = 0;
check_root = 0;
ph = phoneme_tab[phonPAUSE];
for(p=word_phonemes; (ph_code = *p & 0xff) != 0; p++)
{
ph = phoneme_tab[ph_code];
if(ph == NULL)
continue;
if((ph->type == phVOWEL) && (ph_code != phonSCHWA_SHORT))
vcount++;
if(ph->type == phSTRESS)
{
if(ph->std_length > max_stress)
{
max_stress = ph->std_length;
max_stress_posn = vcount+1;
}
}
}
n_words++;
if(ru_stress > vcount)
{
if(f_log != NULL)
{
fprintf(f_log,"%s\t $%d\t // %s\n",word,ru_stress,phonemes);
}
n_errors++;
}
else
{
counts[vcount][ru_stress][ph->type]++;
if((vcount > 1) && (ru_stress != max_stress_posn))
{
n_wrong++;
if((ru_stress==0) || (ru_stress > 7))
{
fprintf(f_out,"// "); // we only have $1 to $7 to indicate stress position
if(f_log != NULL)
{
fprintf(f_log,"%s\t $%d\t // %s\n",word,ru_stress,phonemes);
}
n_errors++;
}
else
check_root = 1;
#define X_COMPACT
fprintf(f_out,"%s",word);
#ifdef X_COMPACT
if(wlength < 8) fputc('\t',f_out);
if(wlength < 16) fputc('\t',f_out);
fprintf(f_out," $%d\n",ru_stress);
#else
while(wlength++ < 20)
fputc(' ',f_out);
fprintf(f_out," $%d //%d %s\n",ru_stress,max_stress_posn,phonemes);
#endif
//CharStats();
}
}
#ifdef deleted
if(check_root)
{
// does this word match any suffixes ?
wlen = strlen(word);
for(sfx=0;(suffix = suffixes[sfx].suffix) != NULL; sfx++)
{
len = strlen(suffix);
if(len >= (wlen-2))
continue;
if(ru_stress > (vcount - suffixes[sfx].syllables))
continue;
if(strcmp(suffix,&word[wlen-len])==0)
{
strcpy(word2,word);
word2[wlen-len] = 0;
// fprintf(f_roots,"%s\t $%d\t\\ %s\n",word2,ru_stress,suffix);
fprintf(f_roots,"%s\t $%d\n",word2,ru_stress);
}
}
}
#endif
}
fclose(f_in);
fclose(f_out);
// fclose(f_roots);
sprintf(buf,"Lexicon: Total %d OK %d fixed %d errors %d (see ru_log)",n_words,n_words-n_wrong,n_wrong,n_errors);
if(gui_flag)
{
delete progress;
wxLogStatus(wxString(buf,wxConvLocal));
}
else
{
fprintf(stderr,"%s\n",buf);
}
if(f_log != NULL)
{
#ifdef deleted
// list tables of frequency of stress position for words of different syllable lengths
int j,k;
for(ix=2; ix<12; ix++)
{
fprintf(f_log,"%2d syllables\n",ix);
for(k=0; k<10; k++)
{
fprintf(f_log," %2d :",k);
for(j=1; j<=ix; j++)
{
fprintf(f_log,"%6d ",counts[ix][j][k]);
}
fprintf(f_log,"\n");
}
fprintf(f_log,"\n\n");
}
#endif
fclose(f_log);
}
} // end of Lexicon_Ru
void CompareLexicon(int id)
{//========================
switch(id)
{
case MENU_LEXICON_RU:
Lexicon_Ru();
break;
case MENU_LEXICON_BG:
Lexicon_Bg();
break;
case MENU_LEXICON_DE:
Lexicon_De();
break;
case MENU_LEXICON_IT:
Lexicon_It(1);
Lexicon_It(2);
break;
case MENU_LEXICON_TEST:
Lexicon_Test();
break;
}
} // end of CompareLexicon
//******************************************************************************************************
extern int HashDictionary(const char *string);
static int n_words;
struct wcount {
struct wcount *link;
int count;
char *word;
};
static int wfreq_sorter(wcount **p1, wcount **p2)
{//==============================================
int x;
wcount *a, *b;
a = *p1;
b = *p2;
if((x = b->count - a->count) != 0)
return(x);
return(strcmp(a->word,b->word));
}
static void wfreq_add(const char *word, wcount **hashtab)
{//======================================================
wcount *p;
wcount **p2;
int len;
int hash;
hash = HashDictionary(word);
p2 = &hashtab[hash];
p = *p2;
while(p != NULL)
{
if(strcmp(p->word,word)==0)
{
p->count++;
return;
}
p2 = &p->link;
p = *p2;
}
// word not found, add it to the list
len = strlen(word) + 1;
if((p = (wcount *)malloc(sizeof(wcount)+len)) == NULL)
return;
p->count = 1;
p->link = NULL;
p->word = (char *)p + sizeof(wcount);
strcpy(p->word,word);
*p2 = p;
n_words++;
}
void CountWordFreq(wxString path, wcount **hashtab)
{//================================================
// Count the occurances of words in this file
FILE *f_in;
unsigned char c;
int wc;
unsigned int ix, j, k;
int n_chars;
char buf[80];
char wbuf[80];
if((f_in = fopen(path.mb_str(wxConvLocal),"rb")) == NULL)
return;
while(!feof(f_in))
{
while((c = fgetc(f_in)) < 'A')
{
// skip leading spaces, numbers, etc
if(feof(f_in)) break;
}
// read utf8 bytes until a space, number or punctuation
ix = 0;
while(!feof(f_in) && (c >= 'A') && (ix < sizeof(buf)-1))
{
buf[ix++] = c;
c = fgetc(f_in);
}
buf[ix++] = 0;
buf[ix] = 0;
// the buf may contain non-alphabetic characters
j = 0;
n_chars = 0;
for(k=0; k<ix; )
{
k += utf8_in(&wc,&buf[k]);
wc = towlower2(wc); // convert to lower case
if(iswalpha2(wc))
{
j += utf8_out(wc,&wbuf[j]);
n_chars++;
}
else
{
wbuf[j] = 0;
if(n_chars > 2)
{
wfreq_add(wbuf,hashtab);
}
j = 0;
n_chars = 0;
}
}
}
fclose(f_in);
} // end of CountWordFreq
void MakeWordFreqList()
{//====================
// Read text files from a specified directory and make a list of the most frequently occuring words.
struct wcount *whashtab[N_HASH_DICT];
wcount **w_list;
int ix;
int j;
int hash;
wcount *p;
FILE *f_out;
char buf[200];
char buf2[200];
wxString dir = wxDirSelector(_T("Directory of text files"),path_speaktext);
if(dir.IsEmpty()) return;
memset(whashtab,0,sizeof(whashtab));
wxString path = wxFindFirstFile(dir+_T("/*"),wxFILE);
while (!path.empty())
{
if(path.AfterLast(PATHSEP) != _T("!wordcounts"))
{
CountWordFreq(path,whashtab);
path = wxFindNextFile();
}
}
// put all the words into a list and then sort it
w_list = (wcount **)malloc(sizeof(wcount *) * n_words);
ix = 0;
for(hash=0; hash < N_HASH_DICT; hash++)
{
p = whashtab[hash];
while((p != NULL) && (ix < n_words))
{
w_list[ix++] = p;
p = p->link;
}
}
qsort((void *)w_list,ix,sizeof(wcount *),(int(*)(const void *,const void *))wfreq_sorter);
// write out the sorted list
strcpy(buf,dir.mb_str(wxConvLocal));
sprintf(buf2,"%s/!wordcounts",buf);
if((f_out = fopen(buf2,"w")) == NULL)
return;
for(j=0; j<ix; j++)
{
p = w_list[j];
fprintf(f_out,"%5d %s\n",p->count,p->word);
free(p);
}
fclose(f_out);
} // end of Make WorkFreqList
//******************************************************************************************************
void ConvertToUtf8()
{//=================
// Convert a file from 8bit to UTF8, according to the current voice
unsigned int c;
int ix;
FILE *f_in;
FILE *f_out;
char buf[200];
wxString fname = wxFileSelector(_T("Convert file to UTF8"),wxString(path_home,wxConvLocal),
_T(""),_T(""),_T("*"),wxOPEN);
if(fname.IsEmpty())
return;
strcpy(buf,fname.mb_str(wxConvLocal));
f_in = fopen(buf,"r");
if(f_in == NULL)
{
wxLogError(_T("Can't read file: ")+fname);
return;
}
strcat(buf,"_1");
f_out = fopen(buf,"w");
if(f_out == NULL)
{
wxLogError(_T("Can't create file: ")+wxString(buf,wxConvLocal));
fclose(f_in);
return;
}
while(!feof(f_in))
{
c = fgetc(f_in) & 0xff;
if(c >= 0xa0)
c = translator->charset_a0[c-0xa0];
ix = utf8_out(c,buf);
fwrite(buf,ix,1,f_out);
}
fclose(f_in);
fclose(f_out);
wxLogStatus(_T("Written to: ")+fname+_T("_1"));
} // end of ConvertToUtf8
//******************************************************************************************************
#define N_SORT_LIST 10000
void DictionarySort(const char *dictname)
{//======================================
// Sort rules in *_rules file between lines which begin with //sort and //endsort
FILE *f_in;
FILE *f_out;
int ix;
char *p;
char *p_end;
char *p_pre;
int sorting;
int sort_ix=0;
int sort_count=0;
int line_len;
int key_len;
char buf[200];
char key[200];
char fname_in[200];
char fname_out[200];
char *sort_list[N_SORT_LIST];
wxLogMessage(_T("Sorts the *_rules file, between lines which begin with\n//sort\n and\n//endsort"));
// try with and without '.txt' extension
sprintf(fname_in,"%s%s_rules.txt",path_dsource,dictname);
if((f_in = fopen(fname_in,"r")) == NULL)
{
sprintf(fname_in,"%s%s_rules",path_dsource,dictname);
if((f_in = fopen(fname_in,"r")) == NULL)
{
wxLogError(_T("Can't open rules file: ") + wxString(fname_in,wxConvLocal));
return;
}
}
sprintf(fname_out,"%s%s_rules_sorted",path_dsource,dictname);
if((f_out = fopen(fname_out,"w")) == NULL)
{
wxLogError(_T("Can't write to file: ") + wxString(fname_out,wxConvLocal));
fclose(f_in);
return;
}
sorting = 0;
while(fgets(buf, sizeof(buf)-1, f_in) != NULL)
{
buf[sizeof(buf)-1] = 0; // ensure zero byte terminator
line_len = strlen(buf);
if(memcmp(buf,"//endsort",9)==0)
{
sort_count++;
sorting = 0;
qsort((void *)sort_list, sort_ix, sizeof(char *), (int(*)(const void *, const void *))string_sorter);
// write out the sorted lines
for(ix=0; ix<sort_ix; ix++)
{
key_len = strlen(sort_list[ix]);
p = &sort_list[ix][key_len+1]; // the original line is after the key
fprintf(f_out,"%s",p);
free(sort_list[ix]);
}
}
if(sorting == 0)
{
if(memcmp(buf,"//sort",6)==0)
{
sorting = 1;
sort_ix = 0;
}
fwrite(buf, line_len, 1, f_out);
continue;
}
p_end = strstr(buf,"//");
if(p_end == NULL)
p_end = &buf[line_len];
// add to the list of lines to be sorted
p = buf;
while((*p==' ') || (*p == '\t')) p++; // skip leading spaces
if(*p == '?')
{
// conditional rule, skip the condition
while(!isspace(*p) && (*p != 0)) p++;
}
// skip any pre -condition
p_pre = p;
while(p < p_end)
{
if(*p == ')')
{
p_pre = p+1;
break;
}
p++;
}
p = p_pre;
while((*p==' ') || (*p == '\t')) p++; // skip spaces
ix = 0;
while(!isspace(*p) && (*p != 0))
{
key[ix++] = *p++;
}
while((*p==' ') || (*p == '\t')) p++; // skip spaces
if(*p == '(')
{
// post-condition
p++; // skip '('
while(!isspace(*p) && (*p != 0) && (p < p_end))
{
key[ix++] = *p++;
}
}
key[ix] = 0;
key_len = strlen(key);
p = (char *)malloc(key_len + line_len + 8);
sprintf(p,"%s%6d",key,sort_ix); // include the line number (within the sort section) in case the keys are otherwise equal
strcpy(p, key);
strcpy(&p[key_len+1], buf);
sort_list[sort_ix++] = p;
if(sort_ix >= N_SORT_LIST)
{
wxLogError(_T("Too many lines to sort, > %d"), N_SORT_LIST);
break;
}
}
fclose(f_in);
fclose(f_out);
if(sorting != 0)
{
wxLogError(_T("Missing //$endsort"));
}
wxLogStatus(_T("Sorted %d sections. Written to file: ") + wxString(fname_out,wxConvLocal),sort_count);
} // end of DictionarySort
void DictionaryFormat(const char *dictname)
{//========================================
// Format the *_rules file for the current voice
FILE *f_in;
FILE *f_out;
char *p;
char *p_start;
unsigned short *pw;
unsigned short *pw_match;
unsigned short *pw_post = NULL;
unsigned short *pw_phonemes = NULL;
int c;
int ix;
int n_pre;
int n_match;
int n_post;
int n_phonemes;
int n_spaces;
int n_out;
int formatting;
int comment;
char buf[200];
unsigned short bufw[200];
char conditional[80];
char fname_in[200];
char fname_out[200];
const int tab1 = 8;
const int tab2 = 18;
const int tab3 = 28;
// try with and without '.txt' extension
sprintf(fname_in,"%s%s_rules.txt",path_dsource,dictname);
if((f_in = fopen(fname_in,"r")) == NULL)
{
sprintf(fname_in,"%s%s_rules",path_dsource,dictname);
if((f_in = fopen(fname_in,"r")) == NULL)
{
wxLogError(_T("Can't open rules file: ") + wxString(fname_in,wxConvLocal));
return;
}
}
sprintf(fname_out,"%s%s_rules_formatted",path_dsource,dictname);
if((f_out = fopen(fname_out,"w")) == NULL)
{
wxLogError(_T("Can't write to file: ") + wxString(fname_out,wxConvLocal));
fclose(f_in);
return;
}
formatting = 0;
n_match = 0;
while(fgets(buf, sizeof(buf)-1, f_in) != NULL)
{
buf[sizeof(buf)-1] = 0; // ensure zero byte terminator
ix = strlen(buf) - 1;
while((buf[ix]=='\n') || (buf[ix]==' ') || (buf[ix]=='\t')) ix--;
buf[ix+1] = 0; // strip tailing spaces
p_start = buf;
while((*p_start==' ') || (*p_start == '\t')) p_start++; // skip leading spaces
comment = 0;
if((p_start[0]=='/') && (p_start[1]=='/'))
comment = 1;
ix = 0;
if(*p_start == '?')
{
// conditional rule
while(!isspace(*p_start) && (*p_start != 0))
{
conditional[ix++] = *p_start++;
}
while((*p_start == ' ') || (*p_start == '\t')) p_start++;
}
conditional[ix] = 0;
if(buf[0] == '.')
{
formatting = 0;
}
if(memcmp(p_start, ".group", 6) == 0)
{
formatting = 2;
if(n_match > 0)
{
// previous line was not blank, so add a blank line
fprintf(f_out,"\n");
}
}
n_match = 0;
if((formatting == 1) && (comment==0))
{
// convert from UTF-8 to UTF-16
p = p_start;
pw = bufw;
do {
p += utf8_in(&c, p);
*pw++ = c;
} while (c != 0);
pw = bufw;
while((*pw != ')') && (*pw != 0) && !iswspace(*pw)) pw++;
n_pre = 0;
n_post = 0;
n_phonemes = 0;
n_spaces = 0;
if(*pw != 0)
n_spaces = tab1;
if(*pw == ')')
{
// there is a pre-condition
n_pre = pw - bufw + 1;
n_spaces = tab1 - n_pre - 1;
pw++;
while((*pw==' ') || (*pw=='\t')) pw++;
}
else
{
pw = bufw;
}
pw_match = pw;
while(((c = *pw)!= ' ') && (c != '\t') && (c != '(') && (c != 0))
{
pw++;
}
n_match = pw - pw_match;
while(((c = *pw)==' ') || (c == '\t')) pw++;
if(*pw == '(')
{
pw_post = pw;
while(((c = *pw)!=' ') && (c != '\t') && (c != 0)) pw++;
n_post = pw - pw_post;
while(((c = *pw)==' ') || (c == '\t')) pw++;
}
if((*pw != 0) && ((*pw != '/') || (pw[1] != '/')))
{
pw_phonemes = pw;
while(((c = *pw)!=' ') && (c != '\t') && (c != 0)) pw++;
n_phonemes = pw - pw_phonemes;
while(((c = *pw)==' ') || (c == '\t')) pw++;
}
// write formatted line
p = buf;
if(conditional[0] != 0)
{
ix = 0;
while(conditional[ix] != 0)
{
*p++ = conditional[ix++];
n_spaces--;
}
*p++ = ' ';
n_spaces--;
}
while(n_spaces-- > 0)
{
*p++ = ' ';
}
if(n_pre > 0)
{
ix = 0;
for(ix=0; ix<n_pre; ix++)
{
p += utf8_out(bufw[ix], p);
}
*p++ = ' ';
}
// write the match condition
if(n_match > 0)
{
ix = 0;
for(ix=0; ix<n_match; ix++)
{
p += utf8_out(pw_match[ix], p);
}
*p++ = ' ';
}
// write the post condition
if(n_post > 0)
{
for(ix=0; ix<n_post; ix++)
{
p += utf8_out(pw_post[ix], p);
}
*p++ = ' ';
n_post++;
}
n_out = tab1 + n_match + n_post;
if(n_pre >= tab1)
n_out += (n_pre - tab1 + 1);
if(n_phonemes > 0)
{
n_spaces = tab2 - n_out;
while(n_spaces-- > 0)
{
*p++ = ' ';
n_out++;
}
// write the phoneme codes
for(ix=0; ix<n_phonemes; ix++)
{
p += utf8_out(pw_phonemes[ix], p);
}
}
if(*pw != 0)
{
*p++ = ' ';
n_phonemes++;
n_spaces = tab3 - (n_out + n_phonemes);
while(n_spaces-- > 0)
{
*p++ = ' ';
}
}
// write the remainer of the line
while(*pw != 0)
{
p+= utf8_out(*pw++, p);
}
*p = 0;
}
if(formatting > 1)
formatting--;
fprintf(f_out, "%s\n", buf);
}
fclose(f_in);
fclose(f_out);
remove(fname_in);
if(rename(fname_out, fname_in) == 0)
wxLogStatus(_("Written to file: ") + wxString(fname_in,wxConvLocal));
else
wxLogStatus(_("Failed to rename: ") + wxString(fname_out,wxConvLocal));
} // end of DictionaryFormat
//******************************************************************************************************
//#define calcspeedtab
#ifdef calcspeedtab
// used to set up the presets in the speed_lookup table
// interpolate between a set of measured wpm values
void SetSpeedTab(void)
{//===================
#define N_WPM 19
// Interpolation table to translate from words-per-minute to internal speed
// words-per-minute values (measured)
static float wpm1[N_WPM] =
{0, 82, 96, 108, 124, 134, 147, 162, 174, 189, 224, 259, 273, 289, 307, 326, 346, 361, 370 };
// corresponding internal speed values
static float wpm2[N_WPM] =
{0,253,200, 170, 140, 125, 110, 95, 85, 75, 55, 40, 35, 30, 25, 20, 15, 10, 5 };
unsigned char speed_lookup[290];
unsigned int ix;
float x;
int speed_wpm;
FILE *f;
// convert from word-per-minute to internal speed code
for(speed_wpm=80; speed_wpm<370; speed_wpm++)
{
for(ix=2; ix<N_WPM-2; ix++)
{
if(speed_wpm < wpm1[ix])
break;
}
x = polint(&wpm1[ix-1], &wpm2[ix-1], 3, speed_wpm);
speed_lookup[speed_wpm-80] = (unsigned char)x;
}
f = fopen("speed_lookup","w");
if(f == NULL) return;
for(ix=0; ix<sizeof(speed_lookup); ix++)
{
fprintf(f,"%4d,",speed_lookup[ix]);
if((ix % 5) == 4)
fprintf(f,"\t//%4d\n\t",(ix / 5)*5 + 80);
}
fclose(f);
} // end of SetSpeedTab
#endif
//#define xcharset
#ifdef xcharset
#include "iconv.h"
void CharsetToUnicode(const char *charset)
{//=======================================
// write a 8bit charset to unicode translation table to file
// charset: eg. "ISO-8859-1"
iconv_t cd;
unsigned char inbuf[4];
size_t n_inbuf;
unsigned char outbuf[12];
size_t n_outbuf;
int n;
int ix;
int x, y;
FILE *f;
char *p_inbuf;
char *p_outbuf;
f = fopen("/home/jsd1/tmp1/unicode1","a");
cd = iconv_open("WCHAR_T",charset);
if (cd == (iconv_t) -1)
{
fprintf(stderr,"Error - iconv_open\n");
return;
}
fprintf(f,"towlower_tab\n ");
for(ix=0x80; ix<=0x241; ix++)
{
y = 0;
if(iswalpha(ix))
{
x = towlower(ix);
if(x == ix)
y = 0xff;
else
y = x - ix;
}
if((y == 0xff) || (y < 0))
fprintf(f,"0xff,"); // ignore the 5 obscure cases where uc > lc
else
{
fprintf(f,"%4d,",y);
}
if((ix&15)==15)
fprintf(f," // %x\n ",ix & ~15);
}
fprintf(f,"\n%s\n ",charset);
for(ix=0x80; ix<0x100; ix++)
{
inbuf[0] = ix;
inbuf[1] = 0;
inbuf[2] = 0;
outbuf[0] = 0;
outbuf[1] = 0;
n_inbuf = 2;
n_outbuf = sizeof(outbuf);
p_inbuf = (char *)inbuf;
p_outbuf = (char *)outbuf;
n = iconv(cd, &p_inbuf, &n_inbuf, &p_outbuf, &n_outbuf);
fprintf(f,"0x%.2x%.2x, ",outbuf[1],outbuf[0]);
if((ix&7)==7)
fprintf(f,"// %.2x\n ",ix & ~7);
}
fclose(f);
iconv_close(cd);
}
#endif
#ifdef deleted
void Test2()
{
//
char buf[120];
FILE *f;
FILE *f_out;
unsigned char *p;
f = fopen("/home/jsd1/tmp1/list","r");
if(f == NULL) return;
f_out = fopen("/home/jsd1/tmp1/list_out","w");
if(f_out == NULL) return;
while(!feof(f))
{
if(fgets(buf,sizeof(buf),f) == NULL)
break;
p = (unsigned char *)buf;
while(*p > ' ') p++;
*p = 0;
fprintf(f_out,"%s . . .\n",buf);
}
fclose(f);
fclose(f_out);
}
#endif
#define MAX_WALPHA 0x24f
void Make_walpha_tab()
{//===================
int ix;
int value;
int c;
short exceptions[40];
int ex = 0;
FILE *f;
f = fopen("/home/jsd1/walpha_tab.txt","w");
for(ix=0x80; ix<=MAX_WALPHA; ix++)
{
value = 0;
if(iswalpha(ix))
{
value = 0xfe; // no case
if(iswlower(ix))
{
value = 0xff;
}
else if(iswupper(ix))
{
c = towlower(ix);
if(c > 0)
value = c - ix;
if((value < 0) || (value > 0xfc))
{
exceptions[ex] = ix;
exceptions[ex+1] = c;
ex+=2;
value = 0xfd;
}
}
}
if(value > 0xfc)
fprintf(f," 0x%.2x,", value);
else
fprintf(f," %4d,", value);
if((ix % 16) == 15)
{
fprintf(f," // %.3x\n", ix & 0xfff0);
}
}
fprintf(f, "\nstatic const short wchar_tolower[] = {\n");
for(ix=0; ix<ex; ix+=2)
{
fprintf(f,"\t0x%.3x, 0x%.3x,\n", exceptions[ix], exceptions[ix+1]);
}
fprintf(f, "\t0,0 };\n");
fprintf(f, "\nstatic const short wchar_toupper[] = {\n");
for(ix=0x80; ix<=MAX_WALPHA; ix++)
{
if(iswlower(ix))
{
c = towupper(ix);
value = ix - c;
if((value != 32) && (value != 1))
{
fprintf(f,"\t0x%.3x, 0x%.3x,\n", ix, c);
}
}
}
fprintf(f, "\t0,0 };\n");
fclose(f);
}
const char* text1 = "Hello world. Testing.";
extern void TestCompile2(void);
void TestTest(int control)
{//=======================
FILE *f;
unsigned int c;
unsigned int ix=0;
char textbuf[2000];
espeak_VOICE voice;
static unsigned int unique_identifier= 123;
static int user_data = 456;
//CharsetToUnicode("ISO-8859-4");
//CharsetToUnicode("ISCII");
if(control==2)
{
return;
}
memset(&voice,0,sizeof(voice));
f = fopen("/home/jsd1/speechdata/text/test.txt","r");
if(f==NULL)
return;
while(!feof(f) && (ix < sizeof(textbuf)-2))
{
c = fgetc(f);
if(!feof(f))
textbuf[ix++] = c;
}
textbuf[ix] = 0;
fclose(f);
f_wavtest = OpenWaveFile3("/home/jsd1/speechdata/text/test.wav");
f_events = fopen("/home/jsd1/speechdata/text/events","w");
fprintf(f_events,"Type Audio Text Length Id\n");
fclose(f_events);
espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 1000, NULL, espeakINITIALIZE_PHONEME_EVENTS);
espeak_SetSynthCallback(TestSynthCallback);
espeak_SetUriCallback(TestUriCallback);
voice.languages = "fr";
espeak_SetVoiceByProperties(&voice);
// espeak_SetVoiceByName("fr");
espeak_Synth("1", 5, 0, POS_CHARACTER, 0, espeakSSML|espeakCHARS_UTF8, &unique_identifier, (void *)user_data);
// voice.languages = "en";
// espeak_SetVoiceByProperties(&voice);
espeak_SetVoiceByName("de");
espeak_Synth(textbuf, strlen(textbuf)+1, 0, POS_CHARACTER, 0, espeakSSML|espeakCHARS_UTF8, &unique_identifier, (void *)user_data);
// espeak_Synth(text1, strlen(text1)+1, 0, POS_CHARACTER, 0, espeakSSML|espeakCHARS_UTF8, &unique_identifier, (void *)(user_data+1));
espeak_SetParameter(espeakPUNCTUATION, 1, 0);
espeak_Synchronize();
// espeak_Cancel();
espeak_SetParameter(espeakPUNCTUATION, 1, 0);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.