Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TextToSpeech:API级别21中已弃用的speak函数_Android_Text To Speech - Fatal编程技术网

Android TextToSpeech:API级别21中已弃用的speak函数

Android TextToSpeech:API级别21中已弃用的speak函数,android,text-to-speech,Android,Text To Speech,我尝试在我的应用程序中使用TextToSpeech String text = editText.getText().toString(); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); 但是函数speak(字符串文本、int-queueMode、HashMap-params)在API级别21中被弃用。相反,建议使用speak(CharSequence text、int queueMode、Bundle参数、String outtanceid

我尝试在我的应用程序中使用TextToSpeech

String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
但是函数speak(字符串文本、int-queueMode、HashMap-params)在API级别21中被弃用。相反,建议使用speak(CharSequence text、int queueMode、Bundle参数、String outtanceid)。
但我不知道如何设置它。谢谢

这是我的全部作品

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);
}
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);
                }

            }
        });

当我使用你的建议时,Android Studio会说:“params=“null”utranceId=“null”并展开if语句建议。而且,这对我的案例没有足够的帮助。Build.VERSION\u代码现在已经过时(2021年4月)。只需替换上面的条件(Android.OS.Build.VERSION.SdkInt>=Android.OS.BuildVersionCodes.Lollipop)