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 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 "tokenizer.h"
  26. #include "speech.h"
  27. #include "phoneme.h"
  28. #include "synthesize.h"
  29. #include "translate.h"
  30. void
  31. test_latin_common()
  32. {
  33. printf("testing Latin/Common (Latn/Zyyy) script classification\n");
  34. assert(clause_type_from_codepoint('a') == CLAUSE_NONE);
  35. assert(clause_type_from_codepoint('.') == CLAUSE_PERIOD);
  36. assert(clause_type_from_codepoint('?') == CLAUSE_QUESTION);
  37. assert(clause_type_from_codepoint('!') == CLAUSE_EXCLAMATION);
  38. assert(clause_type_from_codepoint(',') == CLAUSE_COMMA);
  39. assert(clause_type_from_codepoint(':') == CLAUSE_COLON);
  40. assert(clause_type_from_codepoint(';') == CLAUSE_SEMICOLON);
  41. assert(clause_type_from_codepoint(0x00A1) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  42. assert(clause_type_from_codepoint(0x00Bf) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  43. assert(clause_type_from_codepoint(0x2013) == CLAUSE_SEMICOLON);
  44. assert(clause_type_from_codepoint(0x2014) == CLAUSE_SEMICOLON);
  45. assert(clause_type_from_codepoint(0x2026) == (CLAUSE_SEMICOLON | CLAUSE_SPEAK_PUNCTUATION_NAME | CLAUSE_OPTIONAL_SPACE_AFTER));
  46. }
  47. void
  48. test_greek()
  49. {
  50. printf("testing Greek (Grek) script classification\n");
  51. assert(clause_type_from_codepoint(0x037E) == CLAUSE_QUESTION);
  52. assert(clause_type_from_codepoint(0x0387) == CLAUSE_SEMICOLON);
  53. }
  54. void
  55. test_armenian()
  56. {
  57. printf("testing Armenian (Armn) script classification\n");
  58. assert(clause_type_from_codepoint(0x055B) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
  59. assert(clause_type_from_codepoint(0x055C) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
  60. assert(clause_type_from_codepoint(0x055D) == CLAUSE_COMMA);
  61. assert(clause_type_from_codepoint(0x055E) == (CLAUSE_QUESTION | CLAUSE_PUNCTUATION_IN_WORD));
  62. assert(clause_type_from_codepoint(0x0589) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  63. }
  64. void
  65. test_arabic()
  66. {
  67. printf("testing Arabic (Arab) script classification\n");
  68. assert(clause_type_from_codepoint(0x060C) == CLAUSE_COMMA);
  69. assert(clause_type_from_codepoint(0x061B) == CLAUSE_SEMICOLON);
  70. assert(clause_type_from_codepoint(0x061F) == CLAUSE_QUESTION);
  71. assert(clause_type_from_codepoint(0x06D4) == CLAUSE_PERIOD);
  72. }
  73. void
  74. test_devanagari()
  75. {
  76. printf("testing Devanagari (Deva) script classification\n");
  77. assert(clause_type_from_codepoint(0x0964) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  78. }
  79. void
  80. test_tibetan()
  81. {
  82. printf("testing Tibetan (Tibt) script classification\n");
  83. assert(clause_type_from_codepoint(0x0F0D) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  84. assert(clause_type_from_codepoint(0x0F0E) == CLAUSE_PARAGRAPH);
  85. }
  86. void
  87. test_sinhala()
  88. {
  89. printf("testing Sinhala (Sinh) script classification\n");
  90. assert(clause_type_from_codepoint(0x0DF4) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  91. }
  92. void
  93. test_georgian()
  94. {
  95. printf("testing Georgian (Geor) script classification\n");
  96. assert(clause_type_from_codepoint(0x10FB) == CLAUSE_PARAGRAPH);
  97. }
  98. void
  99. test_ethiopic()
  100. {
  101. printf("testing Ethiopic (Ethi) script classification\n");
  102. assert(clause_type_from_codepoint(0x1362) == CLAUSE_PERIOD);
  103. assert(clause_type_from_codepoint(0x1363) == CLAUSE_COMMA);
  104. assert(clause_type_from_codepoint(0x1364) == CLAUSE_SEMICOLON);
  105. assert(clause_type_from_codepoint(0x1365) == CLAUSE_COLON);
  106. assert(clause_type_from_codepoint(0x1366) == CLAUSE_COLON);
  107. assert(clause_type_from_codepoint(0x1367) == CLAUSE_QUESTION);
  108. assert(clause_type_from_codepoint(0x1368) == CLAUSE_PARAGRAPH);
  109. }
  110. void
  111. test_ideographic()
  112. {
  113. printf("testing Ideographic (Hani) script classification\n");
  114. assert(clause_type_from_codepoint(0x3001) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  115. assert(clause_type_from_codepoint(0x3002) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  116. }
  117. void
  118. test_fullwidth()
  119. {
  120. printf("testing Full Width/Common (Zyyy) script classification\n");
  121. assert(clause_type_from_codepoint(0xFF01) == (CLAUSE_EXCLAMATION | CLAUSE_OPTIONAL_SPACE_AFTER));
  122. assert(clause_type_from_codepoint(0xFF0C) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  123. assert(clause_type_from_codepoint(0xFF0E) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  124. assert(clause_type_from_codepoint(0xFF1A) == (CLAUSE_COLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  125. assert(clause_type_from_codepoint(0xFF1B) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  126. assert(clause_type_from_codepoint(0xFF1F) == (CLAUSE_QUESTION | CLAUSE_OPTIONAL_SPACE_AFTER));
  127. }
  128. void
  129. test_unbound_tokenizer()
  130. {
  131. printf("testing unbound tokenizer\n");
  132. espeak_ng_TOKENIZER *tokenizer = create_tokenizer();
  133. assert(tokenizer != NULL);
  134. assert(tokenizer_get_token_text(tokenizer) != NULL);
  135. assert(*tokenizer_get_token_text(tokenizer) == '\0');
  136. assert(tokenizer_read_next_token(tokenizer) == ESPEAKNG_TOKEN_END_OF_BUFFER);
  137. assert(tokenizer_get_token_text(tokenizer) != NULL);
  138. assert(*tokenizer_get_token_text(tokenizer) == '\0');
  139. assert(tokenizer_reset(tokenizer, NULL) == 0);
  140. assert(tokenizer_read_next_token(tokenizer) == ESPEAKNG_TOKEN_END_OF_BUFFER);
  141. assert(tokenizer_get_token_text(tokenizer) != NULL);
  142. assert(*tokenizer_get_token_text(tokenizer) == '\0');
  143. destroy_tokenizer(tokenizer);
  144. }
  145. int
  146. main(int argc, char **argv)
  147. {
  148. test_latin_common();
  149. test_greek();
  150. test_armenian();
  151. test_arabic();
  152. test_devanagari();
  153. test_tibetan();
  154. test_sinhala();
  155. test_georgian();
  156. test_ethiopic();
  157. test_ideographic();
  158. test_fullwidth();
  159. test_unbound_tokenizer();
  160. printf("done\n");
  161. return EXIT_SUCCESS;
  162. }