javascript Text to Speech arabic

2019-07-08 02:45发布

问题:

I'm trying to make SpeechSynthesisUtterance work for Arabic

It's working fine for English

$(document).ready(function() {
  var u1 = new SpeechSynthesisUtterance('Hello world!');
  u1.lang = 'en-US';
  u1.pitch = 20;
  u1.rate = 1;
  u1.voiceURI = 'native';
  u1.volume = 1000;
  speechSynthesis.speak(u1);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>

But when Arabic is used

$(document).ready(function() {
  var u1 = new SpeechSynthesisUtterance('عربي');
  u1.lang = 'ar-AE';
  u1.pitch = 20;
  u1.rate = 1;
  u1.voiceURI = 'native';
  u1.volume = 1000;
  speechSynthesis.speak(u1);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>

Any idea what I'm doing wrong?

回答1:

The SpeechSynthesisUtterance function doesn't support Arabic, and only supports the following languages with their respective voices :

speechSynthesis.onvoiceschanged = function() {
  var voices = this.getVoices();
  console.log(voices);
};