Sunday, 25 September 2022

Custom TextToSpeechService Does Not Receive Usage Hints from Google TalkBack

I'm building a custom Android TextToSpeechService which filters text by language.

Currently, I'm handling non-English-language text with my custom TextToSpeech service, and I'm sending English language text to an instance of Google Speech Services.

My problem is that, when I use Google Talkback, I'm no longer able to receive Talkback's usage hints (e.g. "Double-tap to activate", etc.)

The following code runs on a singleton which is called from my TextToSpeechService.

private TextToSpeech mAndroidTTS = null; 

public void initEnglishTTS() {
      if (mAndroidTTS == null) {
            mAndroidTTS = new TextToSpeech(mContext, i -> {
                if (i == TextToSpeech.SUCCESS) {
                    mAndroidTTS.setLanguage(Locale.US);
                }
            }, "com.google.android.tts");

        }
}

public void synthesize(String text, SynthesisCallback callback) {
      callback.start(SAMPLING_RATE_HZ,
                AudioFormat.ENCODING_PCM_16BIT, 1);
      sayInEnglish(text);  // If I comment out this line, then it works
      callback.done();

}

protected static void sayInEnglish(String text) {
        String utteranceID = UUID.randomUUID().toString();
        mAndroidTTS.speak(text, TextToSpeech.QUEUE_FLUSH, null, utteranceID);
    
}

In my custom TextToSpeechService, I have the following code:

public class CustomTtsService extends TextToSpeechService {
     // an instance of the singleton
     private SynthesizerSingleton singleton = singleton.getInstance();
     
    @Override
    protected void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback) {
         String text = getRequestString(request);  
         singleton.synthesize(text, callback);
   }

   private String getRequestString(SynthesisRequest request) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            return request.getCharSequenceText().toString();
        } else {
            return request.getText();
        }
    }
}

If I were to comment out the line sayInEnglish(text), then all of the expected requests are received--but obviously, no utterances are synthesized.

What could I be doing incorrectly?



from Custom TextToSpeechService Does Not Receive Usage Hints from Google TalkBack

No comments:

Post a Comment