TextToSpeech问题总结

一:简单的发音Demo

 TextToSpeech mySpeech;//变量声明,自动回导入相应库包

 当前Activity类需implements  TextToSpeech.OnInitListener
 //自动生成的空的初始化函数,建议代码如下
 public void onInit(int status) {
        if(status == mySpeech.SUCCESS)
        {
            int result = mySpeech.setLanguage(Locale.ENGLISH);
            if(result == mySpeech.LANG_MISSING_DATA || result == mySpeech.LANG_NOT_SUPPORTED)
            {
                Toast.makeText(this,"lost",Toast.LENGTH_SHORT).show();
            }
        }
    }

 initTextTosSpeech();//界面加载时初始化

 private void initTextTosSpeech() 初始化代码,男女声及语速设置等
   {
        mySpeech = new TextToSpeech(this,this);
        mySpeech.setPitch(1.0f);
        mySpeech.setSpeechRate(0.5f);
    }
//调用代码示例
mySpeech.speak(text,TextToSpeech.QUEUE_FLUSH,null);//String类型变量text为需要发音文本

二:在当前页面很久不操作(5分钟往上),发音功能失效

原因:手机内存较小,TTS失去连接

解决办法࿱

你可能感兴趣的:(Andriod)