Browse Source

Improve the logging on the JNI/C++ bindings and document which API versions each implementation targets

master
Reece H. Dunn 12 years ago
parent
commit
dfbfec4e05

+ 8
- 8
jni/include/TtsEngine.h View File

/* /*
* Copyright (C) 2009 Google Inc. * Copyright (C) 2009 Google Inc.
* Copyright (C) 2012 Reece H. Dunn
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* limitations under the License. * limitations under the License.
*/ */


// This header defines the interface used by the Android platform
// to access Text-To-Speech functionality in shared libraries that implement
// speech synthesis and the management of resources associated with the
// synthesis.
// An example of the implementation of this interface can be found in
// FIXME: add path+name to implementation of default TTS engine
// Libraries implementing this interface are used in:
// frameworks/base/tts/jni/android_tts_SpeechSynthesis.cpp
/*
* This file contains the TtsEngine interface used by Android to implement
* Text-to-Speech services.
*
* Android Version: 2.2 (Froyo)
* API Version: 8
*/


#ifndef TTS_ENGINE_H_ #ifndef TTS_ENGINE_H_
#define TTS_ENGINE_H_ #define TTS_ENGINE_H_

+ 26
- 6
jni/jni/com_google_espeakengine.cpp View File

/* /*
* Copyright (C) 2008 Google Inc. * Copyright (C) 2008 Google Inc.
* Copyright (C) 2012 Reece H. Dunn
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* limitations under the License. * limitations under the License.
*/ */


/*
* This file contains the TtsEngine implementation for the eSpeak
* Text-to-Speech engine.
*
* Android Version: 2.2 (Froyo)
* API Version: 8
*/


#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>


#define LOG_TAG "eSpeak Engine" #define LOG_TAG "eSpeak Engine"
#define DEBUG true


#include <speak_lib.h> #include <speak_lib.h>
#include <TtsEngine.h> #include <TtsEngine.h>
} }


static bool fileExists(char *fileName) { static bool fileExists(char *fileName) {
if (DEBUG) LOGV("%s", __FUNCTION__);
FILE *file = fopen(fileName, "r"); FILE *file = fopen(fileName, "r");


if (file == NULL) { if (file == NULL) {
} }


static bool hasBaseResources() { static bool hasBaseResources() {
if (DEBUG) LOGV("%s", __FUNCTION__);
char filename[255]; char filename[255];


for (int i = 0; i < NUM_BASE_RESOURCES; i++) { for (int i = 0; i < NUM_BASE_RESOURCES; i++) {
/* Google Engine API function implementations */ /* Google Engine API function implementations */


tts_result attemptInit() { tts_result attemptInit() {
if (DEBUG) LOGV("%s", __FUNCTION__);
if (hasInitialized) { if (hasInitialized) {
return TTS_SUCCESS; return TTS_SUCCESS;
} }
* return tts_result * return tts_result
*/ */
tts_result TtsEngine::init(synthDoneCB_t synthDoneCBPtr, const char *engineConfig) { tts_result TtsEngine::init(synthDoneCB_t synthDoneCBPtr, const char *engineConfig) {
if (DEBUG) LOGV("%s", __FUNCTION__);
ttsSynthDoneCBPointer = synthDoneCBPtr; ttsSynthDoneCBPointer = synthDoneCBPtr;
hasInitialized = false; hasInitialized = false;


* return tts_result * return tts_result
*/ */
tts_result TtsEngine::shutdown(void) { tts_result TtsEngine::shutdown(void) {
if (DEBUG) LOGV("%s", __FUNCTION__);
if (eSpeakDataPath != NULL) { if (eSpeakDataPath != NULL) {
free(eSpeakDataPath); free(eSpeakDataPath);
} }
} }


tts_result TtsEngine::loadLanguage(const char *lang, const char *country, const char *variant) { tts_result TtsEngine::loadLanguage(const char *lang, const char *country, const char *variant) {
LOGV("loadLanguage(\"%s\", \"%s\", \"%s\")", lang, country, variant);
if (DEBUG) LOGV("loadLanguage(\"%s\", \"%s\", \"%s\")", lang, country, variant);


return TTS_FAILURE; return TTS_FAILURE;
} }


tts_support_result isLanguageSupported(const char *lang, const char *country, const char *variant, tts_support_result isLanguageSupported(const char *lang, const char *country, const char *variant,
int *pindex) { int *pindex) {
LOGV("isLanguageSupported(\"%s\", \"%s\", \"%s\")", lang, country, variant);
if (DEBUG) LOGV("isLanguageSupported(\"%s\", \"%s\", \"%s\")", lang, country, variant);


if ((lang == NULL) || (strlen(lang) == 0)) { if ((lang == NULL) || (strlen(lang) == 0)) {
LOGE("TtsEngine::isLanguageAvailable called with no language"); LOGE("TtsEngine::isLanguageAvailable called with no language");
} }


tts_result TtsEngine::setLanguage(const char *lang, const char *country, const char *variant) { tts_result TtsEngine::setLanguage(const char *lang, const char *country, const char *variant) {
LOGV("setLanguage(\"%s\", \"%s\", \"%s\")", lang, country, variant);
if (DEBUG) LOGV("setLanguage(\"%s\", \"%s\", \"%s\")", lang, country, variant);


// Make sure the engine is initialized! // Make sure the engine is initialized!
attemptInit(); attemptInit();


tts_support_result TtsEngine::isLanguageAvailable(const char *lang, const char *country, tts_support_result TtsEngine::isLanguageAvailable(const char *lang, const char *country,
const char *variant) { const char *variant) {
if (DEBUG) LOGV("%s", __FUNCTION__);
return isLanguageSupported(lang, country, variant, NULL); return isLanguageSupported(lang, country, variant, NULL);
} }


tts_result TtsEngine::getLanguage(char *language, char *country, char *variant) { tts_result TtsEngine::getLanguage(char *language, char *country, char *variant) {
if (DEBUG) LOGV("%s", __FUNCTION__);
strcpy(language, currentLang); strcpy(language, currentLang);
strcpy(country, currentCountry); strcpy(country, currentCountry);
strcpy(variant, currentVariant); strcpy(variant, currentVariant);


// Sets the property with the specified value // Sets the property with the specified value
tts_result TtsEngine::setProperty(const char *property, const char *value, const size_t size) { tts_result TtsEngine::setProperty(const char *property, const char *value, const size_t size) {
LOGV("setProperty(\"%s\", \"%s\", %d)", property, value, size);
if (DEBUG) LOGV("setProperty(\"%s\", \"%s\", %d)", property, value, size);


/* Set a specific property for the engine. /* Set a specific property for the engine.
Supported properties include: language (locale), rate, pitch, volume. */ Supported properties include: language (locale), rate, pitch, volume. */


// Sets the property with the specified value // Sets the property with the specified value
tts_result TtsEngine::getProperty(const char *property, char *value, size_t *iosize) { tts_result TtsEngine::getProperty(const char *property, char *value, size_t *iosize) {
LOGV("getProperty(\"%s\", ...)", property);
if (DEBUG) LOGV("getProperty(\"%s\", ...)", property);


/* Get the property for the engine. /* Get the property for the engine.
This property was previously set by setProperty or by default. */ This property was previously set by setProperty or by default. */
*/ */
tts_result TtsEngine::synthesizeText(const char *text, int8_t *buffer, size_t bufferSize, tts_result TtsEngine::synthesizeText(const char *text, int8_t *buffer, size_t bufferSize,
void *userdata) { void *userdata) {
LOGI("Synthesize: %s", text);
if (DEBUG) LOGV("%s", __FUNCTION__);


espeak_SetSynthCallback(eSpeakCallback); espeak_SetSynthCallback(eSpeakCallback);


* return tts_result * return tts_result
*/ */
tts_result TtsEngine::stop() { tts_result TtsEngine::stop() {
if (DEBUG) LOGV("%s", __FUNCTION__);
espeak_Cancel(); espeak_Cancel();
return TTS_SUCCESS; return TTS_SUCCESS;
} }
#endif #endif


TtsEngine* getTtsEngine() { TtsEngine* getTtsEngine() {
if (DEBUG) LOGV("%s", __FUNCTION__);
return new TtsEngine(); return new TtsEngine();
} }



+ 14
- 4
jni/jni/com_googlecode_eyesfree_espeak_eSpeakService.cpp View File

/* /*
* Copyright (C) 2011 Google Inc. * Copyright (C) 2011 Google Inc.
* Copyright (C) 2012 Reece H. Dunn
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* limitations under the License. * limitations under the License.
*/ */


/*
* This file contains the JNI bindings to eSpeak used by SpeechSynthesis.java.
*
* Android Version: 4.0 (Ice Cream Sandwich)
* API Version: 14
*/

#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <Log.h> #include <Log.h>


#define LOG_TAG "eSpeakService" #define LOG_TAG "eSpeakService"
#define DEBUG false
#define DEBUG true


enum audio_channel_count { enum audio_channel_count {
CHANNEL_COUNT_MONO = 1, CHANNEL_COUNT_MONO = 1,
JNICALL Java_com_googlecode_eyesfree_espeak_SpeechSynthesis_nativeSetVoiceByProperties( JNICALL Java_com_googlecode_eyesfree_espeak_SpeechSynthesis_nativeSetVoiceByProperties(
JNIEnv *env, jobject object, jstring name, jstring languages, jint gender, jint age, JNIEnv *env, jobject object, jstring name, jstring languages, jint gender, jint age,
jint variant) { jint variant) {
if (DEBUG) LOGV("%s", __FUNCTION__);

const char *c_name = env->GetStringUTFChars(name, NULL); const char *c_name = env->GetStringUTFChars(name, NULL);
const char *c_languages = env->GetStringUTFChars(languages, NULL); const char *c_languages = env->GetStringUTFChars(languages, NULL);


if (DEBUG) LOGV("%s(name=%s, languages=%s)", __FUNCTION__, c_name, c_languages);

espeak_VOICE voice_select; espeak_VOICE voice_select;
memset(&voice_select, 0, sizeof(espeak_VOICE)); memset(&voice_select, 0, sizeof(espeak_VOICE));


JNIEXPORT jboolean JNIEXPORT jboolean
JNICALL Java_com_googlecode_eyesfree_espeak_SpeechSynthesis_nativeSetLanguage( JNICALL Java_com_googlecode_eyesfree_espeak_SpeechSynthesis_nativeSetLanguage(
JNIEnv *env, jobject object, jstring language, jint variant) { JNIEnv *env, jobject object, jstring language, jint variant) {
if (DEBUG) LOGV("%s", __FUNCTION__);
const char *c_language = env->GetStringUTFChars(language, NULL); const char *c_language = env->GetStringUTFChars(language, NULL);

if (DEBUG) LOGV("%s(language=%s)", __FUNCTION__, c_language);

const int len = strlen(c_language); const int len = strlen(c_language);
char *lang_copy = (char *) calloc(len, sizeof(char)); char *lang_copy = (char *) calloc(len, sizeof(char));
strcpy(lang_copy, c_language); strcpy(lang_copy, c_language);

+ 7
- 0
src/com/googlecode/eyesfree/espeak/SpeechSynthesis.java View File

* limitations under the License. * limitations under the License.
*/ */


/*
* This file implements the Java API to eSpeak using the JNI bindings.
*
* Android Version: 4.0 (Ice Cream Sandwich)
* API Version: 14
*/

package com.googlecode.eyesfree.espeak; package com.googlecode.eyesfree.espeak;


import android.content.Context; import android.content.Context;

+ 9
- 0
src/com/googlecode/eyesfree/espeak/TtsService.java View File

* limitations under the License. * limitations under the License.
*/ */


/*
* This file implements the Android Text-to-Speech engine for eSpeak.
*
* Android Version: 4.0 (Ice Cream Sandwich)
* API Version: 14
*/

package com.googlecode.eyesfree.espeak; package com.googlecode.eyesfree.espeak;


import android.annotation.SuppressLint;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
* *
* @author [email protected] (Alan Viverette) * @author [email protected] (Alan Viverette)
*/ */
@SuppressLint("NewApi")
public class TtsService extends TextToSpeechService { public class TtsService extends TextToSpeechService {
private static final String TAG = TtsService.class.getSimpleName(); private static final String TAG = TtsService.class.getSimpleName();
private static final boolean DEBUG = false; private static final boolean DEBUG = false;

Loading…
Cancel
Save