Skip to content

Instantly share code, notes, and snippets.

@reeonce
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save reeonce/13ccc1788cab8dae2321 to your computer and use it in GitHub Desktop.

Select an option

Save reeonce/13ccc1788cab8dae2321 to your computer and use it in GitHub Desktop.
speechSynthesis js, it is working on Safari
function speech() {
var voices = window.speechSynthesis.getVoices();
var zhVoices = voices.filter(function (ele) { return ele.lang.match(/zh.*/i); });
var foo = new SpeechSynthesisUtterance('世界你好!');
foo.lang = 'zh-CN';
foo.voice = zhVoices[0];
foo.volume = 1; // 0 to 1
foo.rate = 1; // 0.1 to 10
foo.pitch = 1.5; //0 to 2
foo.voiceURI = 'native';
window.speechSynthesis.speak(foo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment