为什么ACTION_CHECK_TTS_DATA意图"难以使用"? [英] Why is the ACTION_CHECK_TTS_DATA Intent "awkward to use"?

查看:173
本文介绍了为什么ACTION_CHECK_TTS_DATA意图"难以使用"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

href="http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html" rel="nofollow">官方的

 意图checkIntent =新意图();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent,MY_DATA_CHECK_ code);
 

但@gregm在这个线程,否则建议:

  

另外,不要使用ACTION_CHECK_TTS_DATA意图,这是尴尬   使用

     

相反,请执行以下操作:

     
      
  1. 创建TextToSpeech
  2.   
  3. 的OnInit,检查isLanguageAvailable()如果是,您的应用程序是所有设置。如果不是,发送ACTION_INSTALL_TTS_DATA
  4.   

如果我理解正确的话,有什么@gregm确实/顾名思义就是延迟的的 TextToSpeech.LANG_MISSING_DATA onActivityResult检查()的OnInit()

这是为什么比更好正式办法?

和为什么ACTION_CHECK_TTS_DATA如此别扭使用?

解决方案

这是@gregm。

ACTION_CHECK_TTS_DATA 需要更复杂的执行和更code,但还没有做同样的事情 TextToSpeech.isLanguageAvailable()让我解释一下:

1)你需要两个异步进程,当您使用 ACTION_INSTALL_TTS_DATA 。首先,发动意图和接受的结果。其次,要等待 TextToSpeech 来调用的OnInit()更多可能出错,而你的应用程序做所有的等待。

2)所有你要做的是if语句执行,你需要同样的code来处理安装语言的数据,如果需要的话,那么为什么还要增加额外的复杂性 <? / P>

它归结做到这一点:

你想1号线的code:

 如果(TextToSpeech.isLanguageAvailable())
{
 (同样的TTS初始化$ C $这里三)
}
 

或> 1线code这样的:

 意图checkIntent =新意图();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent,MY_DATA_CHECK_ code);

公共无效onActivityResult(...)
{
 如果(结果code == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
 (同样的TTS初始化$ C $这里三)
}
 

在我的角度来看,我宁愿只是得到,而不是使用意图搪塞if语句。我相信Android官方文档需要改变,以推荐这种方法。

如果你还是不相信,我们正在讨论这两种方法做同样的事情,检查出的替代实现我的<一个href="https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/tts/TextToSpeechInitializer.java"相对=nofollow>这里和<一href="https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/tts/TextToSpeechInitializerByAction.java"相对=nofollow>此处。此外,如果你不关心这些东西,只是想你的应用程序来说话,只是扩展该<一href="https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/SpeechRecognizingAndSpeakingActivity.java"相对=nofollow>活动并完成。

The official introduction to Text-To-Speech in Android says that "upon creating your activity, a good first step is to check for the presence of the TTS resources with the corresponding intent:"

Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

But @gregm in this thread suggests otherwise:

Also, don't use the ACTION_CHECK_TTS_DATA Intent, that's awkward to use.

Instead, do the following:

  1. Create TextToSpeech
  2. OnInit, check isLanguageAvailable() if it is, your app is all set. if not, send the ACTION_INSTALL_TTS_DATA

If I understand correctly, what @gregm does/suggests is to defer the TextToSpeech.LANG_MISSING_DATA check from onActivityResult() to onInit().

Why is this better than the formal approach?

And why is ACTION_CHECK_TTS_DATA so "awkward to use"?

解决方案

This is @gregm.

ACTION_CHECK_TTS_DATA requires more complicated execution and more code, but yet does the same thing as TextToSpeech.isLanguageAvailable() Let me explain:

1) You need TWO asynchronous processes when you use ACTION_INSTALL_TTS_DATA. First, to launch an Intent and receive the result. Second, to wait for TextToSpeech to call onInit() More can go wrong while your app is doing all that waiting.

2) All you are trying to do is execute an if statement and you need the same code to handle installing the language data if need be, so why bother adding extra complexity?

It boils down do this:

Do you want 1 line of code:

if (TextToSpeech.isLanguageAvailable())
{
 (same tts init code here)
}

or >1 lines of code like:

Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

public void onActivityResult(...)
{
 if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
 (same tts init code here)
}

In my point of view, I'd rather just get to the if statement, instead of using an Intent runaround. I believe the official Android documentation needs to change to recommend this approach.

If you still don't believe that both approaches we are discussing do the same exact thing, check out the alternative implementations I have here and here. Also, If you don't care about all this stuff and just want your app to speak, just extend this Activity and be done.

这篇关于为什么ACTION_CHECK_TTS_DATA意图&QUOT;难以使用&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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