我正尝试通过google TTS语音合成器大声朗读印地文文本,由于我已经手动安装了印地文语音数据,因此在我的设备上运行良好,但是在另一台不包含印地文语音的设备上进行测试时,它没有显示下载特定语音数据的提示。这是部分代码:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
i{color:#000;font-size:30px!important}
.blueColor{color:#118de8}
</style>
<script>
$(document).ready(function(){
$("i").click(function(){
$(this).toggleClass("blueColor");
});
});
</script>
</head>
<body>
<i class="fa fa-chain-broken" aria-hidden="true"></i>
</body>
</html>
因此, @Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == ACT_CHECK_TTS_DATA) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// Data exists, so we instantiate the TTS engine
textToSpeech = new TextToSpeech(this, this);
} else {
// Data is missing, so we start the TTS
// installation process
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
似乎无法正常工作,但是我不知道它到底在做什么,我相信其余的代码很好。
我的问题有解决办法吗?
答案 0 :(得分:1)
使用以下方法来检查是否安装了可用的语言。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == VOICE_DATA_CHECK) {
ArrayList<String> availableLanguages =
data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
if (availableLanguages.isEmpty()) {
// no language data available, prompt for install
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
} else {
// some language data is available, create TTS instance
mTts = new TextToSpeech(this, this);
}
}
}