• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /**
17  * @file picoapi.h
18  *
19  * SVOX Pico application programming interface
20  * (SVOX Pico version 1.0 and later)
21  *
22  * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
23  * All rights reserved.
24  *
25  * History:
26  * - 2009-04-20 -- initial version
27  */
28 
29 
30 /**
31  * @addtogroup picoapi
32  *
33 @b Basic_Concepts
34 
35 @e SVOX_Pico_System
36 
37 The SVOX Pico 'system' is the entity that manages data common to all
38 SVOX Pico engines, e.g. linguistic data needed to do text-to-speech
39 (TTS) synthesis, license key, etc.  All API functions on the Pico
40 system level take a 'pico_System' handle as the first parameter.
41 
42 @e SVOX_Pico_Engine
43 
44 A SVOX Pico 'engine' provides the functions needed to perform actual
45 synthesis. Currently there can be only one engine instance at a time
46 (concurrent engines will be possible in the future). All API functions
47 at the engine level take a 'pico_Engine' handle as the first
48 parameter.
49 
50 @e SVOX_Pico_Resource
51 
52 A SVOX Pico 'resource' denotes all the language- and speaker-dependent
53 data needed to do TTS synthesis. In the following, the term 'resource'
54 may be used interchangeably with the term 'lingware'. A resource file
55 contains a set of knowledge bases for an entire TTS voice or parts of
56 it.
57 
58 
59 @b Basic_Usage
60 
61 In its most basic form, an application must call the following
62 functions in order to perform TTS synthesis:
63 
64    - pico_initialize
65    - pico_loadResource
66    - pico_createVoiceDefinition
67    - pico_addResourceToVoiceDefinition
68    - pico_newEngine
69    - pico_putTextUtf8
70    - pico_getData (several times)
71    - pico_disposeEngine
72    - pico_releaseVoiceDefinition
73    - pico_unloadResource
74    - pico_terminate
75 
76 It is possible to repeatedly run the above sequence, i.e., the SVOX
77 Pico system may be initialized and terminated multiple times. This may
78 be useful in applications that need TTS functionality only from time
79 to time.
80 
81 
82 @b Conventions
83 
84 @e Function_arguments
85 
86 All arguments that only return values are marked by a leading 'out...'
87 in their name. All arguments that are used as input and output values
88 are marked by a leading 'inout...'. All other arguments are read-only
89 (input) arguments.
90 
91 @e Error_handling
92 
93 All API functions return a status code which is one of the status
94 constants defined in picodefs.h. In case of an error, a more detailed
95 description of the status can be retrieved by calling function
96 'pico_getSystemStatusMessage' (or 'pico_getEngineStatusMessage'
97 if the error happened on the SVOX Pico engine level).
98 
99 Unlike errors, warnings do not prevent an API function from performing
100 its function, but output might not be as intended. Functions
101 'pico_getNrSystemWarnings' and 'pico_getNrEngineWarnings' respectively
102 can be used to determine whether an API function caused any
103 warnings. Details about warnings can be retrieved by calling
104 'pico_getSystemWarning' and 'pico_getEngineWarning' respectively.
105 
106 */
107 
108 
109 
110 #ifndef PICOAPI_H_
111 #define PICOAPI_H_
112 
113 
114 
115 #include "picodefs.h"
116 
117 #ifdef __cplusplus
118 extern "C" {
119 #endif
120 #if 0
121 }
122 #endif
123 
124 
125 #ifdef _WIN32
126 #  define PICO_EXPORT  __declspec( dllexport )
127 #else
128 #  define PICO_EXPORT extern
129 #endif
130 
131 #define PICO_FUNC PICO_EXPORT pico_Status
132 
133 
134 
135 /* ********************************************************************/
136 /* PICO data types                                                    */
137 /* ********************************************************************/
138 
139 /* Handle types (opaque) for Pico system, resource, engine ************/
140 
141 typedef struct pico_system   *pico_System;
142 typedef struct pico_resource *pico_Resource;
143 typedef struct pico_engine   *pico_Engine;
144 
145 
146 /* Signed/unsigned integer data types *********************************/
147 
148 #define PICO_INT16_MAX   32767
149 #define PICO_UINT16_MAX  0xffff
150 #define PICO_INT32_MAX   2147483647
151 #define PICO_UINT32_MAX  0xffffffff
152 
153 #include <limits.h>
154 
155 #if (SHRT_MAX == PICO_INT16_MAX)
156 typedef short pico_Int16;
157 #else
158 #error "platform not supported"
159 #endif
160 
161 #if (USHRT_MAX == PICO_UINT16_MAX)
162 typedef unsigned short pico_Uint16;
163 #else
164 #error "platform not supported"
165 #endif
166 
167 #if (INT_MAX == PICO_INT32_MAX)
168 typedef int pico_Int32;
169 #else
170 #error "platform not supported"
171 #endif
172 
173 #if (UINT_MAX == PICO_UINT32_MAX)
174 typedef unsigned int pico_Uint32;
175 #else
176 #error "platform not supported"
177 #endif
178 
179 
180 /* Char data type *****************************************************/
181 
182 typedef unsigned char pico_Char;
183 
184 
185 /* String type to be used when ASCII string values are returned *******/
186 
187 #define PICO_RETSTRINGSIZE 200  /* maximum length of returned strings */
188 
189 typedef char pico_Retstring[PICO_RETSTRINGSIZE];
190 
191 
192 
193 /* ********************************************************************/
194 /* System-level API functions                                         */
195 /* ********************************************************************/
196 
197 /* System initialization and termination functions ********************/
198 
199 /**
200    Initializes the Pico system and returns its handle in 'outSystem'.
201    'memory' and 'size' define the location and maximum size of memory
202    in number of bytes that the Pico system will use. The minimum size
203    required depends on the number of engines and configurations of
204    lingware to be used. No additional memory will be allocated by the
205    Pico system. This function must be called before any other API
206    function is called. It may only be called once (e.g. at application
207    startup), unless a call to 'pico_terminate'.
208 */
209 PICO_FUNC pico_initialize(
210         void *memory,
211         const pico_Uint32 size,
212         pico_System *outSystem
213         );
214 
215 /**
216    Terminates the Pico system. Lingware resources still being loaded
217    are unloaded automatically. The memory area provided to Pico in
218    'pico_initialize' is released. The system handle becomes
219    invalid. It is not allowed to call this function as long as Pico
220    engine instances are existing. No API function may be called after
221    this function, except for 'pico_initialize', which reinitializes
222    the system.
223 */
224 PICO_FUNC pico_terminate(
225         pico_System *system
226         );
227 
228 
229 /* System status and error/warning message retrieval ******************/
230 
231 /**
232    Returns in 'outMessage' a description of the system status or of an
233    error that occurred with the most recently called system-level API
234    function.
235 */
236 PICO_FUNC pico_getSystemStatusMessage(
237         pico_System system,
238         pico_Status errCode,
239         pico_Retstring outMessage
240         );
241 
242 /**
243    Returns in 'outNrOfWarnings' the number of warnings that occurred
244    with the most recently called system-level API function.
245 */
246 PICO_FUNC pico_getNrSystemWarnings(
247         pico_System system,
248         pico_Int32 *outNrOfWarnings
249         );
250 
251 /**
252    Returns in 'outMessage' a description of a warning that occurred
253    with the most recently called system-level API function.
254    'warningIndex' must be in the range 0..N-1 where N is the number of
255    warnings returned by 'pico_getNrSystemWarnings'. 'outCode' returns
256    the warning as an integer code (cf. PICO_WARN_*).
257 */
258 PICO_FUNC pico_getSystemWarning(
259         pico_System system,
260         const pico_Int32 warningIndex,
261         pico_Status *outCode,
262         pico_Retstring outMessage
263         );
264 
265 
266 /* Resource loading and unloading functions ***************************/
267 
268 /**
269    Loads a resource file into the Pico system. The number of resource
270    files loaded in parallel is limited by PICO_MAX_NUM_RESOURCES.
271    Loading of a resource file may be done at any time (even in
272    parallel to a running engine doing TTS synthesis), but with the
273    general restriction that functions taking a system handle as their
274    first argument must be called in a mutually exclusive fashion. The
275    loaded resource will be available only to engines started after the
276    resource is fully loaded, i.e., not to engines currently
277    running.
278 */
279 PICO_FUNC pico_loadResource(
280         pico_System system,
281         const pico_Char *resourceFileName,
282         pico_Resource *outResource
283         );
284 
285 /**
286    Unloads a resource file from the Pico system. If no engine uses the
287    resource file, the resource is removed immediately and its
288    associated internal memory is released, otherwise
289    PICO_EXC_RESOURCE_BUSY is returned.
290 */
291 PICO_FUNC pico_unloadResource(
292         pico_System system,
293         pico_Resource *inoutResource
294         );
295 
296 /* *** Resource inspection functions *******************************/
297 
298 /**
299  Gets the unique resource name of a loaded resource
300 */
301 PICO_FUNC pico_getResourceName(
302         pico_System system,
303         pico_Resource resource,
304         pico_Retstring outName);
305 
306 
307 /* Voice definition ***************************************************/
308 
309 /**
310    Creates a voice definition. Resources must be added to the created
311    voice with 'pico_addResourceToVoiceDefinition' before using the
312    voice in 'pico_newEngine'. It is an error to create a voice
313    definition with a previously defined voice name. In that case use
314    'pico_releaseVoiceName' first.
315 */
316 PICO_FUNC pico_createVoiceDefinition(
317         pico_System system,
318         const pico_Char *voiceName
319         );
320 
321 /**
322    Adds a mapping pair ('voiceName', 'resourceName') to the voice
323    definition. Multiple mapping pairs can added to a voice defintion.
324    When calling 'pico_newEngine' with 'voiceName', the corresponding
325    resources from the mappings will be used with that engine. */
326 
327 PICO_FUNC pico_addResourceToVoiceDefinition(
328         pico_System system,
329         const pico_Char *voiceName,
330         const pico_Char *resourceName
331         );
332 
333 
334 /**
335   Releases the voice definition 'voiceName'.
336 
337 */
338 PICO_FUNC pico_releaseVoiceDefinition(
339         pico_System system,
340         const pico_Char *voiceName
341         );
342 
343 
344 /* Engine creation and deletion functions *****************************/
345 
346 /**
347    Creates and initializes a new Pico engine instance and returns its
348    handle in 'outEngine'. Only one instance per system is currently
349    possible.
350 */
351 PICO_FUNC pico_newEngine(
352         pico_System system,
353         const pico_Char *voiceName,
354         pico_Engine *outEngine
355         );
356 
357 
358 /**
359  Disposes a Pico engine and releases all memory it occupied. The
360  engine handle becomes invalid.
361 */
362 PICO_FUNC pico_disposeEngine(
363         pico_System system,
364         pico_Engine *inoutEngine
365         );
366 
367 
368 
369 /* ********************************************************************/
370 /* Engine-level API functions                                         */
371 /* ********************************************************************/
372 
373 /**
374    Puts text 'text' encoded in UTF8 into the Pico text input buffer.
375    'textSize' is the maximum size in number of bytes accessible in
376    'text'. The input text may also contain text-input commands to
377    change, for example, speed or pitch of the resulting speech
378    output. The number of bytes actually copied to the Pico text input
379    buffer is returned in 'outBytesPut'. Sentence ends are
380    automatically detected. '\0' characters may be embedded in 'text'
381    to finish text input or separate independently to be synthesized
382    text parts from each other. Repeatedly calling 'pico_getData' will
383    result in the content of the text input buffer to be synthesized
384    (up to the last sentence end or '\0' character detected). To empty
385    the internal buffers without finishing synthesis, use the function
386    'pico_resetEngine'.
387 */
388 PICO_FUNC pico_putTextUtf8(
389         pico_Engine engine,
390         const pico_Char *text,
391         const pico_Int16 textSize,
392         pico_Int16 *outBytesPut
393         );
394 
395 /**
396    Gets speech data from the engine. Every time this function is
397    called, the engine performs, within a short time slot, a small
398    amount of processing its input text, and then gives control back to
399    the calling application. Ie. after calling 'pico_putTextUtf8'
400    (incl. a final embedded '\0'), this function needs to be called
401    repeatedly till 'outBytesReceived' bytes are returned in
402    'outBuffer'. The type of data returned in 'outBuffer' (e.g. 8 or 16
403    bit PCM samples) is returned in 'outDataType' and depends on the
404    lingware resources. Possible 'outDataType' values are listed in
405    picodefs.h (PICO_DATA_*).
406    This function returns PICO_STEP_BUSY while processing input and
407    producing speech output. Once all data is returned and there is no
408    more input text available in the Pico text input buffer,
409    PICO_STEP_IDLE is returned.  All other function return values
410    indicate a system error.
411 */
412 PICO_FUNC pico_getData(
413         pico_Engine engine,
414         void *outBuffer,
415         const pico_Int16 bufferSize,
416         pico_Int16 *outBytesReceived,
417         pico_Int16 *outDataType
418         );
419 
420 /**
421    Resets the engine and clears all engine-internal buffers, in
422    particular text input and signal data output buffers.
423    'resetMode' is one of 'PICO_RESET_SOFT', to be used to flush the engine,
424    or 'PICO_RESET_FULL', to reset the engine after an engine error.
425 */
426 PICO_FUNC pico_resetEngine(
427         pico_Engine engine,
428         pico_Int32 resetMode
429 );
430 
431 
432 /* Engine status and error/warning message retrieval ******************/
433 
434 /**
435    Returns in 'outMessage' a description of the engine status or of an
436    error that occurred with the most recently called engine-level API
437    function.
438 */
439 PICO_FUNC pico_getEngineStatusMessage(
440         pico_Engine engine,
441         pico_Status errCode,
442         pico_Retstring outMessage
443         );
444 
445 /**
446    Returns in 'outNrOfWarnings' the number of warnings that occurred
447    with the most recently called engine-level API function.
448 */
449 PICO_FUNC pico_getNrEngineWarnings(
450         pico_Engine engine,
451         pico_Int32 *outNrOfWarnings
452         );
453 
454 /**
455    Returns in 'outMessage' a description of a warning that occurred
456    with the most recently called engine-level API function.
457    'warningIndex' must be in the range 0..N-1 where N is the number of
458    warnings returned by 'pico_getNrEngineWarnings'. 'outCode' returns
459    the warning as an integer code (cf. PICO_WARN_*).
460 */
461 PICO_FUNC pico_getEngineWarning(
462         pico_Engine engine,
463         const pico_Int32 warningIndex,
464         pico_Status *outCode,
465         pico_Retstring outMessage
466         );
467 
468 #ifdef __cplusplus
469 }
470 #endif
471 
472 #endif /*PICOAPI_H_*/
473