mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-12-02 06:42:10 +00:00
Improve the logging on the JNI/C++ bindings and document which API versions each implementation targets
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* 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.
|
||||||
@@ -14,14 +15,13 @@
|
|||||||
* 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
|
* This file contains the TtsEngine interface used by Android to implement
|
||||||
// speech synthesis and the management of resources associated with the
|
* Text-to-Speech services.
|
||||||
// synthesis.
|
*
|
||||||
// An example of the implementation of this interface can be found in
|
* Android Version: 2.2 (Froyo)
|
||||||
// FIXME: add path+name to implementation of default TTS engine
|
* API Version: 8
|
||||||
// Libraries implementing this interface are used in:
|
*/
|
||||||
// frameworks/base/tts/jni/android_tts_SpeechSynthesis.cpp
|
|
||||||
|
|
||||||
#ifndef TTS_ENGINE_H_
|
#ifndef TTS_ENGINE_H_
|
||||||
#define TTS_ENGINE_H_
|
#define TTS_ENGINE_H_
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* 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.
|
||||||
@@ -14,11 +15,21 @@
|
|||||||
* 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>
|
||||||
@@ -152,6 +163,7 @@ static int eSpeakCallback(short *wav, int numsamples, espeak_EVENT *events) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -163,6 +175,7 @@ static bool fileExists(char *fileName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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++) {
|
||||||
@@ -180,6 +193,7 @@ static bool hasBaseResources() {
|
|||||||
/* 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;
|
||||||
}
|
}
|
||||||
@@ -219,6 +233,7 @@ tts_result attemptInit() {
|
|||||||
* 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;
|
||||||
|
|
||||||
@@ -239,6 +254,7 @@ tts_result TtsEngine::init(synthDoneCB_t synthDoneCBPtr, const char *engineConfi
|
|||||||
* 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);
|
||||||
}
|
}
|
||||||
@@ -249,14 +265,14 @@ tts_result TtsEngine::shutdown(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
@@ -375,7 +391,7 @@ tts_support_result isLanguageSupported(const char *lang, const char *country, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
@@ -414,10 +430,12 @@ tts_result TtsEngine::setLanguage(const char *lang, const char *country, const c
|
|||||||
|
|
||||||
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);
|
||||||
@@ -441,7 +459,7 @@ tts_result TtsEngine::setAudioFormat(tts_audio_format& encoding, uint32_t& rate,
|
|||||||
|
|
||||||
// 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. */
|
||||||
@@ -483,7 +501,7 @@ tts_result TtsEngine::setProperty(const char *property, const char *value, const
|
|||||||
|
|
||||||
// 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. */
|
||||||
@@ -554,7 +572,7 @@ tts_result TtsEngine::getProperty(const char *property, char *value, size_t *ios
|
|||||||
*/
|
*/
|
||||||
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);
|
||||||
|
|
||||||
@@ -576,6 +594,7 @@ tts_result TtsEngine::synthesizeText(const char *text, int8_t *buffer, size_t bu
|
|||||||
* 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;
|
||||||
}
|
}
|
||||||
@@ -585,6 +604,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TtsEngine* getTtsEngine() {
|
TtsEngine* getTtsEngine() {
|
||||||
|
if (DEBUG) LOGV("%s", __FUNCTION__);
|
||||||
return new TtsEngine();
|
return new TtsEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* 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.
|
||||||
@@ -14,6 +15,13 @@
|
|||||||
* 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>
|
||||||
@@ -24,7 +32,7 @@
|
|||||||
#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,
|
||||||
@@ -234,11 +242,11 @@ JNIEXPORT jboolean
|
|||||||
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));
|
||||||
|
|
||||||
@@ -262,8 +270,10 @@ JNICALL Java_com_googlecode_eyesfree_espeak_SpeechSynthesis_nativeSetVoiceByProp
|
|||||||
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);
|
||||||
|
|||||||
@@ -14,6 +14,13 @@
|
|||||||
* 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;
|
||||||
|
|||||||
@@ -14,8 +14,16 @@
|
|||||||
* 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;
|
||||||
@@ -42,6 +50,7 @@ import java.util.Locale;
|
|||||||
*
|
*
|
||||||
* @author alanv@google.com (Alan Viverette)
|
* @author alanv@google.com (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;
|
||||||
|
|||||||
Reference in New Issue
Block a user