编写使用Android 系统自带的文字转语音代码

调用Android系统语音TextToSpeech实例对象

具体代码写法如下:

TextToSpeech mTextToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {

    @Override

 public void onInit(int status) {

if (status==TextToSpeech.SUCCESS) {

   //设置语言朗读

  int supported= mTextToSpeech.setLanguage(Locale.US);

 if ((supported!=TextToSpeech.LANG_AVAILABLE)&& (supported!=TextToSpeech.LANG_COUNTRY_AVAILABLE)) {

            Toast.makeText(this, "不支持当前语言!", Toast.LENGTH_SHORT).show();

                             }

                         }

                   }

          });

mTextToSpeech.speak("这里填入想要转成语音的文字", TextToSpeech.QUEUE_FLUSH, null);

编写使用Android 系统自带的文字转语音代码

上一篇:app项目中遇到TCP分包,H5端对分包进行拼包


下一篇:android 线程的使用总结