|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* 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(); |
|
|
} |
|
|
} |
|
|
|
|
|
|