相关疑难解决方法(0)

文本到语音应用程序UI是慢机器人

在我的应用程序中,我使用的是TTS.我有20个不同的活动,当用户向左或向右滑动时会更改这些活动.根据活动,会说一个文字.我正在使用单独的线程执行tts,并且主线程完成了活动选择.但问题非常缓慢,用户界面感觉很尴尬.当我向左或向右滑动时,一旦tts完成说出文本,活动就会发生变化,因为我正在使用单独的线程进行tts.这是codE:

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 …
Run Code Online (Sandbox Code Playgroud)

java android text-to-speech

7
推荐指数
1
解决办法
3275
查看次数

标签 统计

android ×1

java ×1

text-to-speech ×1