私のアプリではTTSを使用しています。ユーザーが左右にスワイプしたときに変更される20種類のアクティビティがあります。アクティビティに応じて、テキストが読み上げられます。私は別のスレッドでttsを実行しており、アクティビティの選択はメインスレッドで行われています。しかし、問題は非常に遅く、UIは鈍いと感じています。私が左右にスワイプすると、ttsがテキストの読み上げを終えると、私はttsのために別のスレッドを使用しているので、発生してはならないアクティビティが変わります。ここ はコードです:テキストToスピーチアプリのUIが遅いです。
TTSクラス:
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();
}
ジェスチャーリーダークラス:それがチェックされたとき(別のクラス)
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
}
decideActivity()メソッドが呼び出されますスワイプが作成され、右または左にスワイプします。
注:
このアプリでTTSを追加する前に、UIが遅れたり遅させずに適切に行っていました。私はTTSを追加した後、アプリが遅くなりました。どのように私は、私は同じ問題を抱えていたし、もちろん、次のlogcatエラー...skipped x many frames. The application may be doing too much work on its main thread.
を見にコメントしようとしていました。この問題に
よろしく
どれ体は助けるために? – user2498079