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