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.

espeak_api.c 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* An implementation of the eSpeak API using the espeak-ng API.
  2. *
  3. * Copyright (C) 2005 to 2013 by Jonathan Duddington
  4. * email: [email protected]
  5. * Copyright (C) 2016 Reece H. Dunn
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see: <http://www.gnu.org/licenses/>.
  19. */
  20. #include "config.h"
  21. #include "speak_lib.h"
  22. #include "espeak_ng.h"
  23. #include <errno.h>
  24. #include <stdlib.h>
  25. #if HAVE_STDINT_H
  26. #include <stdint.h>
  27. #endif
  28. #include "speech.h"
  29. #include "phoneme.h"
  30. #include "synthesize.h"
  31. #include "translate.h"
  32. #include "event.h"
  33. static espeak_ERROR status_to_espeak_error(espeak_ng_STATUS status)
  34. {
  35. switch (status)
  36. {
  37. case ENS_OK: return EE_OK;
  38. case ENOENT: return EE_NOT_FOUND;
  39. case ENS_FIFO_BUFFER_FULL: return EE_BUFFER_FULL;
  40. default: return EE_INTERNAL_ERROR;
  41. }
  42. }
  43. #pragma GCC visibility push(default)
  44. ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length, const char *path, int options)
  45. {
  46. espeak_ng_InitializePath(path);
  47. espeak_ng_STATUS result = espeak_ng_Initialize();
  48. if (result != ENS_OK) {
  49. if (result == ENS_VERSION_MISMATCH)
  50. fprintf(stderr, "Wrong version of espeak-data\n");
  51. else {
  52. fprintf(stderr, "Failed to load espeak-data\n");
  53. if ((options & espeakINITIALIZE_DONT_EXIT) == 0)
  54. exit(1);
  55. }
  56. }
  57. switch (output_type)
  58. {
  59. case AUDIO_OUTPUT_PLAYBACK:
  60. espeak_ng_InitializeOutput(ENOUTPUT_MODE_SPEAK_AUDIO, buf_length, NULL);
  61. break;
  62. case AUDIO_OUTPUT_RETRIEVAL:
  63. espeak_ng_InitializeOutput(0, buf_length, NULL);
  64. break;
  65. case AUDIO_OUTPUT_SYNCHRONOUS:
  66. espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS, buf_length, NULL);
  67. break;
  68. case AUDIO_OUTPUT_SYNCH_PLAYBACK:
  69. espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS | ENOUTPUT_MODE_SPEAK_AUDIO, buf_length, NULL);
  70. break;
  71. }
  72. option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA));
  73. return espeak_ng_GetSampleRate();
  74. }
  75. ESPEAK_API void espeak_SetSynthCallback(t_espeak_callback *SynthCallback)
  76. {
  77. synth_callback = SynthCallback;
  78. #ifdef USE_ASYNC
  79. event_set_callback(synth_callback);
  80. #endif
  81. }
  82. ESPEAK_API void espeak_SetUriCallback(int (*UriCallback)(int, const char *, const char *))
  83. {
  84. uri_callback = UriCallback;
  85. }
  86. ESPEAK_API void espeak_SetPhonemeCallback(int (*PhonemeCallback)(const char *))
  87. {
  88. phoneme_callback = PhonemeCallback;
  89. }
  90. ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size,
  91. unsigned int position,
  92. espeak_POSITION_TYPE position_type,
  93. unsigned int end_position, unsigned int flags,
  94. unsigned int *unique_identifier, void *user_data)
  95. {
  96. return status_to_espeak_error(espeak_ng_Synthesize(text, size, position, position_type, end_position, flags, unique_identifier, user_data));
  97. }
  98. ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size,
  99. const char *index_mark,
  100. unsigned int end_position,
  101. unsigned int flags,
  102. unsigned int *unique_identifier,
  103. void *user_data)
  104. {
  105. return status_to_espeak_error(espeak_ng_SynthesizeMark(text, size, index_mark, end_position, flags, unique_identifier, user_data));
  106. }
  107. ESPEAK_API espeak_ERROR espeak_Key(const char *key_name)
  108. {
  109. return status_to_espeak_error(espeak_ng_SpeakKeyName(key_name));
  110. }
  111. ESPEAK_API espeak_ERROR espeak_Char(wchar_t character)
  112. {
  113. return status_to_espeak_error(espeak_ng_SpeakCharacter(character));
  114. }
  115. ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative)
  116. {
  117. return status_to_espeak_error(espeak_ng_SetParameter(parameter, value, relative));
  118. }
  119. ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist)
  120. {
  121. return status_to_espeak_error(espeak_ng_SetPunctuationList(punctlist));
  122. }
  123. ESPEAK_API espeak_ERROR espeak_Cancel(void)
  124. {
  125. return status_to_espeak_error(espeak_ng_Cancel());
  126. }
  127. ESPEAK_API void espeak_CompileDictionary(const char *path, FILE *log, int flags)
  128. {
  129. espeak_ng_CompileDictionary(path, dictionary_name, log, flags);
  130. }
  131. #pragma GCC visibility pop