/src/espeak-ng/src/libespeak-ng/espeak_api.c
Line | Count | Source |
1 | | /* An implementation of the eSpeak API using the espeak-ng API. |
2 | | * |
3 | | * Copyright (C) 2005 to 2013 by Jonathan Duddington |
4 | | * email: jonsd@users.sourceforge.net |
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 | | |
21 | | #include "config.h" |
22 | | |
23 | | #include <stdint.h> |
24 | | #include <stdlib.h> |
25 | | |
26 | | #include <espeak-ng/espeak_ng.h> |
27 | | #include <espeak-ng/speak_lib.h> |
28 | | #include <espeak-ng/encoding.h> |
29 | | |
30 | | #include "compiledict.h" |
31 | | |
32 | | #include "synthesize.h" // for espeakINITIALIZE_PHONEME_IPA |
33 | | #include "translate.h" // for dictionary_name, option_phoneme_events |
34 | | |
35 | | static espeak_ERROR status_to_espeak_error(espeak_ng_STATUS status) |
36 | 3.02k | { |
37 | 3.02k | switch (status) |
38 | 3.02k | { |
39 | 3.02k | case ENS_OK: return EE_OK; |
40 | 0 | case ENS_SPEECH_STOPPED: return EE_OK; |
41 | 0 | case ENS_VOICE_NOT_FOUND: return EE_NOT_FOUND; |
42 | 0 | case ENS_MBROLA_NOT_FOUND: return EE_NOT_FOUND; |
43 | 0 | case ENS_MBROLA_VOICE_NOT_FOUND: return EE_NOT_FOUND; |
44 | 0 | case ENS_FIFO_BUFFER_FULL: return EE_BUFFER_FULL; |
45 | 0 | default: return EE_INTERNAL_ERROR; |
46 | 3.02k | } |
47 | 3.02k | } |
48 | | |
49 | | #pragma GCC visibility push(default) |
50 | | |
51 | | ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length, const char *path, int options) |
52 | 1 | { |
53 | 1 | espeak_ng_InitializePath(path); |
54 | 1 | espeak_ng_ERROR_CONTEXT context = NULL; |
55 | 1 | espeak_ng_STATUS result = espeak_ng_Initialize(&context); |
56 | 1 | if (result != ENS_OK) { |
57 | 0 | espeak_ng_PrintStatusCodeMessage(result, stderr, context); |
58 | 0 | espeak_ng_ClearErrorContext(&context); |
59 | 0 | if ((options & espeakINITIALIZE_DONT_EXIT) == 0) |
60 | 0 | exit(1); |
61 | 0 | } |
62 | | |
63 | 1 | switch (output_type) |
64 | 1 | { |
65 | 0 | case AUDIO_OUTPUT_PLAYBACK: |
66 | 0 | espeak_ng_InitializeOutput(ENOUTPUT_MODE_SPEAK_AUDIO, buf_length, NULL); |
67 | 0 | break; |
68 | 0 | case AUDIO_OUTPUT_RETRIEVAL: |
69 | 0 | espeak_ng_InitializeOutput(0, buf_length, NULL); |
70 | 0 | break; |
71 | 1 | case AUDIO_OUTPUT_SYNCHRONOUS: |
72 | 1 | espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS, buf_length, NULL); |
73 | 1 | break; |
74 | 0 | case AUDIO_OUTPUT_SYNCH_PLAYBACK: |
75 | 0 | espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS | ENOUTPUT_MODE_SPEAK_AUDIO, buf_length, NULL); |
76 | 0 | break; |
77 | 1 | } |
78 | | |
79 | 1 | option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA)); |
80 | | |
81 | 1 | return espeak_ng_GetSampleRate(); |
82 | 1 | } |
83 | | |
84 | | ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size, |
85 | | unsigned int position, |
86 | | espeak_POSITION_TYPE position_type, |
87 | | unsigned int end_position, unsigned int flags, |
88 | | unsigned int *unique_identifier, void *user_data) |
89 | 3.02k | { |
90 | 3.02k | return status_to_espeak_error(espeak_ng_Synthesize(text, size, position, position_type, end_position, flags, unique_identifier, user_data)); |
91 | 3.02k | } |
92 | | |
93 | | ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size, |
94 | | const char *index_mark, |
95 | | unsigned int end_position, |
96 | | unsigned int flags, |
97 | | unsigned int *unique_identifier, |
98 | | void *user_data) |
99 | 0 | { |
100 | 0 | return status_to_espeak_error(espeak_ng_SynthesizeMark(text, size, index_mark, end_position, flags, unique_identifier, user_data)); |
101 | 0 | } |
102 | | |
103 | | ESPEAK_API espeak_ERROR espeak_Key(const char *key_name) |
104 | 0 | { |
105 | 0 | return status_to_espeak_error(espeak_ng_SpeakKeyName(key_name)); |
106 | 0 | } |
107 | | |
108 | | ESPEAK_API espeak_ERROR espeak_Char(wchar_t character) |
109 | 0 | { |
110 | 0 | return status_to_espeak_error(espeak_ng_SpeakCharacter(character)); |
111 | 0 | } |
112 | | |
113 | | ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative) |
114 | 0 | { |
115 | 0 | return status_to_espeak_error(espeak_ng_SetParameter(parameter, value, relative)); |
116 | 0 | } |
117 | | |
118 | | ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist) |
119 | 0 | { |
120 | 0 | return status_to_espeak_error(espeak_ng_SetPunctuationList(punctlist)); |
121 | 0 | } |
122 | | |
123 | | ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name) |
124 | 0 | { |
125 | 0 | return status_to_espeak_error(espeak_ng_SetVoiceByName(name)); |
126 | 0 | } |
127 | | |
128 | | ESPEAK_API espeak_ERROR espeak_SetVoiceByFile(const char *filename) |
129 | 0 | { |
130 | 0 | return status_to_espeak_error(espeak_ng_SetVoiceByFile(filename)); |
131 | 0 | } |
132 | | |
133 | | ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_selector) |
134 | 0 | { |
135 | 0 | return status_to_espeak_error(espeak_ng_SetVoiceByProperties(voice_selector)); |
136 | 0 | } |
137 | | |
138 | | ESPEAK_API espeak_ERROR espeak_Cancel(void) |
139 | 0 | { |
140 | 0 | return status_to_espeak_error(espeak_ng_Cancel()); |
141 | 0 | } |
142 | | |
143 | | ESPEAK_API espeak_ERROR espeak_Synchronize(void) |
144 | 0 | { |
145 | 0 | return status_to_espeak_error(espeak_ng_Synchronize()); |
146 | 0 | } |
147 | | |
148 | | ESPEAK_API espeak_ERROR espeak_Terminate(void) |
149 | 0 | { |
150 | 0 | return status_to_espeak_error(espeak_ng_Terminate()); |
151 | 0 | } |
152 | | |
153 | | ESPEAK_API void espeak_CompileDictionary(const char *path, FILE *log, int flags) |
154 | 0 | { |
155 | 0 | espeak_ng_ERROR_CONTEXT context = NULL; |
156 | 0 | espeak_ng_STATUS result = espeak_ng_CompileDictionary(path, dictionary_name, log, flags, &context); |
157 | 0 | if (result != ENS_OK) { |
158 | | espeak_ng_PrintStatusCodeMessage(result, stderr, context); |
159 | 0 | espeak_ng_ClearErrorContext(&context); |
160 | 0 | } |
161 | 0 | } |
162 | | |
163 | | #pragma GCC visibility pop |