小编BAD*_*DIA的帖子

W/TextToSpeech:说话失败:未绑定到 TTS 引擎

我有我的课程MyTTS,我有方法speakout在这门课上有方法。当我在类内部调用它时,它工作正常,但是如果我在其他类中初始化这个类并且我再次调用这个方法就永远不起作用,它给了我

\n\n
\n

W/TextToSpeech:说话失败:未绑定到 TTS 引擎

\n
\n\n

这是我的类 MyTTS.java:

\n\n
TextToSpeech textToSpeech;\n\n\npublic MyTTS(Context context) {\n    textToSpeech=new TextToSpeech(context,this);\n}\n\n\n\n@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)\npublic void speakOut(String str,String pk){\n    textToSpeech.speak(str,TextToSpeech.QUEUE_FLUSH,null,pk);\n}\n\n@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)\n@Override\npublic void onInit(int status) {\n    if (status == TextToSpeech.SUCCESS) {\n\n        int result = textToSpeech.setLanguage(Locale.US);\n\n        if (result == TextToSpeech.LANG_MISSING_DATA\n                || result == TextToSpeech.LANG_NOT_SUPPORTED) {\n            Log.e("TTS", "This Language is not supported");\n        } else {\n           speakOut("badr","dfd");\n        }\n\n    } else {\n        Log.e("TTS", "Initilization Failed!");\n    }\n}\n\n@Override\npublic void onPause() {\n\n    if(textToSpeech==null){\n        textToSpeech.stop();\n        textToSpeech.shutdown();\n\n    }\n\n    super.onPause();\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n …

java android text-to-speech google-text-to-speech android-fragments

6
推荐指数
1
解决办法
4103
查看次数