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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. // Arguments to ReadClause. Declared here to avoid duplicating them across the
  33. // different test functions.
  34. static char source[N_TR_SOURCE+40]; // extra space for embedded command & voice change info at end
  35. static short charix[N_TR_SOURCE+4];
  36. static int charix_top = 0;
  37. static int tone2;
  38. static char voice_change_name[40];
  39. static int terminator;
  40. static espeak_ng_STATUS
  41. set_text(const char *text, const char *voicename)
  42. {
  43. espeak_ng_STATUS status = espeak_ng_SetVoiceByName(voicename);
  44. if (status != ENS_OK)
  45. return status;
  46. if (p_decoder == NULL)
  47. p_decoder = create_text_decoder();
  48. return text_decoder_decode_string(p_decoder, text, -1, ESPEAKNG_ENCODING_UTF_8);
  49. }
  50. void
  51. test_latin()
  52. {
  53. printf("testing Latin (Latn)\n");
  54. assert(clause_type_from_codepoint('a') == CLAUSE_NONE);
  55. assert(clause_type_from_codepoint('.') == CLAUSE_PERIOD);
  56. assert(clause_type_from_codepoint('?') == CLAUSE_QUESTION);
  57. assert(clause_type_from_codepoint('!') == CLAUSE_EXCLAMATION);
  58. assert(clause_type_from_codepoint(',') == CLAUSE_COMMA);
  59. assert(clause_type_from_codepoint(':') == CLAUSE_COLON);
  60. assert(clause_type_from_codepoint(';') == CLAUSE_SEMICOLON);
  61. assert(clause_type_from_codepoint(0x00A1) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  62. assert(clause_type_from_codepoint(0x00Bf) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  63. assert(clause_type_from_codepoint(0x2013) == CLAUSE_SEMICOLON);
  64. assert(clause_type_from_codepoint(0x2014) == CLAUSE_SEMICOLON);
  65. assert(clause_type_from_codepoint(0x2026) == (CLAUSE_SEMICOLON | CLAUSE_SPEAK_PUNCTUATION_NAME | CLAUSE_OPTIONAL_SPACE_AFTER));
  66. }
  67. void
  68. test_greek()
  69. {
  70. printf("testing Greek (Grek)\n");
  71. assert(clause_type_from_codepoint(0x037E) == CLAUSE_QUESTION);
  72. assert(clause_type_from_codepoint(0x0387) == CLAUSE_SEMICOLON);
  73. }
  74. void
  75. test_armenian()
  76. {
  77. printf("testing Armenian (Armn)\n");
  78. assert(clause_type_from_codepoint(0x055B) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
  79. assert(clause_type_from_codepoint(0x055C) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
  80. assert(clause_type_from_codepoint(0x055D) == CLAUSE_COMMA);
  81. assert(clause_type_from_codepoint(0x055E) == (CLAUSE_QUESTION | CLAUSE_PUNCTUATION_IN_WORD));
  82. assert(clause_type_from_codepoint(0x0589) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  83. }
  84. void
  85. test_arabic()
  86. {
  87. printf("testing Arabic (Arab)\n");
  88. assert(clause_type_from_codepoint(0x060C) == CLAUSE_COMMA);
  89. assert(clause_type_from_codepoint(0x061B) == CLAUSE_SEMICOLON);
  90. assert(clause_type_from_codepoint(0x061F) == CLAUSE_QUESTION);
  91. assert(clause_type_from_codepoint(0x06D4) == CLAUSE_PERIOD);
  92. }
  93. void
  94. test_devanagari()
  95. {
  96. printf("testing Devanagari (Deva)\n");
  97. assert(clause_type_from_codepoint(0x0964) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  98. }
  99. void
  100. test_tibetan()
  101. {
  102. printf("testing Tibetan (Tibt)\n");
  103. assert(clause_type_from_codepoint(0x0F0D) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  104. assert(clause_type_from_codepoint(0x0F0E) == CLAUSE_PARAGRAPH);
  105. }
  106. void
  107. test_sinhala()
  108. {
  109. printf("testing Sinhala (Sinh)\n");
  110. assert(clause_type_from_codepoint(0x0DF4) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  111. }
  112. void
  113. test_georgian()
  114. {
  115. printf("testing Georgian (Geor)\n");
  116. assert(clause_type_from_codepoint(0x10FB) == CLAUSE_PARAGRAPH);
  117. }
  118. void
  119. test_ethiopic()
  120. {
  121. printf("testing Ethiopic (Ethi)\n");
  122. assert(clause_type_from_codepoint(0x1362) == CLAUSE_PERIOD);
  123. assert(clause_type_from_codepoint(0x1363) == CLAUSE_COMMA);
  124. assert(clause_type_from_codepoint(0x1364) == CLAUSE_SEMICOLON);
  125. assert(clause_type_from_codepoint(0x1365) == CLAUSE_COLON);
  126. assert(clause_type_from_codepoint(0x1366) == CLAUSE_COLON);
  127. assert(clause_type_from_codepoint(0x1367) == CLAUSE_QUESTION);
  128. assert(clause_type_from_codepoint(0x1368) == CLAUSE_PARAGRAPH);
  129. }
  130. void
  131. test_ideographic()
  132. {
  133. printf("testing Ideographic (Hani)\n");
  134. assert(clause_type_from_codepoint(0x3001) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  135. assert(clause_type_from_codepoint(0x3002) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  136. }
  137. void
  138. test_fullwidth()
  139. {
  140. printf("testing Full Width\n");
  141. assert(clause_type_from_codepoint(0xFF01) == (CLAUSE_EXCLAMATION | CLAUSE_OPTIONAL_SPACE_AFTER));
  142. assert(clause_type_from_codepoint(0xFF0C) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  143. assert(clause_type_from_codepoint(0xFF0E) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  144. assert(clause_type_from_codepoint(0xFF1A) == (CLAUSE_COLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  145. assert(clause_type_from_codepoint(0xFF1B) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  146. assert(clause_type_from_codepoint(0xFF1F) == (CLAUSE_QUESTION | CLAUSE_OPTIONAL_SPACE_AFTER));
  147. }
  148. void
  149. test_emoji_single_character_sequences()
  150. {
  151. short retix[] = {
  152. 0, -1, -1,
  153. 2, -1, -1,
  154. 3, -1, -1,
  155. 4, -1, -1, -1,
  156. 5, -1, -1, -1,
  157. 6,
  158. 0 };
  159. assert(set_text(
  160. "\xE2\x86\x94" // [2194] left right arrow
  161. "\xE2\x86\x95" // [2195] up down arrow
  162. "\xE2\x9B\x94" // [26D5] no entry
  163. "\xF0\x9F\x90\x8B" // [1F40B] whale
  164. "\xF0\x9F\x90\xAC", // [1F42C] dolphin
  165. "en") == ENS_OK);
  166. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  167. assert(!strcmp(source,
  168. "\xE2\x86\x94" // [2194] left right arrow
  169. "\xE2\x86\x95" // [2195] up down arrow
  170. "\xE2\x9B\x94" // [26D5] no entry
  171. "\xF0\x9F\x90\x8B" // [1F40B] whale
  172. "\xF0\x9F\x90\xAC" // [1F42C] dolphin
  173. " "));
  174. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 2);
  175. assert(!memcmp(charix, retix, sizeof(retix)));
  176. assert(tone2 == 0);
  177. assert(voice_change_name[0] == 0);
  178. }
  179. void
  180. test_emoji()
  181. {
  182. printf("testing Emoji\n");
  183. test_emoji_single_character_sequences();
  184. }
  185. int
  186. main(int argc, char **argv)
  187. {
  188. assert(espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, espeakINITIALIZE_DONT_EXIT) == 22050);
  189. test_latin();
  190. test_greek();
  191. test_armenian();
  192. test_arabic();
  193. test_devanagari();
  194. test_tibetan();
  195. test_sinhala();
  196. test_georgian();
  197. test_ethiopic();
  198. test_ideographic();
  199. test_fullwidth();
  200. test_emoji();
  201. assert(espeak_Terminate() == EE_OK);
  202. return EXIT_SUCCESS;
  203. }