设置一个现有的后文本到语音返回不同不存在的区域设置 [英] Text to speech returns a different non-existant Locale after setting an existing one

查看:180
本文介绍了设置一个现有的后文本到语音返回不同不存在的区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原题

我有一个标准texttospeech,android.speech.tts.TextToSpeech

I have a standard texttospeech, android.speech.tts.TextToSpeech

我将其初始化,并通过使用设置语言 tts.setLanguage(Locale.getDefault())

I initialize it and set a language by using tts.setLanguage(Locale.getDefault())

这是默认的语言环境是de_DE这个(德国,正确的)。 正确设置它后,我问了TTS给我自己的语言 tts.getLanguage()

That default Locale is de_DE (for germany, correct). Right after setting it, i ask the tts to give me its language tts.getLanguage()

现在它告诉我,它设置为deu_DEU

now it tells me that its set to "deu_DEU"

没有与该设置没有语言环境。所以我不能,即使检查其设置为正确的语言,因为我无法找到Locale对象具有匹配的值。

There is no Locale with that setting. So i cant even check if its set to the right language because i cant find the Locale object that has the matching values.

问题可能与到Android 4.3,但我没有找到任何信息。

Issue might be related to Android 4.3, but i didnt find any info.

背景是,我需要显示具有相同小数点符号的值,但TTS需要正确的符号,或者说点,在德国这是没有意义的。

Background is, that i need to show values with the same decimal symbol, but tts needs the correct symbol or it says "dot" in german which makes NO sense at all.

结论:

语言环境是指包含一个由一种语言,一个国家和一个可选的字符串的字符串的容器。每个文本到语音引擎可以返回一个自定义区域设置像eng_USA_texas

A Locale is a container that contains a string that is composed of a language, a country and an optional string. Every text-to-speech engine can return a custom Locale like "eng_USA_texas".

此外返回的TTS引擎,只能是势均力敌的比赛到想要的语言环境的语言环境。因此,EN_US而不是en_UK。

Furthermore the Locale that is returned by the tts engine can only be a "close match" to the wanted Locale. So "en_US" instead of "en_UK".

不过,现场有一个名为使用getLanguage()方法,并返回上述字符串的第一部分。 en或​​ENG。这些语言codeS由ISO调节,人们可以希望大家坚持它。 (见接受的答案链接)

However, Locale has a method called getLanguage() and it returns the first part of above mentioned string. "en" or "eng". Those Language codes are regulated by ISO and one can hope that everyone sticks to it. (see link in the accepted answer)

所以检查 tts.getLanguage()。使用getLanguage()。startsWith(EN)应始终是真实的,如果它的某种形式的英语语言设置和ISO标准得到满足。

So checking for tts.getLanguage().getLanguage().startsWith("en") should always be true if its some form of english language setting and the ISO standards are fulfilled.

有提及,语言环境不应被相比是重要locale_a == locale_b 既可以是不同的对象还具有相同的内容,它们是类的容器。
有总比 locale_a.equals(locale_b)

It is important to mention that Locales should not be compared by locale_a == locale_b as both can be different objects yet have the same content, they are containers of sort.
Always compare with locale_a.equals(locale_b)

我希望这可以帮助人们理清一些问题,TTS和语言

I hope this helps people sort out some problems with tts and language

推荐答案

您说的没错,这是令人沮丧的是如何现场codeS的TTS对象使用不同的那些设备的语言环境。我不明白为什么这个决定是。

You're right, it's frustrating how the locale codes the TTS object uses are different to those of the device locale. I don't understand why this decision was made.

要进一步增加复杂性,TTS引擎<一href="http://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine.html#EXTRA_AVAILABLE_VOICES"相对=nofollow>可以提供各种不同的语言环境,如eng_US_sarah或EN-US-女等,这是下降到TTS引擎如何将这些被存储并显示出来。

To add further complication, the TTS Engine can supply all kinds of different locales, such as eng_US_sarah or en-US-female etc. It's down to the TTS Engine how these are stored and displayed.

我不得不写额外的code遍历返回的语言环境,并试图将它们匹配区域设置的系统可以使用,或VICA亦然。

I've had to write additional code to iterate through the returned locales and attempt to match them to the locale the system can use, or vica-versa.

首先,来看看如何在引擎已安装<一href="http://developer.android.com/reference/android/speech/tts/TextToSpeechService.html#onIsLanguageAvailable%28java.lang.String,%20java.lang.String,%20java.lang.String%29"相对=nofollow>正在返回其语言环境信息。然后,您就可以开始在codeA名单进行整理,以deu_DEU'到'de_DE'对应关联。

To start with, take a look at how the engines you have installed are returning their locale information. You can then start to collate in your code a list to associate 'deu_DEU' to 'de_De'.

这是经常被使用拆分(_)&放简单化; startsWith(字符串),但不幸的是不是所有的语言环境。

This is often simplistic by using split("_") & startsWith(String), but unfortunately not for all locales.

下面是一些基本的code,我来分析已安装的TTS引擎区域结构。

Here's some base code I've used to analyse the installed TTS Engines' locale structure.

private void getEngines() {

    final Intent ttsIntent = new Intent();
    ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);

    final PackageManager pm = getActivity().getPackageManager();

    final List<ResolveInfo> list = pm.queryIntentActivities(ttsIntent, PackageManager.GET_META_DATA);

    final ArrayList<Intent> intentArray = new ArrayList<Intent>(list.size());

    for (int i = 0; i < list.size(); i++) {

        final Intent getIntent = new Intent();
        getIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);

        getIntent.setPackage(list.get(i).activityInfo.applicationInfo.packageName);
        getIntent.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);

        intentArray.add(getIntent);

    }

    for (int i = 0; i < intentArray.size(); i++) {
        startActivityForResult(intentArray.get(i), i);
    }
}

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {

    try {

        if (data != null) {             
            System.out.print(data.getStringArrayListExtra("availableVoices").toString());
        }

    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

从上面的 ISO-3 codeS 设备本地格式,你应该能够拿出一些对于语言环境,你所关心的。

From the above ISO-3 codes and the device locale format, you should be able to come up with something for the locales you are concerned with.

我已经打算提交增强请求以AOSP了一段时间,因为所有TTS引擎需要使用常量和演员诸如性别等需加入到使用TTS引擎,以自己的全部功能。

I've been intending to submit an enhancement request to AOSP for a while, as all TTS Engines need to use constant values and extras such as gender etc need to be added to use the TTS Engines to their full capabilities.

编辑:而且您的编辑,<一个href="http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#setLanguage%28java.util.Locale%29"相对=nofollow>注意措辞关于 setLanguage()。个人TTS引擎会尝试匹配尽可能靠近所请求的语言环境,但应用的区域可能是完全错误的,这取决于宽松的引擎供应商是<一个href="http://developer.android.com/reference/android/speech/tts/TextToSpeechService.html#onIsLanguageAvailable%28java.lang.String,%20java.lang.String,%20java.lang.String%29"相对=nofollow>在他们的code和他们的反应。

Further to your edit, note the wording regarding setLanguage(). The individual TTS Engine will try and match as close as possible to the requested locale, but that applied locale may be completely wrong, depending on how lenient the Engine provider is in their code and their response.

这篇关于设置一个现有的后文本到语音返回不同不存在的区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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