[英]android Text to Speech of a toast message
I am getting an error with the conversion of the text to speech in android studio. 在android studio中将文本转换为语音时出现错误。 I have initialised the code but it still returns no voice outputs. 我已经初始化了代码,但是它仍然不返回语音输出。 The code is as follows. 代码如下。
else if((match.contains("yes") || match.contains("yeah")) && defsele) {
//Toast toast = Toast.makeText(getApplicationContext(), "Default selection is done and program is starting", Toast.LENGTH_SHORT);
//toast.show();
defsele=false;
switch (progno) {
case 1:
//Toast toast1 = Toast.makeText(getApplicationContext(),"The default settings for cotton cycle is done",Toast.LENGTH_SHORT);
//toast1.show();
String cotton = "The cotton program is starting with the default values";
tts.speak(cotton, TextToSpeech.QUEUE_FLUSH, null);
soak=true;
soakdef();
break;
The tts.speak gets depricated and does not function. tts.speak变得无法使用,无法运行。 How can i make this work.The initialisation code is as follows 我该如何工作。初始化代码如下
tts = new TextToSpeech(this,this);
@Override
public void onInit(int status) {
Log.d("Speech", "OnInit - Status ["+status+"]");
if(status == TextToSpeech.SUCCESS){
Log.d("Speech","Success");
tts.setLanguage(Locale.ENGLISH);
I am very new to android programming and would appreciate any help. 我是android编程的新手,将不胜感激。
Thanks in advanced!!! 提前致谢!!!
try this 尝试这个
TextToSpeech textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
//your text
String textToSpeechStr = "Hello";
//status is success / 0
if (status == TextToSpeech.SUCCESS) {
//speech starts
textToSpeech.speak(textToSpeechStr, TextToSpeech.QUEUE_FLUSH, null);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.