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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. void
  30. test_espeak_terminate_without_initialize()
  31. {
  32. printf("testing espeak_Terminate without espeak_Initialize\n");
  33. assert(event_list == NULL);
  34. assert(translator == NULL);
  35. assert(p_decoder == NULL);
  36. assert(espeak_Terminate() == EE_OK);
  37. assert(event_list == NULL);
  38. assert(translator == NULL);
  39. assert(p_decoder == NULL);
  40. }
  41. void
  42. test_espeak_initialize()
  43. {
  44. printf("testing espeak_Initialize\n");
  45. assert(event_list == NULL);
  46. assert(translator == NULL);
  47. assert(p_decoder == NULL);
  48. assert(espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0) == 22050);
  49. assert(event_list != NULL);
  50. assert(translator == NULL);
  51. assert(p_decoder == NULL);
  52. assert(espeak_Terminate() == EE_OK);
  53. assert(event_list == NULL);
  54. assert(translator == NULL);
  55. assert(p_decoder == NULL);
  56. }
  57. void
  58. test_espeak_synth()
  59. {
  60. printf("testing espeak_Synth\n");
  61. assert(event_list == NULL);
  62. assert(translator == NULL);
  63. assert(p_decoder == NULL);
  64. assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
  65. assert(event_list != NULL);
  66. assert(translator == NULL);
  67. assert(p_decoder == NULL);
  68. const char *test = "One two three.";
  69. assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
  70. assert(translator != NULL);
  71. assert(p_decoder != NULL);
  72. assert(espeak_Synchronize() == EE_OK);
  73. assert(translator != NULL);
  74. assert(p_decoder != NULL);
  75. assert(espeak_Terminate() == EE_OK);
  76. assert(event_list == NULL);
  77. assert(translator == NULL);
  78. assert(p_decoder == NULL);
  79. }
  80. void
  81. test_espeak_synth_no_voices(const char *path)
  82. {
  83. printf("testing espeak_Synth in path with no voices\n");
  84. assert(event_list == NULL);
  85. assert(translator == NULL);
  86. assert(p_decoder == NULL);
  87. assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, path, espeakINITIALIZE_DONT_EXIT) == 22050);
  88. assert(event_list != NULL);
  89. assert(translator == NULL);
  90. assert(p_decoder == NULL);
  91. const char *test = "One two three.";
  92. assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_INTERNAL_ERROR);
  93. assert(translator == NULL);
  94. assert(p_decoder == NULL);
  95. assert(espeak_Synchronize() == EE_OK);
  96. assert(translator == NULL);
  97. assert(p_decoder == NULL);
  98. assert(espeak_Terminate() == EE_OK);
  99. assert(event_list == NULL);
  100. assert(translator == NULL);
  101. assert(p_decoder == NULL);
  102. }
  103. int
  104. main(int argc, char **argv)
  105. {
  106. char *progdir = strdup(argv[0]);
  107. char *dir = strrchr(progdir, '/');
  108. if (dir != NULL) *dir = 0;
  109. test_espeak_terminate_without_initialize();
  110. test_espeak_initialize();
  111. test_espeak_synth();
  112. test_espeak_synth(); // Check that this does not crash when run a second time.
  113. test_espeak_synth_no_voices(progdir);
  114. test_espeak_synth();
  115. free(progdir);
  116. return EXIT_SUCCESS;
  117. }