編寫使用Android 系統自帶的文字轉語音代碼

調用Android系統語音TextToSpeech實例對象ide

具體代碼寫法以下:this

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

@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);it

相關文章
相關標籤/搜索