Speech synthesis (experimental) 语音合成(试验功能)
使用 SpeechSynthesisUtterance.voice
和 indow.speechSynthesis.getVoices()
将消息转换为语音。 使用 window.speechSynthesis.speak()
来播放消息。
了解更多关于 SpeechSynthesisUtterance interface of the Web Speech API.
const speak = message => {
const msg = new SpeechSynthesisUtterance(message);
msg.voice = window.speechSynthesis.getVoices()[0];
window.speechSynthesis.speak(msg);
};
// speak('Hello, World') -> plays the message