教浏览器说话

function say(text, lang) {
    var synth = speechSynthesis;

    var utter = new SpeechSynthesisUtterance(text);
    utter.voice = synth.getVoices().find(v => v.lang === lang);

    synth.speak(utter)
}

用法示例

say(‘你好’,’zh-CN’);

发表评论