Jean-Michel Trivi | c710457 | 2009-05-21 15:32:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Google Inc. |
| 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 | #include <media/AudioSystem.h> |
| 17 | |
| 18 | // This header defines the interface used by the Android platform |
| 19 | // to access Text-To-Speech functionality in shared libraries that implement speech |
| 20 | // synthesis and the management of resources associated with the synthesis. |
| 21 | // An example of the implementation of this interface can be found in |
| 22 | // FIXME: add path+name to implementation of default TTS engine |
| 23 | // Libraries implementing this interface are used in: |
| 24 | // frameworks/base/tts/jni/android_tts_SpeechSynthesis.cpp |
| 25 | |
| 26 | namespace android { |
| 27 | |
Charles Chen | a17cef0 | 2009-06-05 13:58:33 -0700 | [diff] [blame] | 28 | enum tts_synth_status { |
| 29 | TTS_SYNTH_DONE = 0, |
| 30 | TTS_SYNTH_PENDING = 1 |
| 31 | }; |
| 32 | |
| 33 | enum tts_callback_status { |
| 34 | TTS_CALLBACK_HALT = 0, |
| 35 | TTS_CALLBACK_CONTINUE = 1 |
| 36 | }; |
| 37 | |
Jean-Michel Trivi | c710457 | 2009-05-21 15:32:11 -0700 | [diff] [blame] | 38 | // The callback is used by the implementation of this interface to notify its |
| 39 | // client, the Android TTS service, that the last requested synthesis has been |
Charles Chen | a17cef0 | 2009-06-05 13:58:33 -0700 | [diff] [blame] | 40 | // completed. // TODO reword |
Jean-Michel Trivi | c710457 | 2009-05-21 15:32:11 -0700 | [diff] [blame] | 41 | // The callback for synthesis completed takes: |
Charles Chen | a17cef0 | 2009-06-05 13:58:33 -0700 | [diff] [blame] | 42 | // [inout] void *& - The userdata pointer set in the original synth call |
| 43 | // [in] uint32_t - Track sampling rate in Hz |
| 44 | // [in] audio_format - The AudioSystem::audio_format enum |
| 45 | // [in] int - The number of channels |
| 46 | // [inout] int8_t *& - A buffer of audio data only valid during the execution of the callback |
| 47 | // [inout] size_t & - The size of the buffer |
| 48 | // [in] tts_synth_status - Status of the synthesis; 0 for done, 1 for more data to be synthesized. |
| 49 | // Returns the status of the consumer of the synthesis. 0 for stop, 1 for continue. |
| 50 | typedef tts_callback_status (synthDoneCB_t)(void *&, uint32_t, AudioSystem::audio_format, int, int8_t *&, size_t&, tts_synth_status); |
Jean-Michel Trivi | c710457 | 2009-05-21 15:32:11 -0700 | [diff] [blame] | 51 | |
| 52 | class TtsEngine; |
| 53 | extern "C" TtsEngine* getTtsEngine(); |
| 54 | |
| 55 | enum tts_result { |
| 56 | TTS_SUCCESS = 0, |
| 57 | TTS_FAILURE = -1, |
| 58 | TTS_FEATURE_UNSUPPORTED = -2, |
| 59 | TTS_VALUE_INVALID = -3, |
| 60 | TTS_PROPERTY_UNSUPPORTED = -4, |
Jean-Michel Trivi | 8d336f9 | 2009-05-28 11:11:25 -0700 | [diff] [blame] | 61 | TTS_PROPERTY_SIZE_TOO_SMALL = -5, |
| 62 | TTS_MISSING_RESOURCES = -6 |
Jean-Michel Trivi | c710457 | 2009-05-21 15:32:11 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | class TtsEngine |
| 66 | { |
| 67 | public: |
| 68 | // Initialize the TTS engine and returns whether initialization succeeded. |
| 69 | // @param synthDoneCBPtr synthesis callback function pointer |
| 70 | // @return TTS_SUCCESS, or TTS_FAILURE |
| 71 | virtual tts_result init(synthDoneCB_t synthDoneCBPtr); |
| 72 | |
| 73 | // Shut down the TTS engine and releases all associated resources. |
| 74 | // @return TTS_SUCCESS, or TTS_FAILURE |
| 75 | virtual tts_result shutdown(); |
| 76 | |
| 77 | // Interrupt synthesis and flushes any synthesized data that hasn't been output yet. |
| 78 | // This will block until callbacks underway are completed. |
| 79 | // @return TTS_SUCCESS, or TTS_FAILURE |
| 80 | virtual tts_result stop(); |
| 81 | |
| 82 | // Load the resources associated with the specified language. The loaded language will |
| 83 | // only be used once a call to setLanguage() with the same language value is issued. |
| 84 | // Language values are based on the Android conventions for localization as described in |
| 85 | // the Android platform documentation on internationalization. This implies that language |
| 86 | // data is specified in the format xx-rYY, where xx is a two letter ISO 639-1 language code |
| 87 | // in lowercase and rYY is a two letter ISO 3166-1-alpha-2 language code in uppercase |
| 88 | // preceded by a lowercase "r". |
| 89 | // @param value pointer to the language value |
| 90 | // @param size length of the language value |
| 91 | // @return TTS_SUCCESS, or TTS_FAILURE |
| 92 | virtual tts_result loadLanguage(const char *value, const size_t size); |
| 93 | |
| 94 | // Signal the engine to use the specified language. This will force the language to be |
| 95 | // loaded if it wasn't loaded previously with loadLanguage(). |
| 96 | // See loadLanguage for the specification of the language. |
| 97 | // @param value pointer to the language value |
| 98 | // @param size length of the language value |
| 99 | // @return TTS_SUCCESS, or TTS_FAILURE |
| 100 | virtual tts_result setLanguage(const char *value, const size_t size); |
| 101 | |
| 102 | // Retrieve the currently set language, or an empty "value" if no language has |
| 103 | // been set. |
| 104 | // @param[out] value pointer to the retrieved language value |
| 105 | // @param[inout] iosize in: stores the size available to store the language value in *value |
| 106 | // out: stores the size required to hold the language value if |
| 107 | // getLanguage() returned TTS_PROPERTY_SIZE_TOO_SMALL, |
| 108 | // unchanged otherwise. |
| 109 | // @return TTS_SUCCESS, or TTS_PROPERTY_SIZE_TOO_SMALL, or TTS_FAILURE |
| 110 | virtual tts_result getLanguage(char *value, size_t *iosize); |
| 111 | |
| 112 | // Set a property for the the TTS engine |
| 113 | // "size" is the maximum size of "value" for properties "property" |
| 114 | // @param property pointer to the property name |
| 115 | // @param value pointer to the property value |
| 116 | // @param size maximum size required to store this type of property |
| 117 | // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS, or TTS_FAILURE, |
| 118 | // or TTS_VALUE_INVALID |
| 119 | virtual tts_result setProperty(const char *property, const char *value, const size_t size); |
| 120 | |
| 121 | // Retrieve a property from the TTS engine |
| 122 | // @param property pointer to the property name |
| 123 | // @param[out] value pointer to the retrieved language value |
| 124 | // @param[inout] iosize in: stores the size available to store the property value |
| 125 | // out: stores the size required to hold the language value if |
| 126 | // getLanguage() returned TTS_PROPERTY_SIZE_TOO_SMALL, |
| 127 | // unchanged otherwise. |
| 128 | // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS, or TTS_PROPERTY_SIZE_TOO_SMALL |
| 129 | virtual tts_result getProperty(const char *property, char *value, size_t *iosize); |
| 130 | |
| 131 | // Synthesize the text. |
| 132 | // When synthesis completes, the engine invokes the callback to notify the TTS framework. |
| 133 | // Note about the format of the input: the text parameter may use the following elements |
| 134 | // and their respective attributes as defined in the SSML 1.0 specification: |
| 135 | // * lang |
| 136 | // * say-as: |
| 137 | // o interpret-as |
| 138 | // * phoneme |
| 139 | // * voice: |
| 140 | // o gender, |
| 141 | // o age, |
| 142 | // o variant, |
| 143 | // o name |
| 144 | // * emphasis |
| 145 | // * break: |
| 146 | // o strength, |
| 147 | // o time |
| 148 | // * prosody: |
| 149 | // o pitch, |
| 150 | // o contour, |
| 151 | // o range, |
| 152 | // o rate, |
| 153 | // o duration, |
| 154 | // o volume |
| 155 | // * mark |
| 156 | // Differences between this text format and SSML are: |
| 157 | // * full SSML documents are not supported |
| 158 | // * namespaces are not supported |
| 159 | // Text is coded in UTF-8. |
| 160 | // @param text the UTF-8 text to synthesize |
| 161 | // @param userdata pointer to be returned when the call is invoked |
| 162 | // @return TTS_SUCCESS or TTS_FAILURE |
Charles Chen | a17cef0 | 2009-06-05 13:58:33 -0700 | [diff] [blame] | 163 | virtual tts_result synthesizeText(const char *text, int8_t *buffer, size_t bufferSize, void *userdata); |
Jean-Michel Trivi | c710457 | 2009-05-21 15:32:11 -0700 | [diff] [blame] | 164 | |
| 165 | // Synthesize IPA text. When synthesis completes, the engine must call the given callback to notify the TTS API. |
| 166 | // @param ipa the IPA data to synthesize |
| 167 | // @param userdata pointer to be returned when the call is invoked |
| 168 | // @return TTS_FEATURE_UNSUPPORTED if IPA is not supported, otherwise TTS_SUCCESS or TTS_FAILURE |
Charles Chen | a17cef0 | 2009-06-05 13:58:33 -0700 | [diff] [blame] | 169 | virtual tts_result synthesizeIpa(const char *ipa, int8_t *buffer, size_t bufferSize, void *userdata); |
Jean-Michel Trivi | c710457 | 2009-05-21 15:32:11 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | } // namespace android |
| 173 | |