Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android TextToSpeech.LANG\u可用_Android_Locale_Text To Speech - Fatal编程技术网

android TextToSpeech.LANG\u可用

android TextToSpeech.LANG\u可用,android,locale,text-to-speech,Android,Locale,Text To Speech,我还在为我的tts而挣扎。在我的模拟器中一切都很好,但由于我的手机是瑞典语的,我需要检查Locale.US(我的文本是英语)并安装它。 和我以为我是这样做的,但是区域设置不可用,返回-1?我是不是做错了什么,我以为英语总是可以用的 public void onInit(int status) { // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. if (status == TextToSp

我还在为我的tts而挣扎。在我的模拟器中一切都很好,但由于我的手机是瑞典语的,我需要检查Locale.US(我的文本是英语)并安装它。 和我以为我是这样做的,但是区域设置不可用,返回-1?我是不是做错了什么,我以为英语总是可以用的

   public void onInit(int status) {
    // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
    if (status == TextToSpeech.SUCCESS) {
        // Set preferred language to US english.
        // Note that a language may not be available, and the result will indicate this.
        int result = mtts.setLanguage(Locale.US);

        if (result == TextToSpeech.LANG_MISSING_DATA ||
            result == TextToSpeech.LANG_NOT_SUPPORTED) {
           // Lanuage data is missing or the language is not supported.
            Log.e(TAG, "Language is not available.");
           //install it?

            result = mtts.isLanguageAvailable(Locale.US);
            if (result == TextToSpeech.LANG_AVAILABLE) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Language missing, install English speech?")
                   .setCancelable(false)
                   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {

                           //installera
                           Intent installIntent = new Intent();
                           installIntent.setAction(
                               TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                           startActivity(installIntent);


                       }
                   })
                   .setNegativeButton("No", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                       }
                   });
            AlertDialog alert = builder.create();
            } 
           //not installable
            Log.e(TAG, "Language not installable");

        } else {

            // The TTS engine has been successfully initialized.
            speak();
        }
    } else {
        // Initialization failed.
        Log.e(TAG, "Could not initialize TextToSpeech.");
    }
}

似乎有用。。如果手机未连接到计算机。我对此一无所知,但当我断开连接时,我再次运行了我的应用程序,它获取了语言包并安装了它,现在它能流利地说英语。

你有一个小错误。 而不是:

if (result == TextToSpeech.LANG_AVAILABLE) 
你应该:

if (result != TextToSpeech.LANG_AVAILABLE) 

然后对话框将显示

,所以,我昨晚编码时把一切都搞砸了。现在我看到一个对话框,问我是否应该安装这些语言,但当我单击“是”时,它就会进入市场并开始下载。。然后它向我抛出一个Java.io.IOException?关于androids安装过程,我可以做些什么?手机告诉我它已安装,但在设置mtts区域设置时,结果中仍然显示“-1”。谁知道如何安装已安装的软件包?