Merge commit '81608741dc26da8ce6ddfe4a86fa1b956cb6406b' * commit '81608741dc26da8ce6ddfe4a86fa1b956cb6406b': Add a synchronous stop method to TTS synth engine so that upon its destruction,
This commit is contained in:
@@ -721,6 +721,27 @@ android_tts_SynthProxy_stop(JNIEnv *env, jobject thiz, jint jniData)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
android_tts_SynthProxy_stopSync(JNIEnv *env, jobject thiz, jint jniData)
|
||||
{
|
||||
int result = TTS_FAILURE;
|
||||
|
||||
if (jniData == 0) {
|
||||
LOGE("android_tts_SynthProxy_stop(): invalid JNI data");
|
||||
return result;
|
||||
}
|
||||
|
||||
// perform a regular stop
|
||||
result = android_tts_SynthProxy_stop(env, thiz, jniData);
|
||||
// but wait on the engine having released the engine mutex which protects
|
||||
// the synthesizer resources.
|
||||
engineMutex.lock();
|
||||
engineMutex.unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static jobjectArray
|
||||
android_tts_SynthProxy_getLanguage(JNIEnv *env, jobject thiz, jint jniData)
|
||||
{
|
||||
@@ -778,6 +799,10 @@ static JNINativeMethod gMethods[] = {
|
||||
"(I)I",
|
||||
(void*)android_tts_SynthProxy_stop
|
||||
},
|
||||
{ "native_stopSync",
|
||||
"(I)I",
|
||||
(void*)android_tts_SynthProxy_stopSync
|
||||
},
|
||||
{ "native_speak",
|
||||
"(ILjava/lang/String;I)I",
|
||||
(void*)android_tts_SynthProxy_speak
|
||||
|
||||
@@ -51,6 +51,18 @@ public class SynthProxy {
|
||||
return native_stop(mJniData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous stop of the synthesizer. This method returns when the synth
|
||||
* has completed the stop procedure and doesn't use any of the resources it
|
||||
* was using while synthesizing.
|
||||
*
|
||||
* @return {@link android.speech.tts.TextToSpeech.SUCCESS} or
|
||||
* {@link android.speech.tts.TextToSpeech.ERROR}
|
||||
*/
|
||||
public int stopSync() {
|
||||
return native_stopSync(mJniData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthesize speech and speak it directly using AudioTrack.
|
||||
*/
|
||||
@@ -156,6 +168,8 @@ public class SynthProxy {
|
||||
|
||||
private native final int native_stop(int jniData);
|
||||
|
||||
private native final int native_stopSync(int jniData);
|
||||
|
||||
private native final int native_speak(int jniData, String text, int streamType);
|
||||
|
||||
private native final int native_synthesizeToFile(int jniData, String text, String filename);
|
||||
|
||||
@@ -188,6 +188,8 @@ public class TtsService extends Service implements OnCompletionListener {
|
||||
|
||||
// Unregister all callbacks.
|
||||
mCallbacks.kill();
|
||||
|
||||
Log.v("TtsService", "onDestroy() completed");
|
||||
}
|
||||
|
||||
|
||||
@@ -497,14 +499,13 @@ public class TtsService extends Service implements OnCompletionListener {
|
||||
|
||||
// clear the current speech item
|
||||
if (mCurrentSpeechItem != null) {
|
||||
result = sNativeSynth.stop();
|
||||
result = sNativeSynth.stopSync();
|
||||
mKillList.put(mCurrentSpeechItem, true);
|
||||
mIsSpeaking = false;
|
||||
|
||||
// was the engine writing to a file?
|
||||
if (mCurrentSpeechItem.mType == SpeechItem.TEXT_TO_FILE) {
|
||||
// delete the file that was being written
|
||||
// TODO make sure the synth is not writing to the file anymore
|
||||
if (mCurrentSpeechItem.mFilename != null) {
|
||||
File tempFile = new File(mCurrentSpeechItem.mFilename);
|
||||
Log.v("TtsService", "Leaving behind " + mCurrentSpeechItem.mFilename);
|
||||
@@ -884,6 +885,7 @@ public class TtsService extends Service implements OnCompletionListener {
|
||||
}
|
||||
if (mSpeechQueue.size() < 1) {
|
||||
mIsSpeaking = false;
|
||||
mKillList.clear();
|
||||
broadcastTtsQueueProcessingCompleted();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user