PageRenderTime 32ms CodeModel.GetById 16ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/PlaceHolderTTSEngine/native/project/jni/com_google_placeHolderTTSEngine.cpp

http://eyes-free.googlecode.com/
C++ | 230 lines | 125 code | 44 blank | 61 comment | 17 complexity | baf009fe0b0804ac2c851d53ed5fb7d0 MD5 | raw file
  1/*
  2 * Copyright (C) 2008 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
 17#include <stdio.h>
 18#include <string.h>
 19#include <unistd.h>
 20
 21#define LOG_TAG "PlaceHolder TTS Engine"
 22
 23//#include <utils/Log.h>
 24//#include <android_runtime/AndroidRuntime.h>
 25//#include <speak_lib.h>
 26#include <tts/TtsEngine.h>
 27#include <PlaceHolderTTS.h>
 28
 29#if 0
 30  #define LOGI(...) printf(__VA_ARGS__)
 31  #define LOGE(...) frintf(stderr, __VA_ARGS__)
 32#else
 33  #define LOGI(...)
 34  #define LOGE(...)
 35#endif
 36
 37namespace android {
 38
 39static const char *MY_LANGUAGE = "en";
 40
 41// Callback to the TTS API
 42static synthDoneCB_t* ttsSynthDoneCBPointer;
 43
 44/* Functions exposed to the TTS API */
 45
 46// Initializes the TTS engine and returns whether initialization succeeded
 47tts_result TtsEngine::init(synthDoneCB_t synthDoneCBPtr)
 48{
 49    LOGI("TtsEngine::init");
 50    ttsSynthDoneCBPointer = synthDoneCBPtr;
 51    PlaceHolderTTS_Init();
 52    return TTS_SUCCESS;
 53}
 54
 55// Shutsdown the TTS engine
 56tts_result TtsEngine::shutdown( void )
 57{
 58    LOGI("TtsEngine::shutdown");
 59    return TTS_SUCCESS;
 60}
 61
 62
 63tts_result TtsEngine::loadLanguage(const char *lang, const char *country, const char *variant)
 64{
 65    LOGI("TtsEngine::loadLanguage: lang=%s, country=%s, variant=%s", lang, country, variant);
 66    return TTS_FAILURE;
 67}
 68
 69// Language will be specified according to the Android conventions for
 70// localization as documented here:
 71// http://developer.android.com/guide/topics/resources/resources-i18n.html
 72//
 73// language will be a string of the form "xx" or "xx-rYY", where xx is a
 74// two letter ISO 639-1 language code in lowercase and rYY is a two letter ISO
 75// 3166-1-alpha-2 language code in uppercase preceded by a lowercase "r".
 76// Note that the "-rYY" portion may be omitted if the region is unimportant.
 77//
 78tts_result TtsEngine::setLanguage( const char * lang, const char * country, const char * variant )
 79{
 80    LOGI("TtsEngine::setLanguage: lang=%s, country=%s, variant=%s", lang, country, variant);
 81    return strcmp(lang, MY_LANGUAGE) == 0 ? TTS_SUCCESS : TTS_FAILURE;
 82}
 83
 84
 85tts_support_result TtsEngine::isLanguageAvailable(const char *lang, const char *country,
 86            const char *variant) {
 87    LOGI("TtsEngine::isLanguageAvailable: lang=%s, country=%s, variant=%s", lang, country, variant);
 88    return strcmp(lang, MY_LANGUAGE) == 0 ? TTS_LANG_AVAILABLE : TTS_LANG_NOT_SUPPORTED;
 89}
 90
 91tts_result TtsEngine::getLanguage(char *language, char *country, char *variant)
 92{
 93    LOGI("TtsEngine::getLanguage");
 94    strcpy(language, MY_LANGUAGE);
 95    strcpy(country, "");
 96    strcpy(variant, "");
 97    return TTS_SUCCESS;
 98}
 99
100
101/** setAudioFormat
102 * sets the audio format to use for synthesis, returns what is actually used.
103 * @encoding - reference to encoding format
104 * @rate - reference to sample rate
105 * @channels - reference to number of channels
106 * return tts_result
107 * */
108tts_result TtsEngine::setAudioFormat(AudioSystem::audio_format& encoding, uint32_t& rate,
109            int& channels)
110{
111    LOGI("TtsEngine::setAudioFormat");
112    // TODO: Fix this!
113    return TTS_SUCCESS;
114}
115
116// Sets the property with the specified value.
117tts_result TtsEngine::setProperty(const char *property, const char *value,
118            const size_t size)
119{
120    LOGI("TtsEngine::setProperty: property=%s, value=%s, size=%lu",
121         property, value, (unsigned long) size);
122
123    /* Set a specific property for the engine.  */
124
125    /* Sanity check */
126    if (property == NULL) {
127        LOGE("setProperty called with property NULL");
128        return TTS_PROPERTY_UNSUPPORTED;
129    }
130
131    if (value == NULL) {
132        LOGE("setProperty called with value NULL");
133        return TTS_VALUE_INVALID;
134    }
135
136#if 1 // This is an example only...
137    if (strncmp(property, "foo", 3) == 0) { // FIXME(fergus): can we use strcmp rather than strncmp here?
138        if (strcmp(value, "bar") == 0) {
139            return TTS_SUCCESS;
140        } else {
141            LOGE("can't set property 'foo' to anything except 'bar'");
142            return TTS_VALUE_INVALID;
143        }
144    }
145#endif
146
147    return TTS_PROPERTY_UNSUPPORTED;
148}
149
150
151tts_result TtsEngine::getProperty(const char *property, char *value, size_t *iosize)
152{
153    LOGI("TtsEngine::getProperty: property=%s, value=%s, iosize=%lu",
154         property, value, (unsigned long) *iosize);
155
156    /* Get the property for the engine.
157       This property was previously set by setProperty or by default.       */
158
159    /* sanity check */
160    if (property == NULL) {
161        LOGE("getProperty called with property NULL");
162        return TTS_PROPERTY_UNSUPPORTED;
163    }
164
165    if (value == NULL) {
166        LOGE("getProperty called with value NULL");
167        return TTS_VALUE_INVALID;
168    }
169
170#if 1 // Example only...
171    if (strncmp(property, "foo", 3) == 0) {
172        strncpy(value, "bar", *iosize); // FIXME(fergus): is this right?
173        *iosize = strlen("bar");
174        return TTS_SUCCESS;
175    }
176#endif
177
178    /* Unknown property */
179    LOGE("Unsupported property");
180    return TTS_PROPERTY_UNSUPPORTED;
181}
182
183/** synthesizeText
184 *  Synthesizes a text string.
185 *  The text string could be annotated with SSML tags.
186 *  @text     - text to synthesize
187 *  @buffer   - buffer which will receive generated samples
188 *  @bufferSize - size of buffer
189 *  @userdata - pointer to user data which will be passed back to callback function
190 *  return tts_result
191*/
192tts_result TtsEngine::synthesizeText( const char * text, int8_t * buffer, size_t bufferSize, void * userdata )
193{
194    LOGI("TtsEngine::synthesizeText: text=%s, bufferSize=%lu", text, (unsigned long) bufferSize);
195
196    // STUB: you will need to implement this.
197    // Your implementation will need to call ttsSynthDoneCBPointer(...).
198
199    return TTS_SUCCESS;
200}
201
202// Synthesizes IPA text.
203tts_result TtsEngine::synthesizeIpa( const char * ipa, int8_t * buffer, size_t bufferSize, void * userdata )
204{
205    LOGI("TtsEngine::synthesizeIpa");
206
207    // This API function is deprecated, so don't implementing this!
208    return TTS_FAILURE;
209}
210
211
212// Interrupts synthesis.
213tts_result TtsEngine::stop()
214{
215    LOGI("TtsEngine::stop");
216
217    // STUB: you will need to implement this.
218
219    return TTS_SUCCESS;
220}
221
222
223
224TtsEngine* getTtsEngine()
225{
226    LOGI("TtsEngine::getTtsEngine");
227    return new TtsEngine();
228}
229
230}; // namespace android