Skip to content

Instantly share code, notes, and snippets.

@netnr netnr/wsa.js

Created Dec 8, 2019
Embed
What would you like to do?
Web Speech API ,朗读页面选中的内容
var ssu = {
init: function () {
var txt = window.getSelection().toString();
ssu.speech(txt);
},
speech: function (txt) {
if (!txt || txt.trim() == "") {
txt = "未选择文字";
}
var ws = new window.SpeechSynthesisUtterance(txt);
window.speechSynthesis.speak(ws);
}
}
ssu.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.