如何解决API级别30提供了印地语不支持的语言错误代码
我实现了文本到语音的转换,直到印地语的android API级别28都可以正常工作,但是在android API级别30中,它返回错误代码-2(不支持语言)。
private void setTextTospeech() {
textToSpeech = new TextToSpeech(mContext,new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
if (language.toLowerCase().contains(langaugeCodeEnglish)) {
int result = textToSpeech.setLanguage(new Locale("en","IN"));
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
//Toast.makeText(mContext,result + " is not supported",Toast.LENGTH_SHORT).show();
Log.e("Text2SpeechWidget",result + " is not supported");
}
} else {
int result = textToSpeech.setLanguage(new Locale("hi","IN"));
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
textToSpeech.setLanguage(Locale.forLanguageTag("hin"));
} else {
// Toast.makeText(mContext,result + "Language is not supported",Toast.LENGTH_SHORT).show();
Log.e("Text2SpeechWidget",result + "Language is not supported");
}
Log.e("Text2SpeechWidget",result + " is not supported");
}
}
}
}
});
}
private void speak(String s,String text) {
try{
float pitch = (float) 0.62;
float speed = (float) 0.86;
textToSpeech.setSpeechRate(speed);
textToSpeech.setPitch(pitch);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Bundle bundle = new Bundle();
bundle.putInt(TextToSpeech.Engine.KEY_ParaM_STREAM,AudioManager.STREAM_MUSIC);
textToSpeech.speak(s,TextToSpeech.QUEUE_FLUSH,bundle,null);
textToSpeech.speak(text,TextToSpeech.QUEUE_ADD,null);
} else {
HashMap<String,String> param = new HashMap<>();
param.put(TextToSpeech.Engine.KEY_ParaM_STREAM,String.valueOf(AudioManager.STREAM_MUSIC));
textToSpeech.speak(s,param);
textToSpeech.speak(text,param);
}
}catch (Exception ae){
ae.printstacktrace();
}
}
<queries>
...
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。