Making a Text-To-Speech Wrapper in Android

拟墨画扇 提交于 2019-12-07 17:57:31

I suggest you rely on the lock instead of your ready state int. Insert code as follows:

public int Speak( String text )
{
        if (waitForInitLock.isLocked())
        {
            try
            {
                waitForInitLock.tryLock(180, TimeUnit.SECONDS);
            }
            catch (InterruptedException e)
            {
                Log.e(D_LOG, "interruped");
            }
            //unlock it here so that it is never locked again
            waitForInitLock.unlock();
        }

    if( ready == 1 )
    {
        tts.speak(text, TextToSpeech.QUEUE_ADD, null);
        return 1;
    }
    else
    {
        return 0;
    }   
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!