Merge change 5226 into donut
* changes: Fix bug in TTS service where the language setting was using the default language when the setting wasn't enforced, and vice-versa. Cleaning the log of the native TTS layer to use LOGV for verbose messages, rather than LOGI.
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#define LOG_NDEBUG 0
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -168,7 +168,7 @@ void prepAudioTrack(SynthProxyJniStorage* pJniData,
|
|||||||
static tts_callback_status ttsSynthDoneCB(void *& userdata, uint32_t rate,
|
static tts_callback_status ttsSynthDoneCB(void *& userdata, uint32_t rate,
|
||||||
AudioSystem::audio_format format, int channel,
|
AudioSystem::audio_format format, int channel,
|
||||||
int8_t *&wav, size_t &bufferSize, tts_synth_status status) {
|
int8_t *&wav, size_t &bufferSize, tts_synth_status status) {
|
||||||
LOGI("ttsSynthDoneCallback: %d bytes", bufferSize);
|
LOGV("ttsSynthDoneCallback: %d bytes", bufferSize);
|
||||||
|
|
||||||
if (userdata == NULL){
|
if (userdata == NULL){
|
||||||
LOGE("userdata == NULL");
|
LOGE("userdata == NULL");
|
||||||
@@ -178,7 +178,7 @@ static tts_callback_status ttsSynthDoneCB(void *& userdata, uint32_t rate,
|
|||||||
SynthProxyJniStorage* pJniData = (SynthProxyJniStorage*)(pForAfter->jniStorage);
|
SynthProxyJniStorage* pJniData = (SynthProxyJniStorage*)(pForAfter->jniStorage);
|
||||||
|
|
||||||
if (pForAfter->usageMode == USAGEMODE_PLAY_IMMEDIATELY){
|
if (pForAfter->usageMode == USAGEMODE_PLAY_IMMEDIATELY){
|
||||||
LOGI("Direct speech");
|
LOGV("Direct speech");
|
||||||
|
|
||||||
if (wav == NULL) {
|
if (wav == NULL) {
|
||||||
delete pForAfter;
|
delete pForAfter;
|
||||||
@@ -189,16 +189,16 @@ static tts_callback_status ttsSynthDoneCB(void *& userdata, uint32_t rate,
|
|||||||
prepAudioTrack(pJniData, rate, format, channel);
|
prepAudioTrack(pJniData, rate, format, channel);
|
||||||
if (pJniData->mAudioOut) {
|
if (pJniData->mAudioOut) {
|
||||||
pJniData->mAudioOut->write(wav, bufferSize);
|
pJniData->mAudioOut->write(wav, bufferSize);
|
||||||
LOGI("AudioTrack wrote: %d bytes", bufferSize);
|
//LOGV("AudioTrack wrote: %d bytes", bufferSize);
|
||||||
} else {
|
} else {
|
||||||
LOGI("Can't play, null audiotrack");
|
LOGE("Can't play, null audiotrack");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (pForAfter->usageMode == USAGEMODE_WRITE_TO_FILE) {
|
} else if (pForAfter->usageMode == USAGEMODE_WRITE_TO_FILE) {
|
||||||
LOGI("Save to file");
|
LOGV("Save to file");
|
||||||
if (wav == NULL) {
|
if (wav == NULL) {
|
||||||
delete pForAfter;
|
delete pForAfter;
|
||||||
LOGI("Null: speech has completed");
|
LOGV("Null: speech has completed");
|
||||||
}
|
}
|
||||||
if (bufferSize > 0){
|
if (bufferSize > 0){
|
||||||
fwrite(wav, 1, bufferSize, pForAfter->outputFile);
|
fwrite(wav, 1, bufferSize, pForAfter->outputFile);
|
||||||
|
|||||||
@@ -170,6 +170,39 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getDefaultLanguage() {
|
||||||
|
String defaultLang = android.provider.Settings.Secure.getString(mResolver,
|
||||||
|
android.provider.Settings.Secure.TTS_DEFAULT_LANG);
|
||||||
|
if (defaultLang == null) {
|
||||||
|
return TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_LANG;
|
||||||
|
} else {
|
||||||
|
return defaultLang;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getDefaultCountry() {
|
||||||
|
String defaultCountry = android.provider.Settings.Secure.getString(mResolver,
|
||||||
|
android.provider.Settings.Secure.TTS_DEFAULT_COUNTRY);
|
||||||
|
if (defaultCountry == null) {
|
||||||
|
return TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_COUNTRY;
|
||||||
|
} else {
|
||||||
|
return defaultCountry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getDefaultLocVariant() {
|
||||||
|
String defaultVar = android.provider.Settings.Secure.getString(mResolver,
|
||||||
|
android.provider.Settings.Secure.TTS_DEFAULT_VARIANT);
|
||||||
|
if (defaultVar == null) {
|
||||||
|
return TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT;
|
||||||
|
} else {
|
||||||
|
return defaultVar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setSpeechRate(int rate) {
|
private void setSpeechRate(int rate) {
|
||||||
if (isDefaultEnforced()) {
|
if (isDefaultEnforced()) {
|
||||||
nativeSynth.setSpeechRate(getDefaultRate());
|
nativeSynth.setSpeechRate(getDefaultRate());
|
||||||
@@ -185,15 +218,16 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
|
|
||||||
|
|
||||||
private void setLanguage(String lang, String country, String variant) {
|
private void setLanguage(String lang, String country, String variant) {
|
||||||
Log.v("TTS", "TtsService.setLanguage("+lang+", "+country+", "+variant+")");
|
Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
|
||||||
if (isDefaultEnforced()) {
|
if (isDefaultEnforced()) {
|
||||||
nativeSynth.setLanguage(lang, country, variant);
|
nativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(),
|
||||||
|
getDefaultLocVariant());
|
||||||
} else {
|
} else {
|
||||||
// TODO handle default language
|
nativeSynth.setLanguage(lang, country, variant);
|
||||||
nativeSynth.setLanguage("eng", "USA", "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a sound resource to the TTS.
|
* Adds a sound resource to the TTS.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user