TextToSpeech : deprecated speak function in API Level 21

前端 未结 2 1564
遥遥无期
遥遥无期 2021-02-18 13:25

I try to use a TextToSpeech in my app,

String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);

But the fu

相关标签:
2条回答
  • 2021-02-18 13:59
    String text = editText.getText().toString();
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tts.speak(text,TextToSpeech.QUEUE_FLUSH,null,null);
    } else {
        tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
    }
    
    0 讨论(0)
  • 2021-02-18 14:12

    Here is the complete work that work for me

    Private TextToSpeech ts
     ts=new TextToSpeech(CurrentActivity.this, new TextToSpeech.OnInitListener() {
                @Override
                public void onInit(int status) {
                    String text = "Any Text to Speak";
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        ts.speak(text,TextToSpeech.QUEUE_FLUSH,null,null);
                    } else {
                        ts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
                    }
    
                }
            });
    
    0 讨论(0)
提交回复
热议问题