window.URL = window.URL || window.webkitURL;
const response = `self.onmessage = ({ data: { data } }) => {
const {method} = data;
self.postMessage(method.replace("吗",""));
}`;
const blob = new Blob([response],{ type: "application/javascript" });
const work = new Worker(URL.createObjectURL(blob));
work.onmessage = function (e) {
// speechSynthesis.speak(new SpeechSynthesisUtterance(e.data))
alert(`Response: ${JSON.stringify(e)}`);
// URL.revokeObjectURL(url);//释放内存
// worker.terminate();
};
worker.postMessage({
method: "吃饭了吗"
});
动态创建 Web Worker 实践指南
评论
该文章已经关闭评论