本文主要是介绍语音播报speechSynthesis最简单的例子(亲测有用),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最简单的例子,在chrome上亲测有效:
const utterThis = new SpeechSynthesisUtterance('我来试试呀');
const synth = window.speechSynthesis;
synth.speak(utterThis);
加入配置,可以配置语言、音量、语速、音高,继续玩:
const utterThis = new SpeechSynthesisUtterance();
utterThis.text = '我来试试呀';
utterThis.lang = 'zh-CN'; // 语言
// syu.lang = "en-US"; //语言
utterThis.volume = 1; // 音量:0~1,默认1
utterThis.rate = 1; // 语速:0.1~10,默认1
utterThis.pitch = 1; // 音高:0~2,默认1
const synth = window.speechSynthesis;
synth.speak(utterThis);
这篇关于语音播报speechSynthesis最简单的例子(亲测有用)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!