how to get to know programmatically whether any TTS engine installed in my device or not?

前端 未结 4 690
逝去的感伤
逝去的感伤 2021-01-05 01:25

I would like to know programmatically how to get TTS engine info of the device for e.g. whether any TTS engine is installed or not , if installed then what are those and wha

4条回答
  •  爱一瞬间的悲伤
    2021-01-05 02:06

    To save your clicks:

    Launch this to check if TTS is installed or not:

    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
    

    and then get result in this:

    private TextToSpeech mTts;
    protected void onActivityResult(
        int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            // success, create the TTS instance
            mTts = new TextToSpeech(this, this);
        } else {
            // missing data, install it
            Intent installIntent = new Intent();
            installIntent.setAction(
                TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }
    }
    

提交回复
热议问题