为什么不可用声音列表总是空的? [英] Why does the list of unavailable voices is always empty?

查看:195
本文介绍了为什么不可用声音列表总是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的使应用程序能够查询平台的语言文件的可用性:只要实现以下目的,通过使用 startActivityForResult 方法来发送它的异步请求

Android enables an application to query the platform for the availability of language files: simply instantiate the intent below and send it in an asynchronous request by using startActivityForResult method.

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

上述请求的结果是通过调用的onActivityResult 方法返回:第二个参数是重新presents上述请求的成功或失败的值,第三个参数包含了一些其他数据。之间的附加数据中,有两个列表(可能为空):

The result of the above request is returned by calling the onActivityResult method: the second argument is a value which represents the success or failure of the above request, and the third argument contains some additional data. Among the additional data, there are two lists (possibly empty):


  • 可用的声音;

  • the available voices;

ArrayList<String> availableVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
Log.i(LOG_TAG, String.format("Available voices: %s %s", availableVoices.size(), availableVoices.toString()));


  • 不可用的声音。

  • the unavailable voices.

    ArrayList<String> unavailableVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
    Log.i(LOG_TAG, String.format("Unavailable voices: %s %s", unavailableVoices.size(), unavailableVoices.toString()));
    


  • 在如上所示的一个简单的请求的情况下,不可用声音的列表是空的,而可用的声音数组充满了安装在系统上的所有声音。

    In the case of a simple request like the one shown above, the list of unavailable voices is empty, while the array of available voices is filled with all the voices installed on the system.

    行为的改变,如果你添加 TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR 额外的:根据文档,这些额外的用于给TTS引擎来检查一些指令具体的声音。这里是源$ C ​​$ C的exsample:

    The behavior changes if you add the TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR extra: according to the documentation, this extra is used to give instructions to the TTS engine that checks for some specific voices. Here is an exsample of source code:

    ArrayList<String> checkVoiceDataFor = new ArrayList<String>(3);
    checkVoiceDataFor.add("ita-ITA");   // installed on emulator
    checkVoiceDataFor.add("eng-USA-female");  // not installed
    checkVoiceDataFor.add("eng-USA");   // installed on emulator
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    checkIntent.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR, checkVoiceDataFor);
    

    我期望响应包含:

    I expect that the response contains:


    • ITA-ITA和CHI-USA可用的声音列表;

    • CHI-USA-女性在不可用声音列表中。

    然而,结果如下:


    • 可用的声音:2 CHI-USA ITA-ITA]

    • 不可声音:0]

    为什么?

    推荐答案

    有关不可用的声音,我用的是以下内容:

    For the unavailable voices, I use the following:

        ArrayList<String> unavailable = data
                .getStringArrayListExtra("unavailableVoices");
    

    结果总是格式CHI-GBR或只是工程。

    The results are always in the format 'eng-GBR' or just 'eng'.

    如果我误解你的问题,你想知道为什么你没有得到一个不可用输出专门为您搜索的CHI-USA-女'(而不是全部),那么我可以仅建议格式不适合作为过去的搜索。我会建议寻找ZZZ-ZZZ上看到实际的问题在于......

    If I've misunderstood you're question and you're wondering why you don't get an 'unavailable' output specifically for your search of 'eng-USA-female' (rather than at all), then I can only suggest the format isn't suitable to be past to the search. I would suggest searching 'zzz-ZZZ' to see where the actual problem lies...

    希望有所帮助。

    这篇关于为什么不可用声音列表总是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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