Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript Text to Speech arabic

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?

like image 633
user3515102 Avatar asked May 16 '26 12:05

user3515102


1 Answers

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);
};
like image 81
Alexandre Elshobokshy Avatar answered May 19 '26 00:05

Alexandre Elshobokshy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!