调用 TextToSpeech Activity,无需任何 UI 显示
在不调用任何 UI 更改的情况下调用 TextToSpeech 的推荐方法是什么?给出的示例都与 Activity 绑定,而 Activity 的默认行为是显示其自己的 UI。
我试图通过 Intent 通过我的主要活动调用 TextToSpeechActivity。我根本不想改变 UI。我希望 TextToSpeech 能够在 UI 中不发生任何更改的情况下发出声音。这是我到目前为止所拥有的。
public class MyActivity extends Activity {
public void onClick(View v) {
Intent intent = new Intent(this, TextToSpeechActivity.class);
startActivity(intent);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
每次单击时,主 UI 都会替换为 TextToSpeech 活动的 UI。不,我不希望主 Activity 实现 TextToSpeech.OnInitListener。 main 中已经有足够的代码了。已经够乱的了。
What is the recommended way to call TextToSpeech without invoking any UI change? The examples given are all bound to Activities, and the default behavior for an activity is to display its own UI.
I'm trying to call a TextToSpeechActivity via my main activity via an Intent. I don't want the UI to change at all. I want the TextToSpeech to sound without anything in the UI changing. Here's what I have so far.
public class MyActivity extends Activity {
public void onClick(View v) {
Intent intent = new Intent(this, TextToSpeechActivity.class);
startActivity(intent);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Every time I click, the main UI is replaced with the UI for the TextToSpeech activity. And no, I don't want the main Activity to implement TextToSpeech.OnInitListener. There's already enough code in main. It's messy enough already.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要开始新的活动。 TTS 的棘手之处在于您需要先完成一些初始化才能使用它。例如在
onClick()
中这样做根本不起作用。我已经在 Zwitscher 中实现了这一点:
https://github.com/pilhuhn /ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L317
speak()
从 UI 上的按钮调用,所需的初始化从onCreate()
中调用:https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd /zwitscher/OneTweetActivity.java#L62如果不再需要,请不要忘记关闭 TTS 系统:
https://github.com/pilhuhn /ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L394
HTH(如果有更好的解决方案,请告诉我)
You don't need to start a new activity. The hairy thing with TTS is that you need to have some initialization done before you can use it. And doing that e.g. within
onClick()
does not work at all.I've implemented that in Zwitscher:
https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L317
speak()
is called from a button on the UI, and the initialization needed is called from withinonCreate()
: https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L62And don't forget to shut down the TTS system if no longer needed:
https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L394
HTH ( and let me know if there is a better solution)