1 /* 2 * baratinoo.h - Shim for Baratinoo (VoxyGen) 3 * to be able to build the Baratinoo module without the Baratinoo SDK. 4 * 5 * Copyright (C) 2018 Hypra 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2, or (at your option) 10 * any later version. 11 * 12 * This software 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 GNU 15 * 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 <https://www.gnu.org/licenses/>. 19 */ 20 21 #include <stdarg.h> 22 23 typedef enum { 24 BARATINOO_ALL_PARSING, /* Proprietary parsing and XML parsing both activated */ 25 BARATINOO_NO_PARSING, /* No parsing at all */ 26 BARATINOO_PROPRIETARY_PARSING, /* Proprietary parsing only */ 27 BARATINOO_XML_PARSING /* XML parsing only */ 28 } BARATINOO_PARSING; 29 30 typedef enum { 31 /* Enum changed in 8.4. */ 32 33 /* BARATINOO_UTF8 is defined dynamically below, the 2 values below are 34 * just here to be excessively rigorous and make sure possible values are 35 * included in the enumeration */ 36 BARATINOO_UTF8__V8_1 = 11, 37 BARATINOO_UTF8__V8_4 = 13, 38 } BARATINOO_TEXT_ENCODING; 39 40 typedef enum { 41 BARATINOO_MARKER_EVENT, 42 BARATINOO_WAITMARKER_EVENT, 43 } BARATINOO_EVENT_TYPE; 44 45 typedef enum { 46 BARATINOO_UNINITIALIZED, 47 BARATINOO_INITIALIZED, 48 BARATINOO_READY, 49 BARATINOO_RUNNING, 50 BARATINOO_EVENT, 51 BARATINOO_INPUT_ERROR, 52 BARATINOO_ENGINE_ERROR 53 } BARATINOOC_STATE; 54 55 typedef enum 56 { 57 BARATINOO_INIT_OK, 58 BARATINOO_INIT_ERROR 59 } BARATINOO_INIT_RETURN; 60 61 typedef enum { 62 BARATINOO_TRACE_ERROR, 63 BARATINOO_TRACE_INIT, 64 BARATINOO_TRACE_WARNING, 65 BARATINOO_TRACE_INFO, 66 BARATINOO_TRACE_DEBUG 67 } BaratinooTraceLevel; 68 69 typedef void (*BaratinooTraceCB)(BaratinooTraceLevel level, int engineNumber, const char *source, const void *privatedata, const char *format, va_list args); 70 typedef int (*BaratinooOutputSignalCB)(void *privateData, const void *address, int length); 71 72 typedef void* BCengine; 73 typedef void* BCinputTextBuffer; 74 typedef void* BCoutputSignalBuffer; 75 76 typedef struct 77 { 78 int major; 79 int minor; 80 /* we don't care about possible extras */ 81 } BaratinooVersionStruct; 82 83 typedef struct { 84 BARATINOO_EVENT_TYPE type; 85 float timeStamp; /* millisecond unit */ 86 unsigned long byteStamp; /* byte unit */ 87 unsigned long sampleStamp; /* sample unit */ 88 union { 89 struct { 90 const char *name; 91 } marker; 92 struct { 93 const char *name; 94 float duration; /* millisecond unit */ 95 unsigned int samples; /* sample unit */ 96 } waitMarker; 97 struct { /* UTF-8 encoding */ 98 const char *tts; 99 const char *input; 100 } word; 101 struct { /* UTF-8 encoding */ 102 const char *tts; 103 const char *input; 104 } punctuation; 105 struct { /* UTF-8 encoding */ 106 const char *input; 107 } separator; 108 struct { 109 const char *symbol; 110 float duration; /* millisecond unit */ 111 unsigned int samples; /* sample unit */ 112 } phoneme; 113 /* viseme field is 8.4 and later, but doesn't affect union size */ 114 struct { 115 const char *name; 116 const char *language; 117 } newVoice; 118 struct { 119 int type; 120 int size; 121 const char *datas; 122 } raw; 123 } data; 124 } BaratinooEvent; 125 126 typedef struct { 127 const char *name; 128 const char *language; 129 const char *iso639; 130 const char *iso3166; 131 const char *variant; 132 const char *accent; 133 const char *gender; 134 const char *version; 135 const char *modules; 136 int age; 137 int expire_days; 138 } BaratinooVoiceInfo__V8_1; 139 typedef struct { 140 const char *name; 141 const char *language; 142 const char *iso639; 143 const char *iso3166; 144 const char *variant; 145 const char *accent; 146 const char *gender; 147 const char *version; 148 const char *speech_modes; 149 const char *modules; 150 int age; 151 int expire_days; 152 } BaratinooVoiceInfo__V8_4; 153 /* we use the biggest as default impl as we have to allocate it on the stack */ 154 typedef BaratinooVoiceInfo__V8_4 BaratinooVoiceInfo; 155 156 /* lib and version */ 157 extern BARATINOO_INIT_RETURN BCinitlib(BaratinooTraceCB traceCB); 158 extern void BCterminatelib(void); 159 extern const char *BCgetBaratinooVersion(void); 160 extern const BaratinooVersionStruct *BCgetBaratinooVersionStruct(void); 161 /* engine */ 162 extern BCengine BCnew(const void *privatedata); 163 extern void BCinit(BCengine engine, const char *config); 164 extern void BCdelete(BCengine engine); 165 extern BARATINOOC_STATE BCgetState(BCengine engine); 166 extern BARATINOOC_STATE BCprocessLoop(BCengine engine, int count); 167 extern BARATINOOC_STATE BCpurge(BCengine engine); 168 extern void BCsetWantedEvent(BCengine engine, BARATINOO_EVENT_TYPE type); 169 extern BaratinooEvent BCgetEvent(BCengine engine); 170 extern int BCgetNumberOfVoices(BCengine engine); 171 extern BaratinooVoiceInfo BCgetVoiceInfo(BCengine engine,int voiceNumber); 172 /* I/O */ 173 typedef enum 174 { 175 BARATINOO_PCM = 0, 176 } BARATINOO_SIGNAL_CODING; 177 178 extern BCinputTextBuffer BCinputTextBufferNew(BARATINOO_PARSING parsing, BARATINOO_TEXT_ENCODING encoding, int voiceIndex, char *voiceModules); 179 extern void BCinputTextBufferDelete(BCinputTextBuffer inputTextBuffer); 180 extern int BCinputTextBufferInit(BCinputTextBuffer inputTextBuffer, const char *text); 181 extern BARATINOOC_STATE BCinputTextBufferSetInEngine(BCinputTextBuffer inputTextBuffer, BCengine engine); 182 183 extern void BCsetOutputSignal(BCengine engine, BaratinooOutputSignalCB cb, void *privateData, BARATINOO_SIGNAL_CODING coding, int frequency); 184 extern BCoutputSignalBuffer BCoutputSignalBufferNew(BARATINOO_SIGNAL_CODING coding, int frequency); 185 extern void BCoutputSignalBufferDelete(BCoutputSignalBuffer outputSignalBuffer); 186 extern void BCoutputTextBufferSetInEngine(BCoutputSignalBuffer outputSignalBuffer, BCengine engine); 187 extern int BCoutputSignalBufferIsError(BCoutputSignalBuffer outputSignalBuffer); 188 extern char * BCoutputSignalBufferGetSignalBuffer(BCoutputSignalBuffer outputSignalBuffer); 189 extern int BCoutputSignalBufferGetSignalLength(BCoutputSignalBuffer outputSignalBuffer); 190 extern void BCoutputSignalBufferResetSignal(BCoutputSignalBuffer outputSignalBuffer); 191 192