// ==UserScript== // @name 划词转语音播放 // @namespace http://tampermonkey // @version 1 // @description 划词转语音播放,支持中英文,需要联网使用百度语音合成API // @match *://*/* // @author wll // @icon https://img-blog.csdnimg.cn/20181221195058594.gif // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 监听鼠标划词事件 document.addEventListener('mouseup', function(event) { const selectedText = window.getSelection().toString().trim(); if (selectedText) { var msg = new SpeechSynthesisUtterance(selectedText); window.speechSynthesis.speak(msg); } }); })();