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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 <espeak-ng/espeak_ng.h>
  22. #include <espeak/speak_lib.h>
  23. #include <stdlib.h>
  24. #if HAVE_STDINT_H
  25. #include <stdint.h>
  26. #endif
  27. #include "speech.h"
  28. #include "phoneme.h"
  29. #include "synthesize.h"
  30. #include "translate.h"
  31. #include "event.h"
  32. static espeak_ERROR status_to_espeak_error(espeak_ng_STATUS status)
  33. {
  34. switch (status)
  35. {
  36. case ENS_OK: return EE_OK;
  37. case ENS_VOICE_NOT_FOUND: return EE_NOT_FOUND;
  38. case ENS_MBROLA_NOT_FOUND: return EE_NOT_FOUND;
  39. case ENS_MBROLA_VOICE_NOT_FOUND: return EE_NOT_FOUND;
  40. case ENS_FIFO_BUFFER_FULL: return EE_BUFFER_FULL;
  41. default: return EE_INTERNAL_ERROR;
  42. }
  43. }
  44. #pragma GCC visibility push(default)
  45. ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length, const char *path, int options)
  46. {
  47. espeak_ng_InitializePath(path);
  48. espeak_ng_ERROR_CONTEXT context = NULL;
  49. espeak_ng_STATUS result = espeak_ng_Initialize(&context);
  50. if (result != ENS_OK) {
  51. espeak_ng_PrintStatusCodeMessage(result, stderr, context);
  52. espeak_ng_ClearErrorContext(&context);
  53. if ((options & espeakINITIALIZE_DONT_EXIT) == 0)
  54. exit(1);
  55. }
  56. switch (output_type)
  57. {
  58. case AUDIO_OUTPUT_PLAYBACK:
  59. espeak_ng_InitializeOutput(ENOUTPUT_MODE_SPEAK_AUDIO, buf_length, NULL);
  60. break;
  61. case AUDIO_OUTPUT_RETRIEVAL:
  62. espeak_ng_InitializeOutput(0, buf_length, NULL);
  63. break;
  64. case AUDIO_OUTPUT_SYNCHRONOUS:
  65. espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS, buf_length, NULL);
  66. break;
  67. case AUDIO_OUTPUT_SYNCH_PLAYBACK:
  68. espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS | ENOUTPUT_MODE_SPEAK_AUDIO, buf_length, NULL);
  69. break;
  70. }
  71. option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA));
  72. return espeak_ng_GetSampleRate();
  73. }
  74. ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size,
  75. unsigned int position,
  76. espeak_POSITION_TYPE position_type,
  77. unsigned int end_position, unsigned int flags,
  78. unsigned int *unique_identifier, void *user_data)
  79. {
  80. return status_to_espeak_error(espeak_ng_Synthesize(text, size, position, position_type, end_position, flags, unique_identifier, user_data));
  81. }
  82. ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size,
  83. const char *index_mark,
  84. unsigned int end_position,
  85. unsigned int flags,
  86. unsigned int *unique_identifier,
  87. void *user_data)
  88. {
  89. return status_to_espeak_error(espeak_ng_SynthesizeMark(text, size, index_mark, end_position, flags, unique_identifier, user_data));
  90. }
  91. ESPEAK_API espeak_ERROR espeak_Key(const char *key_name)
  92. {
  93. return status_to_espeak_error(espeak_ng_SpeakKeyName(key_name));
  94. }
  95. ESPEAK_API espeak_ERROR espeak_Char(wchar_t character)
  96. {
  97. return status_to_espeak_error(espeak_ng_SpeakCharacter(character));
  98. }
  99. ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative)
  100. {
  101. return status_to_espeak_error(espeak_ng_SetParameter(parameter, value, relative));
  102. }
  103. ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist)
  104. {
  105. return status_to_espeak_error(espeak_ng_SetPunctuationList(punctlist));
  106. }
  107. ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name)
  108. {
  109. return status_to_espeak_error(espeak_ng_SetVoiceByName(name));
  110. }
  111. ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_selector)
  112. {
  113. return status_to_espeak_error(espeak_ng_SetVoiceByProperties(voice_selector));
  114. }
  115. ESPEAK_API espeak_ERROR espeak_Cancel(void)
  116. {
  117. return status_to_espeak_error(espeak_ng_Cancel());
  118. }
  119. ESPEAK_API espeak_ERROR espeak_Synchronize(void)
  120. {
  121. return status_to_espeak_error(espeak_ng_Synchronize());
  122. }
  123. ESPEAK_API espeak_ERROR espeak_Terminate(void)
  124. {
  125. return status_to_espeak_error(espeak_ng_Terminate());
  126. }
  127. ESPEAK_API void espeak_CompileDictionary(const char *path, FILE *log, int flags)
  128. {
  129. espeak_ng_ERROR_CONTEXT context = NULL;
  130. espeak_ng_STATUS result = espeak_ng_CompileDictionary(path, dictionary_name, log, flags, &context);
  131. if (result != ENS_OK) {
  132. espeak_ng_PrintStatusCodeMessage(result, stderr, context);
  133. espeak_ng_ClearErrorContext(&context);
  134. }
  135. }
  136. #pragma GCC visibility pop