Text To Speech UI - Slow Android

In my application I use TTS. I have 20 different actions that change when the user scrolls left or right. According to this activity, the text says. I execute tts with a separate thread, and activity selection is done using the main thread. But the problem is very slow, the user interface feels funny. When I scroll left or right, as soon as tts finishes speaking the text, activity changes cannot occur because I use a separate thread for tts. Here is the code:

TTS Class:

public class textToSpeech { TextToSpeech tts=null; public textToSpeech(Context con) { tts = new TextToSpeech(con,new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { 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); } } }); } public void SpeakText (String text) { tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); // TextToSpeech.QUEUE_FLUSH forces the app to stop all the sounds that are currently playing before speaking this text } public void stopSpeak() { tts.stop(); } 

Gesture reading class: (separate class)

 public void decideAlphabet() { tts.stopSpeak(); threadForTTS.start(); switch (i) { case 0: activities=null; activities = new Intent(contxt,A.class); contxt.startActivity(activities); break; case 1: activities=null; activities = new Intent(contxt,B.class); contxt.startActivity(activities); break; ....... 20 more case statements for selecting activities } 

The solveActivity () method is called when it is checked, which has been done, swipe the screen left or right.

Note:

Before adding tts to this application, the user interface performed correctly without delay or slowness. After adding TTS, the application became slow. How can I solve this problem?

Hi

+6
java android text-to-speech
source share
1 answer

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

Of course, I was sure that TTS was called from another thread, which I checked with Thread.currentThread().getName() But, as it turned out, OnInit did continue to work in the main thread, and it seems that installing the language is an expensive operation , A quick change to run OnInit content in a new thread, and the complaint about the freeze / choreographer UI 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() 
+6
source share

All Articles