在 Android 文本转语音应用程序的当前活动中朗读文本后调用活动
我是安卓新手。任何人都可以帮助我满足以下要求吗?在当前活动的演讲完成后调用活动。
Activity2 的文本在 Activity1 完成后读取,但 Activity2 在 Activity1 文本完成之前启动。在此话语中,id 也未被识别。
我写的代码如下。任何帮助将不胜感激。谢谢。
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
String text= tt.getText().toString();
if (text!=null && text.length()>0) {
Toast.makeText(activity1.this, "Speaking: " + text, Toast.LENGTH_LONG).show();
tts.setOnUtteranceCompletedListener(this);
HashMap<String, String> myHash = new HashMap();
tts.speak(text, TextToSpeech.QUEUE_ADD, myHash);
myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
"completed");
}
else if (status == TextToSpeech.ERROR) {
Toast.makeText(Fossils.this,
"Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
}
}
}
public void onUtteranceCompleted(String t) {
if(t == "completed"){
Intent i = new Intent(this, activity2.class);
startActivity(i);
}
}
I am new to android. Can any one help me with the following requirement; to call an activity after the speech of the current activity has completed.
The text of activity2 is read after completion of activity1 but activity2 is launched before activity1 text is completed. In this utterance id is also not identified.
The code I have written is follows. Any help would be appreciated. Thanks.
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
String text= tt.getText().toString();
if (text!=null && text.length()>0) {
Toast.makeText(activity1.this, "Speaking: " + text, Toast.LENGTH_LONG).show();
tts.setOnUtteranceCompletedListener(this);
HashMap<String, String> myHash = new HashMap();
tts.speak(text, TextToSpeech.QUEUE_ADD, myHash);
myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
"completed");
}
else if (status == TextToSpeech.ERROR) {
Toast.makeText(Fossils.this,
"Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
}
}
}
public void onUtteranceCompleted(String t) {
if(t == "completed"){
Intent i = new Intent(this, activity2.class);
startActivity(i);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码顺序错误:您需要在调用
speak
之前将put
放入HashMap
中。试试这个:You have the wrong order in your code: you need to
put
into theHashMap
before callingspeak
. Try this: