// ==UserScript== // @name 智能语音点读机 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1.0 // @description 哪里不会点哪里~! // @author 张仨 // @grant none // @match *://* // ==/UserScript== (function () { 'use strict'; function speak(sentence, pitch, rate) { var utterance = new SpeechSynthesisUtterance(sentence); //创建实例 sentence:要说的话 utterance.pitch = pitch; //pitch: 音调,取值范围(0 - 2) 默认值:1 utterance.rate = rate; //语速,取值范围(0.1 - 10) 默认值:1 window.speechSynthesis.speak(utterance); } //选中文本(松开鼠标)后开始播报 window.addEventListener('mouseup', () => { var txt = window.getSelection(); speak(txt, 1, 1) //对应sentence , pitch , rate 可自行调整 }) //TODO 以下功能暂未加入,哥哥们可以自己开发 //window.speechSynthesis.pause(); //暂停 //window.speechSynthesis.resume(); // 恢复 //window.speechSynthesis.cancel(); // 取消 })();