繁体   English   中英

android祝酒消息的文字转语音

[英]android Text to Speech of a toast message

在android studio中将文本转换为语音时出现错误。 我已经初始化了代码,但是它仍然不返回语音输出。 代码如下。

    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;

tts.speak变得无法使用,无法运行。 我该如何工作。初始化代码如下

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

我是android编程的新手,将不胜感激。

提前致谢!!!

尝试这个

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM