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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <stdint.h>
  22. #include <stdlib.h>
  23. #include <espeak-ng/espeak_ng.h>
  24. #include <espeak-ng/speak_lib.h>
  25. #include <espeak-ng/encoding.h>
  26. #include "compiledict.h"
  27. #include "phoneme.h"
  28. #include "voice.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_SPEECH_STOPPED: return EE_OK;
  38. case ENS_VOICE_NOT_FOUND: return EE_NOT_FOUND;
  39. case ENS_MBROLA_NOT_FOUND: return EE_NOT_FOUND;
  40. case ENS_MBROLA_VOICE_NOT_FOUND: return EE_NOT_FOUND;
  41. case ENS_FIFO_BUFFER_FULL: return EE_BUFFER_FULL;
  42. default: return EE_INTERNAL_ERROR;
  43. }
  44. }
  45. #pragma GCC visibility push(default)
  46. ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length, const char *path, int options)
  47. {
  48. espeak_ng_InitializePath(path);
  49. espeak_ng_ERROR_CONTEXT context = NULL;
  50. espeak_ng_STATUS result = espeak_ng_Initialize(&context);
  51. if (result != ENS_OK) {
  52. espeak_ng_PrintStatusCodeMessage(result, stderr, context);
  53. espeak_ng_ClearErrorContext(&context);
  54. if ((options & espeakINITIALIZE_DONT_EXIT) == 0)
  55. exit(1);
  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 espeak_ERROR espeak_Synth(const void *text, size_t size,
  76. unsigned int position,
  77. espeak_POSITION_TYPE position_type,
  78. unsigned int end_position, unsigned int flags,
  79. unsigned int *unique_identifier, void *user_data)
  80. {
  81. return status_to_espeak_error(espeak_ng_Synthesize(text, size, position, position_type, end_position, flags, unique_identifier, user_data));
  82. }
  83. ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size,
  84. const char *index_mark,
  85. unsigned int end_position,
  86. unsigned int flags,
  87. unsigned int *unique_identifier,
  88. void *user_data)
  89. {
  90. return status_to_espeak_error(espeak_ng_SynthesizeMark(text, size, index_mark, end_position, flags, unique_identifier, user_data));
  91. }
  92. ESPEAK_API espeak_ERROR espeak_Key(const char *key_name)
  93. {
  94. return status_to_espeak_error(espeak_ng_SpeakKeyName(key_name));
  95. }
  96. ESPEAK_API espeak_ERROR espeak_Char(wchar_t character)
  97. {
  98. return status_to_espeak_error(espeak_ng_SpeakCharacter(character));
  99. }
  100. ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative)
  101. {
  102. return status_to_espeak_error(espeak_ng_SetParameter(parameter, value, relative));
  103. }
  104. ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist)
  105. {
  106. return status_to_espeak_error(espeak_ng_SetPunctuationList(punctlist));
  107. }
  108. ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name)
  109. {
  110. return status_to_espeak_error(espeak_ng_SetVoiceByName(name));
  111. }
  112. ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_selector)
  113. {
  114. return status_to_espeak_error(espeak_ng_SetVoiceByProperties(voice_selector));
  115. }
  116. ESPEAK_API espeak_ERROR espeak_Cancel(void)
  117. {
  118. return status_to_espeak_error(espeak_ng_Cancel());
  119. }
  120. ESPEAK_API espeak_ERROR espeak_Synchronize(void)
  121. {
  122. return status_to_espeak_error(espeak_ng_Synchronize());
  123. }
  124. ESPEAK_API espeak_ERROR espeak_Terminate(void)
  125. {
  126. return status_to_espeak_error(espeak_ng_Terminate());
  127. }
  128. ESPEAK_API void espeak_CompileDictionary(const char *path, FILE *log, int flags)
  129. {
  130. espeak_ng_ERROR_CONTEXT context = NULL;
  131. espeak_ng_STATUS result = espeak_ng_CompileDictionary(path, dictionary_name, log, flags, &context);
  132. if (result != ENS_OK) {
  133. espeak_ng_PrintStatusCodeMessage(result, stderr, context);
  134. espeak_ng_ClearErrorContext(&context);
  135. }
  136. }
  137. #pragma GCC visibility pop