Text To Speech app UI is slow android

前端 未结 1 859
慢半拍i
慢半拍i 2021-01-05 04:40

In my app I am using TTS. I have 20 different activities which are changed when the user swipe left or right. According the activity, a text is spoken. I am executing tts wi

1条回答
  •  鱼传尺愫
    2021-01-05 05:29

    I had the same problem and was about to comment on seeing the following logcat error ...skipped x many frames. The application may be doing too much work on its main thread.

    Of course I was sure TTS was being called from another thread which I checked using Thread.currentThread().getName() But it turns out however that OnInit was indeed still running on the main thread and it looks like setting the language is an expensive operation. A quick change to run contents of onInit in a new thread and the UI freezing/choreographer complaining stopped:

    @Override
    public void onInit(int status) {
       new Thread(new Runnable() {
          public void run() {
             if(status != TextToSpeech.ERROR) // initialization me error to nae ha
             {
                tts.setPitch(1.1f); // saw from internet
                tts.setSpeechRate(0.4f); // f denotes float, it actually type casts 0.5 to float
                tts.setLanguage(Locale.US);
             }
          }
       }
    }).start()
    

    0 讨论(0)
提交回复
热议问题