eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tokenizer.c 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2017 Reece H. Dunn
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write see:
  16. * <http://www.gnu.org/licenses/>.
  17. */
  18. #include "config.h"
  19. #include <assert.h>
  20. #include <stdint.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <espeak-ng/espeak_ng.h>
  24. #include "encoding.h"
  25. #include "speech.h"
  26. #include "phoneme.h"
  27. #include "synthesize.h"
  28. #include "translate.h"
  29. void
  30. test_latin_common()
  31. {
  32. printf("testing Latin/Common (Latn/Zyyy) script classification\n");
  33. assert(clause_type_from_codepoint('a') == CLAUSE_NONE);
  34. assert(clause_type_from_codepoint('.') == CLAUSE_PERIOD);
  35. assert(clause_type_from_codepoint('?') == CLAUSE_QUESTION);
  36. assert(clause_type_from_codepoint('!') == CLAUSE_EXCLAMATION);
  37. assert(clause_type_from_codepoint(',') == CLAUSE_COMMA);
  38. assert(clause_type_from_codepoint(':') == CLAUSE_COLON);
  39. assert(clause_type_from_codepoint(';') == CLAUSE_SEMICOLON);
  40. assert(clause_type_from_codepoint(0x00A1) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  41. assert(clause_type_from_codepoint(0x00Bf) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  42. assert(clause_type_from_codepoint(0x2013) == CLAUSE_SEMICOLON);
  43. assert(clause_type_from_codepoint(0x2014) == CLAUSE_SEMICOLON);
  44. assert(clause_type_from_codepoint(0x2026) == (CLAUSE_SEMICOLON | CLAUSE_SPEAK_PUNCTUATION_NAME | CLAUSE_OPTIONAL_SPACE_AFTER));
  45. }
  46. void
  47. test_greek()
  48. {
  49. printf("testing Greek (Grek) script classification\n");
  50. assert(clause_type_from_codepoint(0x037E) == CLAUSE_QUESTION);
  51. assert(clause_type_from_codepoint(0x0387) == CLAUSE_SEMICOLON);
  52. }
  53. void
  54. test_armenian()
  55. {
  56. printf("testing Armenian (Armn) script classification\n");
  57. assert(clause_type_from_codepoint(0x055B) == (CLAUSE_PERIOD | CLAUSE_PUNCTUATION_IN_WORD));
  58. assert(clause_type_from_codepoint(0x055C) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
  59. assert(clause_type_from_codepoint(0x055D) == CLAUSE_COMMA);
  60. assert(clause_type_from_codepoint(0x055E) == (CLAUSE_QUESTION | CLAUSE_PUNCTUATION_IN_WORD));
  61. assert(clause_type_from_codepoint(0x0589) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  62. }
  63. void
  64. test_arabic()
  65. {
  66. printf("testing Arabic (Arab) script classification\n");
  67. assert(clause_type_from_codepoint(0x060C) == CLAUSE_COMMA);
  68. assert(clause_type_from_codepoint(0x061B) == CLAUSE_SEMICOLON);
  69. assert(clause_type_from_codepoint(0x061F) == CLAUSE_QUESTION);
  70. assert(clause_type_from_codepoint(0x06D4) == CLAUSE_PERIOD);
  71. }
  72. void
  73. test_devanagari()
  74. {
  75. printf("testing Devanagari (Deva) script classification\n");
  76. assert(clause_type_from_codepoint(0x0964) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  77. }
  78. void
  79. test_tibetan()
  80. {
  81. printf("testing Tibetan (Tibt) script classification\n");
  82. assert(clause_type_from_codepoint(0x0F0D) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  83. assert(clause_type_from_codepoint(0x0F0E) == CLAUSE_PARAGRAPH);
  84. }
  85. void
  86. test_sinhala()
  87. {
  88. printf("testing Sinhala (Sinh) script classification\n");
  89. assert(clause_type_from_codepoint(0x0DF4) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  90. }
  91. void
  92. test_georgian()
  93. {
  94. printf("testing Georgian (Geor) script classification\n");
  95. assert(clause_type_from_codepoint(0x10FB) == CLAUSE_PARAGRAPH);
  96. }
  97. void
  98. test_ethiopic()
  99. {
  100. printf("testing Ethiopic (Ethi) script classification\n");
  101. assert(clause_type_from_codepoint(0x1362) == CLAUSE_PERIOD);
  102. assert(clause_type_from_codepoint(0x1363) == CLAUSE_COMMA);
  103. assert(clause_type_from_codepoint(0x1364) == CLAUSE_SEMICOLON);
  104. assert(clause_type_from_codepoint(0x1365) == CLAUSE_COLON);
  105. assert(clause_type_from_codepoint(0x1366) == CLAUSE_COLON);
  106. assert(clause_type_from_codepoint(0x1367) == CLAUSE_QUESTION);
  107. assert(clause_type_from_codepoint(0x1368) == CLAUSE_PARAGRAPH);
  108. }
  109. void
  110. test_ideographic()
  111. {
  112. printf("testing Ideographic (Hani) script classification\n");
  113. assert(clause_type_from_codepoint(0x3001) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  114. assert(clause_type_from_codepoint(0x3002) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  115. }
  116. void
  117. test_fullwidth()
  118. {
  119. printf("testing Full Width/Common (Zyyy) script classification\n");
  120. assert(clause_type_from_codepoint(0xFF01) == (CLAUSE_EXCLAMATION | CLAUSE_OPTIONAL_SPACE_AFTER));
  121. assert(clause_type_from_codepoint(0xFF0C) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  122. assert(clause_type_from_codepoint(0xFF0E) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  123. assert(clause_type_from_codepoint(0xFF1A) == (CLAUSE_COLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  124. assert(clause_type_from_codepoint(0xFF1B) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  125. assert(clause_type_from_codepoint(0xFF1F) == (CLAUSE_QUESTION | CLAUSE_OPTIONAL_SPACE_AFTER));
  126. }
  127. int
  128. main(int argc, char **argv)
  129. {
  130. test_latin_common();
  131. test_greek();
  132. test_armenian();
  133. test_arabic();
  134. test_devanagari();
  135. test_tibetan();
  136. test_sinhala();
  137. test_georgian();
  138. test_ethiopic();
  139. test_ideographic();
  140. test_fullwidth();
  141. printf("done\n");
  142. return EXIT_SUCCESS;
  143. }