Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0dbc6a44 authored by Charles Chen's avatar Charles Chen
Browse files

Fixing bug #2008185 - problem with the TTS dropping

utterances under heavy load was caused by the speech
queue being locked. Switched to using a timeout with
tryLock so that the TTS service does not give up
immediately.
parent 5b11a0f3
Loading
Loading
Loading
Loading
+13 −8
Original line number Original line Diff line number Diff line
@@ -109,7 +109,9 @@ public class TtsService extends Service implements OnCompletionListener {
            mFilename = file;
            mFilename = file;
        }
        }
    }
    }

    // If the speech queue is locked for more than 5 seconds, something has gone
    // very wrong with processSpeechQueue.
    private static final int SPEECHQUEUELOCK_TIMEOUT = 5000;
    private static final int MAX_SPEECH_ITEM_CHAR_LENGTH = 4000;
    private static final int MAX_SPEECH_ITEM_CHAR_LENGTH = 4000;
    private static final int MAX_FILENAME_LENGTH = 250;
    private static final int MAX_FILENAME_LENGTH = 250;
    // TODO use the TTS stream type when available
    // TODO use the TTS stream type when available
@@ -389,9 +391,8 @@ public class TtsService extends Service implements OnCompletionListener {
        int result = TextToSpeech.TTS_ERROR;
        int result = TextToSpeech.TTS_ERROR;
        boolean speechQueueAvailable = false;
        boolean speechQueueAvailable = false;
        try{
        try{
            // If the queue is locked for more than 1 second,
            speechQueueAvailable =
            // something has gone very wrong with processSpeechQueue.
                    speechQueueLock.tryLock(SPEECHQUEUELOCK_TIMEOUT, TimeUnit.MILLISECONDS);
            speechQueueAvailable = speechQueueLock.tryLock(1000, TimeUnit.MILLISECONDS);
            if (speechQueueAvailable) {
            if (speechQueueAvailable) {
                Log.i("TtsService", "Stopping");
                Log.i("TtsService", "Stopping");
                for (int i = mSpeechQueue.size() - 1; i > -1; i--){
                for (int i = mSpeechQueue.size() - 1; i > -1; i--){
@@ -439,9 +440,8 @@ public class TtsService extends Service implements OnCompletionListener {
        int result = TextToSpeech.TTS_ERROR;
        int result = TextToSpeech.TTS_ERROR;
        boolean speechQueueAvailable = false;
        boolean speechQueueAvailable = false;
        try{
        try{
            // If the queue is locked for more than 1 second,
            speechQueueAvailable =
            // something has gone very wrong with processSpeechQueue.
                    speechQueueLock.tryLock(SPEECHQUEUELOCK_TIMEOUT, TimeUnit.MILLISECONDS);
            speechQueueAvailable = speechQueueLock.tryLock(1000, TimeUnit.MILLISECONDS);
            if (speechQueueAvailable) {
            if (speechQueueAvailable) {
                for (int i = mSpeechQueue.size() - 1; i > -1; i--){
                for (int i = mSpeechQueue.size() - 1; i > -1; i--){
                    if (mSpeechQueue.get(i).mType != SpeechItem.TEXT_TO_FILE){
                    if (mSpeechQueue.get(i).mType != SpeechItem.TEXT_TO_FILE){
@@ -752,8 +752,10 @@ public class TtsService extends Service implements OnCompletionListener {
    private void processSpeechQueue() {
    private void processSpeechQueue() {
        boolean speechQueueAvailable = false;
        boolean speechQueueAvailable = false;
        try {
        try {
            speechQueueAvailable = speechQueueLock.tryLock();
            speechQueueAvailable =
                    speechQueueLock.tryLock(SPEECHQUEUELOCK_TIMEOUT, TimeUnit.MILLISECONDS);
            if (!speechQueueAvailable) {
            if (!speechQueueAvailable) {
                Log.e("TtsService", "processSpeechQueue - Speech queue is unavailable.");
                return;
                return;
            }
            }
            if (mSpeechQueue.size() < 1) {
            if (mSpeechQueue.size() < 1) {
@@ -822,6 +824,9 @@ public class TtsService extends Service implements OnCompletionListener {
            if (mSpeechQueue.size() > 0) {
            if (mSpeechQueue.size() > 0) {
                mSpeechQueue.remove(0);
                mSpeechQueue.remove(0);
            }
            }
        } catch (InterruptedException e) {
          Log.e("TtsService", "TTS processSpeechQueue: tryLock interrupted");
          e.printStackTrace();
        } finally {
        } finally {
            // This check is needed because finally will always run; even if the
            // This check is needed because finally will always run; even if the
            // method returns somewhere in the try block.
            // method returns somewhere in the try block.