文本到语音在模拟器上工作,但不在电话上

问题描述:

我已经经历了几乎所有与此主题相关的链接,但还没有找到任何合适的答案。我正在尝试为语音应用程序构建基本的文本。它在模拟器上工作得很好。但是当我在手机上运行它时,它显示不支持语言。 我想这与地区设置有关。默认区域中我的手机设置为en_US 我的代码如下:文本到语音在模拟器上工作,但不在电话上

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    tts = new TextToSpeech(this, this); 
    btnSpeak = (Button) findViewById(R.id.btnSpeak); 
    txtText = (EditText) findViewById(R.id.txtText); 
    btnSpeak.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View arg0) { 
      // Method yet to be defined 
      speakOut(); 
     } 

    }); 
} 

public void onInit(int status) { 
    // TODO Auto-generated method stub 
    // TTS is successfully initialized 
    if (status == TextToSpeech.SUCCESS) { 
     // Setting speech language 
     // System.out.println(Locale.getAvailableLocales()); 
     int result = tts.setLanguage(Locale.ENGLISH); 
     // int result = tts.setLanguage(Locale.getDefault()); 
     // If your device doesn't support language you set above 
     if (result == TextToSpeech.LANG_MISSING_DATA 
       || result == TextToSpeech.LANG_NOT_SUPPORTED) { 
      // Cook simple toast message with message 
      Toast.makeText(this, "Language not supported", 
        Toast.LENGTH_LONG).show(); 
      Log.e("TTS", "Language is not supported"); 

     } else { 
      btnSpeak.setEnabled(true); 
     } 
     // TTS is not initialized properly 
    } else { 
     Toast.makeText(this, "TTS Initilization Failed", Toast.LENGTH_LONG) 
       .show(); 
     Log.e("TTS", "Initilization Failed"); 
    } 
} 

private void speakOut() { 
    // Get the text typed 
    String text = txtText.getText().toString(); 
    // If no text is typed, tts will read out 'You haven't typed text' 
    // else it reads out the text you typed 
    if (text.length() == 0) { 
     tts.speak("You haven't typed text", TextToSpeech.QUEUE_FLUSH, null); 
    } else { 
     tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); 
    } 

} 

public void onDestroy() { 
    // Don't forget to shutdown! 
    if (tts != null) { 
     tts.stop(); 
     tts.shutdown(); 
    } 
    super.onDestroy(); 
} 

即使我使用int result = tts.setLanguage(Locale.getDefault());代替Locale.ENGLISH,它显示了相同的语言不支持的消息

logcat的错误:

02-26 16:24:57.492: I/TextToSpeech.java(23356): initTts() successfully bound to service 
02-26 16:24:58.015: E/TTS(23356): Language is not supported 

我与Android版本在我的电话 - 三星Galaxy-Y(GT-S5360)运行此2.3.6

+0

可能的重复:http://*.com/questions/13236771/android-speech-to-text-works-in-emulator-but-not-on-phone – 2013-02-26 10:52:48

+0

你有没有得到任何错误?如果可能,请显示错误日志 – 2013-02-26 10:53:45

+0

请添加您的tts对象的初始化代码,这将有助于指定您的手机及其操作系统版本 – 2013-02-26 10:55:15

自己找到了解决方案。问题在于Android默认tts引擎上可用的语言环境与我手机上的语言环境不匹配。
我安装了另一个tts引擎,它的工作原理非常好。