Why does the list of unavailable voices is always empty?

孤街醉人 提交于 2019-12-13 18:02:21

问题


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);

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.

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 and eng-USA in the list of available voices;
  • eng-USA-female in the list of unavailable voices.

However, the results are as follows:

  • Available voices: 2 [eng-USA ita-ITA]
  • Unavailable voices: 0 []

Why?


回答1:


For the unavailable voices, I use the following:

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

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

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...

Hope that helps.



来源:https://stackoverflow.com/questions/10524980/why-does-the-list-of-unavailable-voices-is-always-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!