TextToSpeech : deprecated speak function in API Level 21

前端 未结 2 1577
遥遥无期
遥遥无期 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 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);
                    }
    
                }
            });
    

提交回复
热议问题