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.

readclause.c 5.4KB

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