/native/external/espeak/src/mbrolib.h
C++ Header | 205 lines | 54 code | 46 blank | 105 comment | 0 complexity | c866bdb19ef20b2f8dc8b3d859f5f145 MD5 | raw file
1#ifndef MBROLIB_H 2#define MBROLIB_H 3 4/* 5 * mbrolib: mbrola wrapper. 6 * 7 * Copyright (C) 2007 Gilles Casse <gcasse@oralux.org> 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 3 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 * 23*/ 24 25#ifdef __cplusplus 26extern "C" { 27#endif 28 29/* < types */ 30 31/** Parameters */ 32 33typedef struct { 34 int ignore_error; /* 1=Ignore any fatal error or unknown diphone */ 35 char comment_char; /* Comment character */ 36 float volume_ratio; /* Volume ratio */ 37 float frequency_ratio; /* Applied to pitch points */ 38 float time_ratio; /* Applied to phone durations */ 39} mbrolib_parameter; 40 41 42/** Returned errors */ 43 44typedef enum { 45 MBROLIB_OK=0, 46 MBROLIB_DATABASE_NOT_INSTALLED, 47 MBROLIB_INVAL, 48 MBROLIB_OUT_OF_MEMORY, 49 MBROLIB_OUT_OF_RANGE, 50 MBROLIB_READ_ERROR, 51 MBROLIB_WRITE_ERROR 52} MBROLIB_ERROR; 53 54 55 56/** Gender */ 57 58typedef enum { 59 MBROLIB_FEMALE, 60 MBROLIB_MALE 61} MBROLIB_GENDER; 62 63 64 65/** Voice descriptor */ 66 67typedef struct { 68 char *name; /* name (for example: "en1") */ 69 char *filename; /* database pathname (for example: "/usr/share/mbrola/voices/en1) */ 70 int rate; /* database sample rate */ 71 MBROLIB_GENDER gender; 72 const char *language; /* Language and optional dialect qualifier in ascii (e.g. en, fr_ca). */ 73} mbrolib_voice; 74 75/* > */ 76 77 78/** Initialization, returns a new handle. 79 First function. 80 81 @param the_sample_rate: output rate in Hz (for example 22050). If 0, keep the original database rate. 82 83 @return handle (or NULL if error). 84*/ 85void* mbrolib_init( int sample_rate); 86typedef void* (t_mbrolib_init)(int); 87 88 89/** Returns the list of the installed mbrola databases. 90 The databases are searched according to the MBROLA_PATH environment variable if set, 91 or under a default path otherwise (see MBROLA_PATH in mbrolib.c). 92 93 An array of voices is returned. The last item is set to NULL. 94 The caller must not free the returned items or the array. 95 96 @param the_handle previously given by mbrolib_init. 97 98 @return An array of voices. 99*/ 100const mbrolib_voice ** mbrolib_list_voices( void* the_handle); 101typedef const mbrolib_voice ** (t_mbrolib_list_voices)(void*); 102 103 104 105/** Set voice 106 107 @param the_handle. 108 109 @param the_database (for example, "en1"). 110 111 @return error code (MBROLIB_OK, MBROLIB_DATABASE_NOT_INSTALLED, MBROLIB_INVAL). 112 113*/ 114MBROLIB_ERROR mbrolib_set_voice( void* the_handle, const char* the_name); 115typedef MBROLIB_ERROR (t_mbrolib_set_voice)( void*, const char*); 116 117 118 119/** Get the current database parameters. 120 The caller supplies a pointer to an already allocated structure. 121 122 @param the_handle previously given by mbrolib_init. 123 124 @param the_parameters: pointer to the structure. 125 126 @return error code (MBROLIB_OK, MBROLIB_INVAL). 127*/ 128MBROLIB_ERROR mbrolib_get_parameter(void* the_handle, mbrolib_parameter* the_parameter); 129typedef MBROLIB_ERROR (t_mbrolib_get_parameter)(void*, mbrolib_parameter*); 130 131 132 133/** Set the database parameters using the supplied data. 134 135 @param the_handle previously given by mbrolib_init. 136 137 @param the_parameters: pointer to the wished parameters. 138 139 @return error code (MBROLIB_OK, MBROLIB_INVAL). 140*/ 141MBROLIB_ERROR mbrolib_set_parameter(void* the_handle, const mbrolib_parameter* the_parameter); 142typedef MBROLIB_ERROR (t_mbrolib_set_parameter)(void*, const mbrolib_parameter*); 143 144 145 146/** Write the mbrola phonemes in the internal buffer. 147 148 @param the_handle. 149 150 @param the_mbrola_phonemes. 151 152 @param the_size in bytes. 153 154 @return error code (MBROLIB_OK, MBROLIB_INVAL, MBROLIB_WRITE_ERROR, MBROLIB_READ_ERROR). 155*/ 156MBROLIB_ERROR mbrolib_write(void* the_handle, const char* the_mbrola_phonemes, size_t the_size); 157typedef MBROLIB_ERROR (t_mbrolib_write)(void*, const char*, size_t); 158 159 160 161/** Read n bytes of the output samples. 162 163 @param the_handle. 164 165 @param the_samples (raw audio data, 16bits, mono). 166 167 @param the_size max number of int16 to read. 168 169 @param the_size number of int16 read. 170 171 @return error code (MBROLIB_OK, MBROLIB_INVAL, MBROLIB_READ_ERROR). 172 173*/ 174MBROLIB_ERROR mbrolib_read(void* the_handle, short* the_samples, int the_max_size, int* the_read_size); 175typedef MBROLIB_ERROR (t_mbrolib_read)(void*, short*, int, int*); 176 177 178 179/** Flush 180 181 @param the_handle. 182 183*/ 184void mbrolib_flush(void* the_handle); 185typedef void (t_mbrolib_flush)(void*); 186 187 188 189/** Release the handle 190 191 @param the_handle. 192 193 @return error code (MBROLIB_OK, MBROLIB_INVAL). 194 195*/ 196MBROLIB_ERROR mbrolib_terminate(void* the_handle); 197typedef MBROLIB_ERROR (t_mbrolib_terminate)(void*); 198 199 200 201#ifdef __cplusplus 202} 203#endif 204 205#endif