1e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh/*
2e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * Copyright (C) 2009 Google Inc.
3e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh *
4e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * Licensed under the Apache License, Version 2.0 (the "License");
5e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * you may not use this file except in compliance with the License.
6e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * You may obtain a copy of the License at
7e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh *
8e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh *      http://www.apache.org/licenses/LICENSE-2.0
9e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh *
10e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * Unless required by applicable law or agreed to in writing, software
11e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * distributed under the License is distributed on an "AS IS" BASIS,
12e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * See the License for the specific language governing permissions and
14e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * limitations under the License.
15e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh */
16e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#ifndef ANDROID_TTS_H
17e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#define ANDROID_TTS_H
18e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
19e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// This header defines the interface used by the Android platform
20e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// to access Text-To-Speech functionality in shared libraries that implement
21e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// speech synthesis and the management of resources associated with the
22e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// synthesis.
23e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
24e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// The shared library must contain a function named "android_getTtsEngine"
25e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// that returns an 'android_tts_engine_t' instance.
26e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
27e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#ifdef __cplusplus
28e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehextern "C" {
29e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#endif
30e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
31a1ec217d9be90f989de16aaff2584688e374dc3fAndrew Hsieh#include <stdint.h>
32a1ec217d9be90f989de16aaff2584688e374dc3fAndrew Hsieh
33e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#define ANDROID_TTS_ENGINE_PROPERTY_CONFIG "engineConfig"
34e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#define ANDROID_TTS_ENGINE_PROPERTY_PITCH  "pitch"
35e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#define ANDROID_TTS_ENGINE_PROPERTY_RATE   "rate"
36e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#define ANDROID_TTS_ENGINE_PROPERTY_VOLUME "volume"
37e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
38e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef enum {
39e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_SUCCESS                 = 0,
40e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_FAILURE                 = -1,
41e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_FEATURE_UNSUPPORTED     = -2,
42e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_VALUE_INVALID           = -3,
43e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_PROPERTY_UNSUPPORTED    = -4,
44e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_PROPERTY_SIZE_TOO_SMALL = -5,
45e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_MISSING_RESOURCES       = -6
46e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh} android_tts_result_t;
47e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
48e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef enum {
49e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_LANG_COUNTRY_VAR_AVAILABLE = 2,
50e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_LANG_COUNTRY_AVAILABLE    = 1,
51e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_LANG_AVAILABLE            = 0,
52e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_LANG_MISSING_DATA         = -1,
53e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_LANG_NOT_SUPPORTED        = -2
54e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh} android_tts_support_result_t;
55e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
56e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef enum {
57e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_SYNTH_DONE              = 0,
58e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_SYNTH_PENDING           = 1
59e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh} android_tts_synth_status_t;
60e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
61e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef enum {
62e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_CALLBACK_HALT           = 0,
63e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_CALLBACK_CONTINUE       = 1
64e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh} android_tts_callback_status_t;
65e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
66e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// Supported audio formats
67e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef enum {
68e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_AUDIO_FORMAT_INVALID    = -1,
69e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_AUDIO_FORMAT_DEFAULT    = 0,
70e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_AUDIO_FORMAT_PCM_16_BIT = 1,
71e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    ANDROID_TTS_AUDIO_FORMAT_PCM_8_BIT  = 2,
72e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh} android_tts_audio_format_t;
73e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
74e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
75e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh/* An android_tts_engine_t object can be anything, but must have,
76e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * as its first field, a pointer to a table of functions.
77e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh *
78e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * See the full definition of struct android_tts_engine_t_funcs_t
79e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * below for details.
80e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh */
81e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef struct android_tts_engine_funcs_t  android_tts_engine_funcs_t;
82e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
83e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef struct {
84e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_engine_funcs_t *funcs;
85e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh} android_tts_engine_t;
86e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
87e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh/* This function must be located in the TTS Engine shared library
88e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * and must return the address of an android_tts_engine_t library.
89e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh */
90e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehextern android_tts_engine_t *android_getTtsEngine();
91e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
92e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh/* Including the old version for legacy support (Froyo compatibility).
93e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh * This should return the same thing as android_getTtsEngine.
94e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh */
95a1ec217d9be90f989de16aaff2584688e374dc3fAndrew Hsiehandroid_tts_engine_t *getTtsEngine();
96e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
97e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// A callback type used to notify the framework of new synthetized
98e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// audio samples, status will be SYNTH_DONE for the last sample of
99e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// the last request, of SYNTH_PENDING otherwise.
100e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//
101e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// This is passed by the framework to the engine through the
102e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// 'engine_init' function (see below).
103e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//
104e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// The callback for synthesis completed takes:
105e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @param [inout] void *&       - The userdata pointer set in the original
106e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//                                 synth call
107e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @param [in]    uint32_t      - Track sampling rate in Hz
108e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @param [in]    uint32_t      - The audio format
109e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @param [in]    int           - The number of channels
110e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @param [inout] int8_t *&     - A buffer of audio data only valid during the
111e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//                                execution of the callback
112e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @param [inout] size_t  &     - The size of the buffer
113e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @param [in] tts_synth_status - indicate whether the synthesis is done, or
114e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//                                 if more data is to be synthesized.
115e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// @return TTS_CALLBACK_HALT to indicate the synthesis must stop,
116e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//         TTS_CALLBACK_CONTINUE to indicate the synthesis must continue if
117e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//            there is more data to produce.
118e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehtypedef android_tts_callback_status_t (*android_tts_synth_cb_t)
119e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void **pUserData,
120e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             uint32_t trackSamplingHz,
121e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             android_tts_audio_format_t audioFormat,
122e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             int channelCount,
123e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             int8_t **pAudioBuffer,
124e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             size_t *pBufferSize,
125e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             android_tts_synth_status_t status);
126e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
127e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
128e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// The table of function pointers that the android_tts_engine_t must point to.
129e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// Note that each of these functions will take a handle to the engine itself
130e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh// as their first parameter.
131e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh//
132e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
133e02e042b38d282df98814709a68d40cbcf614216Andrew Hsiehstruct android_tts_engine_funcs_t {
134e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // reserved fields, ignored by the framework
135e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // they must be placed here to ensure binary compatibility
136e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // of legacy binary plugins.
137e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    void *reserved[2];
138e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
139e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Initialize the TTS engine and returns whether initialization succeeded.
140e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param synthDoneCBPtr synthesis callback function pointer
141e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_SUCCESS, or TTS_FAILURE
142e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*init)
143e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
144e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             android_tts_synth_cb_t synthDonePtr,
145e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *engineConfig);
146e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
147e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Shut down the TTS engine and releases all associated resources.
148e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_SUCCESS, or TTS_FAILURE
149e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*shutdown)
150e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine);
151e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
152e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Interrupt synthesis and flushes any synthesized data that hasn't been
153e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // output yet. This will block until callbacks underway are completed.
154e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_SUCCESS, or TTS_FAILURE
155e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*stop)
156e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine);
157e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
158e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Returns the level of support for the language, country and variant.
159e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_LANG_COUNTRY_VAR_AVAILABLE if the language, country and variant are supported,
160e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //            and the corresponding resources are correctly installed
161e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //         TTS_LANG_COUNTRY_AVAILABLE if the language and country are supported and the
162e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //             corresponding resources are correctly installed, but there is no match for
163e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //             the specified variant
164e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //         TTS_LANG_AVAILABLE if the language is supported and the
165e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //             corresponding resources are correctly installed, but there is no match for
166e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //             the specified country and variant
167e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //         TTS_LANG_MISSING_DATA if the required resources to provide any level of support
168e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //             for the language are not correctly installed
169e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //         TTS_LANG_NOT_SUPPORTED if the language is not supported by the TTS engine.
170e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_support_result_t (*isLanguageAvailable)
171e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
172e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *lang,
173e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *country,
174e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *variant);
175e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
176e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Load the resources associated with the specified language. The loaded
177e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // language will only be used once a call to setLanguage() with the same
178e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // language value is issued. Language and country values are coded according to the ISO three
179e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // letter codes for languages and countries, as can be retrieved from a java.util.Locale
180e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // instance. The variant value is encoded as the variant string retrieved from a
181e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // java.util.Locale instance built with that variant data.
182e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param lang pointer to the ISO three letter code for the language
183e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param country pointer to the ISO three letter code for the country
184e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param variant pointer to the variant code
185e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_SUCCESS, or TTS_FAILURE
186e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*loadLanguage)
187e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
188e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *lang,
189e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *country,
190e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *variant);
191e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
192e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Load the resources associated with the specified language, country and Locale variant.
193e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // The loaded language will only be used once a call to setLanguageFromLocale() with the same
194e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // language value is issued. Language and country values are coded according to the ISO three
195e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // letter codes for languages and countries, as can be retrieved from a java.util.Locale
196e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // instance. The variant value is encoded as the variant string retrieved from a
197e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // java.util.Locale instance built with that variant data.
198e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param lang pointer to the ISO three letter code for the language
199e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param country pointer to the ISO three letter code for the country
200e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param variant pointer to the variant code
201e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_SUCCESS, or TTS_FAILURE
202e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*setLanguage)
203e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
204e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *lang,
205e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *country,
206e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *variant);
207e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
208e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Retrieve the currently set language, country and variant, or empty strings if none of
209e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // parameters have been set. Language and country are represented by their 3-letter ISO code
210e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[out]   pointer to the retrieved 3-letter code language value
211e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[out]   pointer to the retrieved 3-letter code country value
212e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[out]   pointer to the retrieved variant value
213e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_SUCCESS, or TTS_FAILURE
214e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*getLanguage)
215e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
216e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             char *language,
217e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             char *country,
218e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             char *variant);
219e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
220e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Notifies the engine what audio parameters should be used for the synthesis.
221e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // This is meant to be used as a hint, the engine implementation will set the output values
222e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // to those of the synthesis format, based on a given hint.
223e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[inout] encoding in: the desired audio sample format
224e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                         out: the format used by the TTS engine
225e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[inout] rate in: the desired audio sample rate
226e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                         out: the sample rate used by the TTS engine
227e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[inout] channels in: the desired number of audio channels
228e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                         out: the number of channels used by the TTS engine
229e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_SUCCESS, or TTS_FAILURE
230e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*setAudioFormat)
231e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
232e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             android_tts_audio_format_t* pEncoding,
233e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             uint32_t* pRate,
234e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             int* pChannels);
235e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
236e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Set a property for the the TTS engine
237e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // "size" is the maximum size of "value" for properties "property"
238e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param property pointer to the property name
239e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param value    pointer to the property value
240e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param size     maximum size required to store this type of property
241e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return         TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS, or TTS_FAILURE,
242e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                  or TTS_VALUE_INVALID
243e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*setProperty)
244e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
245e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *property,
246e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *value,
247e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const size_t size);
248e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
249e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Retrieve a property from the TTS engine
250e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param        property pointer to the property name
251e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[out]   value    pointer to the retrieved language value
252e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param[inout] iosize   in: stores the size available to store the
253e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                          property value.
254e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                        out: stores the size required to hold the language
255e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                          value if getLanguage() returned
256e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //                          TTS_PROPERTY_SIZE_TOO_SMALL, unchanged otherwise
257e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS,
258e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //         or TTS_PROPERTY_SIZE_TOO_SMALL
259e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*getProperty)
260e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
261e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *property,
262e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             char *value,
263e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             size_t *iosize);
264e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
265e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Synthesize the text.
266e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // As the synthesis is performed, the engine invokes the callback to notify
267e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // the TTS framework that it has filled the given buffer, and indicates how
268e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // many bytes it wrote. The callback is called repeatedly until the engine
269e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // has generated all the audio data corresponding to the text.
270e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Note about the format of the input: the text parameter may use the
271e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // following elements
272e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // and their respective attributes as defined in the SSML 1.0 specification:
273e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * lang
274e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * say-as:
275e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o interpret-as
276e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * phoneme
277e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * voice:
278e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o gender,
279e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o age,
280e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o variant,
281e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o name
282e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * emphasis
283e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * break:
284e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o strength,
285e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o time
286e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * prosody:
287e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o pitch,
288e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o contour,
289e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o range,
290e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o rate,
291e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o duration,
292e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //          o volume
293e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * mark
294e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Differences between this text format and SSML are:
295e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * full SSML documents are not supported
296e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    //    * namespaces are not supported
297e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // Text is coded in UTF-8.
298e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param text      the UTF-8 text to synthesize
299e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param userdata  pointer to be returned when the call is invoked
300e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param buffer    the location where the synthesized data must be written
301e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @param bufferSize the number of bytes that can be written in buffer
302e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    // @return          TTS_SUCCESS or TTS_FAILURE
303e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh    android_tts_result_t (*synthesizeText)
304e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh            (void *engine,
305e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             const char *text,
306e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             int8_t *buffer,
307e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             size_t bufferSize,
308e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh             void *userdata);
309e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh};
310e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
311e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#ifdef __cplusplus
312e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh}
313e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#endif
314e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh
315e02e042b38d282df98814709a68d40cbcf614216Andrew Hsieh#endif /* ANDROID_TTS_H */
316