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.

api.c 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 <stdlib.h>
  21. #include <string.h>
  22. #include <espeak-ng/espeak_ng.h>
  23. #include <espeak-ng/speak_lib.h>
  24. #include <espeak-ng/encoding.h>
  25. #include "speech.h"
  26. #include "phoneme.h"
  27. #include "synthesize.h"
  28. #include "translate.h"
  29. // region espeak_Initialize
  30. void
  31. test_espeak_terminate_without_initialize()
  32. {
  33. printf("testing espeak_Terminate without espeak_Initialize\n");
  34. assert(event_list == NULL);
  35. assert(translator == NULL);
  36. assert(p_decoder == NULL);
  37. assert(espeak_Terminate() == EE_OK);
  38. assert(event_list == NULL);
  39. assert(translator == NULL);
  40. assert(p_decoder == NULL);
  41. }
  42. void
  43. test_espeak_initialize()
  44. {
  45. printf("testing espeak_Initialize\n");
  46. assert(event_list == NULL);
  47. assert(translator == NULL);
  48. assert(p_decoder == NULL);
  49. assert(espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0) == 22050);
  50. assert(event_list != NULL);
  51. assert(translator == NULL);
  52. assert(p_decoder == NULL);
  53. assert(espeak_Terminate() == EE_OK);
  54. assert(event_list == NULL);
  55. assert(translator == NULL);
  56. assert(p_decoder == NULL);
  57. }
  58. // endregion
  59. // region espeak_Synth
  60. void
  61. test_espeak_synth()
  62. {
  63. printf("testing espeak_Synth\n");
  64. assert(event_list == NULL);
  65. assert(translator == NULL);
  66. assert(p_decoder == NULL);
  67. assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
  68. assert(event_list != NULL);
  69. assert(translator == NULL);
  70. assert(p_decoder == NULL);
  71. const char *test = "One two three.";
  72. assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
  73. assert(translator != NULL);
  74. assert(p_decoder != NULL);
  75. assert(espeak_Synchronize() == EE_OK);
  76. assert(translator != NULL);
  77. assert(p_decoder != NULL);
  78. assert(espeak_Terminate() == EE_OK);
  79. assert(event_list == NULL);
  80. assert(translator == NULL);
  81. assert(p_decoder == NULL);
  82. }
  83. void
  84. test_espeak_synth_no_voices(const char *path)
  85. {
  86. printf("testing espeak_Synth in path with no voices\n");
  87. assert(event_list == NULL);
  88. assert(translator == NULL);
  89. assert(p_decoder == NULL);
  90. assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, path, espeakINITIALIZE_DONT_EXIT) == 22050);
  91. assert(event_list != NULL);
  92. assert(translator == NULL);
  93. assert(p_decoder == NULL);
  94. const char *test = "One two three.";
  95. assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_INTERNAL_ERROR);
  96. assert(translator == NULL);
  97. assert(p_decoder == NULL);
  98. assert(espeak_Synchronize() == EE_OK);
  99. assert(translator == NULL);
  100. assert(p_decoder == NULL);
  101. assert(espeak_Terminate() == EE_OK);
  102. assert(event_list == NULL);
  103. assert(translator == NULL);
  104. assert(p_decoder == NULL);
  105. }
  106. // endregion
  107. // region espeak_SetVoiceByName
  108. void
  109. test_espeak_set_voice_by_name_null_voice()
  110. {
  111. printf("testing espeak_SetVoiceByName(NULL)\n");
  112. assert(event_list == NULL);
  113. assert(translator == NULL);
  114. assert(p_decoder == NULL);
  115. assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
  116. assert(event_list != NULL);
  117. assert(translator == NULL);
  118. assert(p_decoder == NULL);
  119. assert(espeak_SetVoiceByName("") == EE_NOT_FOUND);
  120. assert(translator == NULL);
  121. assert(p_decoder == NULL);
  122. const char *test = "One two three.";
  123. assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
  124. assert(translator != NULL);
  125. assert(p_decoder != NULL);
  126. assert(espeak_Synchronize() == EE_OK);
  127. assert(translator != NULL);
  128. assert(p_decoder != NULL);
  129. assert(espeak_Terminate() == EE_OK);
  130. assert(event_list == NULL);
  131. assert(translator == NULL);
  132. assert(p_decoder == NULL);
  133. }
  134. void
  135. test_espeak_set_voice_by_name_blank_voice()
  136. {
  137. printf("testing espeak_SetVoiceByName(\"\")\n");
  138. assert(event_list == NULL);
  139. assert(translator == NULL);
  140. assert(p_decoder == NULL);
  141. assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
  142. assert(event_list != NULL);
  143. assert(translator == NULL);
  144. assert(p_decoder == NULL);
  145. assert(espeak_SetVoiceByName("") == EE_NOT_FOUND);
  146. assert(translator == NULL);
  147. assert(p_decoder == NULL);
  148. const char *test = "One two three.";
  149. assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
  150. assert(translator != NULL);
  151. assert(p_decoder != NULL);
  152. assert(espeak_Synchronize() == EE_OK);
  153. assert(translator != NULL);
  154. assert(p_decoder != NULL);
  155. assert(espeak_Terminate() == EE_OK);
  156. assert(event_list == NULL);
  157. assert(translator == NULL);
  158. assert(p_decoder == NULL);
  159. }
  160. void
  161. test_espeak_set_voice_by_name_valid_voice()
  162. {
  163. printf("testing espeak_SetVoiceByName(\"de\")\n");
  164. assert(event_list == NULL);
  165. assert(translator == NULL);
  166. assert(p_decoder == NULL);
  167. assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
  168. assert(event_list != NULL);
  169. assert(translator == NULL);
  170. assert(p_decoder == NULL);
  171. assert(espeak_SetVoiceByName("de") == EE_OK);
  172. assert(translator != NULL);
  173. assert(p_decoder == NULL);
  174. const char *test = "One two three.";
  175. assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
  176. assert(translator != NULL);
  177. assert(p_decoder != NULL);
  178. assert(espeak_Synchronize() == EE_OK);
  179. assert(translator != NULL);
  180. assert(p_decoder != NULL);
  181. assert(espeak_Terminate() == EE_OK);
  182. assert(event_list == NULL);
  183. assert(translator == NULL);
  184. assert(p_decoder == NULL);
  185. }
  186. // endregion
  187. int
  188. main(int argc, char **argv)
  189. {
  190. char *progdir = strdup(argv[0]);
  191. char *dir = strrchr(progdir, '/');
  192. if (dir != NULL) *dir = 0;
  193. test_espeak_terminate_without_initialize();
  194. test_espeak_initialize();
  195. test_espeak_synth();
  196. test_espeak_synth(); // Check that this does not crash when run a second time.
  197. test_espeak_synth_no_voices(progdir);
  198. test_espeak_synth();
  199. test_espeak_set_voice_by_name_null_voice();
  200. test_espeak_set_voice_by_name_blank_voice();
  201. test_espeak_set_voice_by_name_valid_voice();
  202. free(progdir);
  203. return EXIT_SUCCESS;
  204. }