呼叫文字转语音活动没有任何用户界面的显示 [英] Call TextToSpeech Activity Without Any UI Display

查看:147
本文介绍了呼叫文字转语音活动没有任何用户界面的显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是推荐的方法来调用文字转语音而不调用任何UI的变化?所举的例子都是必然的活动,并为活动的默认行为是显示自己的UI。

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.

我想通过一个意图通过我的主要活动叫TextToSpeechActivity。我不希望UI做任何改动。我想要的文字转语音的声音没有在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);
    }
}

我每次点击,主UI被替换为文字转语音活动的用户界面。不,我不希望主要活动实施TextToSpeech.OnInitListener。有已经足够为主code。这是混乱的够多了。

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.

推荐答案

您无需启动一个新的活动。与TTS毛茸茸的事情是,你需要有一些初始化之前完成,你可以使用它。而这样做,例如的onClick()在根本不工作。
我实现了在Zwitscher:
<一href=\"https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L317\" rel=\"nofollow\">https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L317
说话()从UI上的一个按钮调用,需要的是所谓的初始化中的onCreate(): <一href=\"https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L62\" rel=\"nofollow\">https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L62
而且不要忘了关闭的TTS系统,如果不再需要:
<一href=\"https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L394\" rel=\"nofollow\">https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L394

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 within onCreate(): https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L62 And 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(让我知道如果有一个更好的解决方案)

HTH ( and let me know if there is a better solution)

这篇关于呼叫文字转语音活动没有任何用户界面的显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆