大声朗读 - TTS辅助阅读

极为好用的网页朗读器,集成微软/百度TTS,在浏览器上实时文本转语音 支持移动端| 全平台适用

  1. // ==UserScript==
  2. // @name 大声朗读 - TTS辅助阅读
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.2.2
  5. // @description 极为好用的网页朗读器,集成微软/百度TTS,在浏览器上实时文本转语音 支持移动端| 全平台适用
  6. // @author GAEE
  7. // @match http://*/*
  8. // @match https://*/*
  9. // @exclude https://example.com/
  10. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAeXUlEQVR4Xu1dC5hkVXGuuj37QPKpiyJhFUUjEGMC7IKCEQEVFA0YEYfE6OrC9K0zM+vqgsYX0SxRE5UgJCszc+rOLhsjiFk1aMCgokaFoPjCRFQMvnXxEQWREHZ2+la+wp7N7jDdfe7tc7vv7T7n++ZzpavqVP3n/H37nkcVQmgBgYBASwQwYBMQCAi0RiAQJMyOgEAbBAJBwvQICASChDkQEMiHQHiC5MMtaA0JAoEgQzLQIcx8CASC5MMtaA0JAoEgQzLQIcx8CASC5MMtaA0JAoEgQzLQIcx8CASC5MMtaA0JAoEgQzLQIcx8CASC5MMtaA0JAoEgQzLQIcx8CASC5MMtaA0JAoEgQzLQIcx8CASC5MMtaA0JAoEgQzLQIcx8CAwMQdatW7f/ypUrn4WIh4nIHQDwzSRJvpAPlqAVEPgNAgNBECKqA8AFAHDoooH9cBRF75iZmbmxSgO+YcOGh+3evXt1mqYPRcRf618URb9O0/QeZr63SrFU3dfKE4SI/gkARjsMxNOY+YayD9b4+PjpaZoSAJzRxtc5APgJANwhIj9BRP23/l0PAJ9n5t1lj7NK/lWaIHEcH42IX3EA/IvM/CQHub6JGGNIRGyXDuwSkU8g4udE5OYkST7apb2hV680QYwxl4rIK11GUURemiTJP7rI9lqmSfRPAcBDPff9DQC4BhGvsdZ+xrPtoTBXWYLU6/XHRlGkT4+HOI7Up5j5GY6yPRUzxoyLyHTBnX4RAK6t1W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PsnmeObsPGa+1MW3XsgEguyFchzHT0RETQ2ku7O9bt9i5iN8dEpEuvR8QitbWTLf+yRI88yZ7iMtrmu+x1UR+eMkST7sAwcfNgJBlkCRiI4TkUlE7OX7yX3MvJ+PQSWi5wNAy3rv/aq5rrHFcbweES9vEecOZj7bBwa+bASCtEGyXq8/I4oi/dl1li/A29i5hZldK2h1dIeIXgMAb18kuFNERrPUg/f5BFnwZan9KET8krX22I6B9VggEMQBcGPMaSJyEgDon56RKqJdyszn+TRsjHmRiGhJ7JWI+NFarfa+rAcuiyBI80mi16QfJyJziPj9LIcxfWLUyVYgSCeEFn0+Njb2mFqtdqqSBRFPEpGsKYeW6vFuPZzYryu/7SAoiiAZYe+beCBIl9AT0VoAOAUAlDT6v3mat+PZeToPBGmNQCCI5xlFRAenabp6ZGTkYBFZrX8AcLD+IaL+f/23/rfvIeIPEfEdMzMz13h2w5u58ATxBmUwNIgIBIIM4qiGmLwhEAjiDcpgaBARCAQZxFENMXlDIBDEG5TB0CAiEAgyiKMaYvKGQCCINyiDoUFEgIg07VHLw4UA8N/M3NerAkXiHvZBikR3AGwTkZ6sPaNVKCJyY5IkLU8OVx2CQJCqj2DB/hPR7wDA7a26yXIyuGBXCzEfCFIIrINllIg0MZtmL/yjhcj09G0URedOT0//x2BFu280gSCDPLqeY6vX6ydHUXSyngy21t7k2XwpzQWClHJYglNlQSAQpCwjEfwoJQKBIKUcluBUWRAIBCnLSAQ/SolAIEgphyU4VRYEAkHKMhLBj1IiEAhSymEJTpUFgUCQsoxE8KOUCASClHJYglNlQSAQpCwjEfwoJQKBIKUcluBUWRAIBCnLSAQ/SolAIEgphyU4VRYEAkHKMhLBj1IiEAhSymEJTpUFgUCQsoxE8KOUCASClHJYglNlQSAQpCwjEfwoJQKBIKUcluBUWRD4P/HrVZtVAZ9WAAAAAElFTkSuQmCC
  11. // @run-at document-end
  12. // @grant GM_download
  13. // @connect azure.microsoft.com
  14. // @connect ai.baidu.com
  15. // @grant GM_addStyle
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_openInTab
  19. // @grant GM_xmlhttpRequest
  20. // @grant GM_registerMenuCommand
  21. // @grant GM_unregisterMenuCommand
  22. // @grant GM_notification
  23. // @grant unsafeWindow
  24. // @license none
  25. // @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
  26. // @require https://greasyfork.org/scripts/442967-tts-sdk/code/TTS_SDK.js?version=1037522
  27. // @require https://cdn.jsdelivr.net/npm/microsoft-cognitiveservices-speech-sdk@1.15.1/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js
  28. /* globals jQuery, $, waitForKeyElements */
  29. // ==/UserScript==
  30. //this.$ = this.jQuery = jQuery.noConflict(true);
  31. let version = "0.3.2.2 Alpha 实验版";
  32. var Global_TEXT = "";
  33. var MicrosoftTTS_info = {
  34. person: "zh-CN-XiaoxiaoNeural",
  35. speed: 1,
  36. pitch: 1,
  37. status: false,
  38. };
  39. var BaiduTTS_info = {
  40. person: 4003,
  41. speed: 5,
  42. pitch: 5,
  43. status: false,
  44. };
  45. var info = {
  46. type: "microsoft",
  47. };
  48. var setting = {
  49. version: version,
  50. speech_type: "all_text",
  51. };
  52. var TTS_GLOBAL,TTS_MORE_GLOBAL;
  53.  
  54. (function() {
  55. 'use strict';
  56.  
  57. init_voice_setting();
  58.  
  59. GM_addStyle('body{user-select:auto !important; -webkit-user-select:auto !important; -moz-user-select:auto !important; -ms-user-select:auto !important; }');
  60. GM_addStyle('#GAEE_TTS_IFRAME,.div {bottom: 10%;transform: translate(10px);position: fixed;z-index: 1000;background-spanor: transparent;transform: translate(0);}.TTS_Button {display: flex;justify-content: center;align-items: center;height: 31px;width: 20px;border-radius: 8px;padding: 7px 12px;font-size: 12px;spanor: #969696;//border-radius: 50%;box-shadow: 0 2px 10px rgb(0 0 0 / 5%);background-spanor: white;background: rgba(255, 255, 255, 0.9);margin-left: 8px;transform-origin: center;transition: .2s;cursor: pointer;flex-direction: spanumn;}.TTS_Button:hover {background: #e3e5e7;}.TTS_Card {position: fixed;//position:relative;box-sizing: border-box;padding: 18px;width: 360px;height: 200px;border-radius: 8px;background: white;box-shadow: 0 3px 12px rgb(0 0 0 / 20%);font-size: 16px;bottom: 18%;margin-left: 9px;-moz-user-select: none;-khtml-user-select: none;user-select: none;z-index: 1000;}.TTS_Card .close {position: absolute;top: 14px;right: 14px;width: 14px;height: 14px;cursor: pointer;}.TTS_Card .title {margin-bottom: 16px;margin-left: 2px;//spanor: black;//font-size: 16px;line-height: 22px;display: flex;}.TTS_Card .title .title_text {spanor: black;font-size: 16px;margin-right: 30px;}.TTS_Card .title .TTS_Change {display: flex;}.TTS_Card .title .TTS_Change .il {margin-left: 40px;font-size: 16px;font-family: "微软雅黑";color: #969696;border-bottom: 2px solid #ffffff;cursor: pointer;}.TTS_Card .title .TTS_Change .il:hover {border-bottom: 2px dashed #F00;}.TTS_Card .title .TTS_Change .il:focus {outline: none;border-bottom: 2px solid #F00;}.TTS_Card .login-tip-content-item>* {display: flex;align-items: center;margin-bottom: 14px;width: 50%;height: 26px;}.setting {//position:relative;position: absolute;weight: 100%;height: auto;//max-height: 145px;//background:green;//overflow: auto;}.setting .row {margin: auto;max-height: 50px;width: 100%;overflow: auto;// overflow-x: scroll;// overflow-y: hidden;//white-space: nowrap;margin-bottom: 12px;}.setting .col {width: auto;}.setting .span {width: 70px;height: 30px;float: left;margin-right: 1px;//color: red;color: #2C3E50;cursor: pointer;}.setting .setting_down {display: flex;}.setting .speech_set {font-size: 13px;margin-top: 3px;}.setting .slider {width: 170px;height: 20px;margin: 0;transform-origin: 75px 75px;}.setting .others {display: flex;font-size: inherit;margin-left: auto;}.setting .others .more {background-color: #DCDCDC;border: 1px solid #DCDCDC;color: #fff;display: inline-block;font-size: 9px;padding: 2px 18px;height: 20px;cursor: pointer;}.setting .others .listen {background-color: #0078d4;border: 1px solid #0078d4;border-radius: 3px;color: #fff;display: inline-block;font-size: 9px;padding: 5px 8px;cursor: pointer;}.setting .others .more:active {background-color: #C0C0C0;}.setting .others .listen:active {background-color: #0062ad;}::-webkit-scrollbar {width: 4px;height: 4px;background-color: transparent;}::-webkit-scrollbar-track {-webkit-box-shadow: inset 0 0 6px transparent;border-radius: 10px;background-color: white;}::-webkit-scrollbar-thumb {border-radius: 10px;-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .3);background-color: #555;}.setting a {color: #2a5caa;text-decoration: none;}');
  61.  
  62. let BUTTON = '<div class="div"><div class="TTS_Button" id="TTS_Button"><svg width="1.7em" height="1.7em" t="1649228019321" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2481" width="200" height="200"><path id="icon-start" d="M920.8 600.5V491c0-55.7-11-109.8-32.7-160.9-20.9-49.3-50.9-93.6-88.9-131.6-38.1-38.1-82.4-68-131.6-88.9-51.1-21.7-105.2-32.7-160.9-32.7s-109.8 11-160.9 32.7c-49.3 20.9-93.6 50.9-131.6 88.9-38.1 38.1-68 82.4-88.9 131.6-21.9 51.1-32.9 105.2-32.9 160.9v109.5c-21.7 33.2-33.2 73.2-33.2 115.6 0 42.6 11.6 82.7 33.4 116 17.8 27.2 41.7 47.9 68.5 59.8 9.6 32.2 39.5 55.7 74.7 55.7H265c43 0 78-35 78-78v-307c0-43-35-78-78-78h-29.2c-35.2 0-65.1 23.5-74.7 55.7-4.3 1.9-8.6 4.1-12.8 6.5V491c0-48.1 9.5-94.9 28.2-139 18.1-42.6 44-81 77-113.9 33-33 71.3-58.9 113.9-77 44.1-18.7 90.9-28.2 139-28.2 48.1 0 94.9 9.5 139 28.2 42.6 18.1 81 44 113.9 77 33 33 58.9 71.3 77 113.9 18.7 44.1 28.2 90.9 28.2 139v55.8c-4.2-2.4-8.4-4.6-12.8-6.5-9.6-32.2-39.5-55.7-74.7-55.7h-29.2c-43 0-78 35-78 78v307c0 43 35 78 78 78H777c35.2 0 65.1-23.5 74.7-55.7 26.8-12 50.7-32.7 68.5-59.8 21.9-33.3 33.4-73.4 33.4-116 0.4-42.4-11.1-82.3-32.8-115.6z" fill="#969696" p-id="2482"></path><path id="icon-playing" d="M512 816.213333c-23.466667 0-42.666667-19.2-42.666667-42.666666V250.88c0-23.466667 19.2-42.666667 42.666667-42.666667s42.666667 19.2 42.666667 42.666667v522.666667c0 23.466667-19.2 42.666667-42.666667 42.666666zM341.333333 597.333333c-23.466667 0-42.666667-19.2-42.666666-42.666666v-85.333334c0-23.466667 19.2-42.666667 42.666666-42.666666s42.666667 19.2 42.666667 42.666666v85.333334c0 23.466667-19.2 42.666667-42.666667 42.666666zM853.333333 640c-23.466667 0-42.666667-19.2-42.666666-42.666667v-170.666666c0-23.466667 19.2-42.666667 42.666666-42.666667s42.666667 19.2 42.666667 42.666667v170.666666c0 23.466667-19.2 42.666667-42.666667 42.666667zM170.666667 682.666667c-23.466667 0-42.666667-19.2-42.666667-42.666667V384c0-23.466667 19.2-42.666667 42.666667-42.666667s42.666667 19.2 42.666666 42.666667v256c0 23.466667-19.2 42.666667-42.666666 42.666667zM682.666667 727.893333c-23.466667 0-42.666667-19.2-42.666667-42.666666V338.773333c0-23.466667 19.2-42.666667 42.666667-42.666666s42.666667 19.2 42.666666 42.666666v346.88a42.666667 42.666667 0 0 1-42.666666 42.24z" fill="#969696" p-id="1413"></path></svg></div></div>';
  63. let CARD = '<div class="TTS_Card" id="TTS_Card"><div class="close" id="card_close"><svg viewBox="0 0 100 100"><path d="M2 2 L98 98 M 98 2 L2 98Z" stroke-width="10px" stroke="#969696" stroke-linecap="round"></path></svg></div><div class="title"><div class="title_text"> TTS</div><div class="TTS_Change"><div id="microsoft" tabindex="1" class="il"> 微软</div><div id="baidu" tabindex="2" class="il" style="border-bottom: 2px solid #F00;"> 百度</div><div id="about" tabindex="3" class="il"> 关于</div></div></div><div class="card"><div class="setting" id="microsoft_card" style="display: none;"><div> 代码正在构建中</div></div><div class="setting" id="baidu_card" style="display: show;"><div class="row"><div class="col"><div class="span" aria-label="4003"> 度逍遥</div><div class="span" aria-label="4115"> 度小贤</div><div class="span" aria-label="4119"> 度小鹿</div><div class="span" aria-label="4100"> 度小雯</div><div class="span" aria-label="4106"> 度博文</div><div class="span" aria-label="4103"> 度米朵</div></div></div><div class="speech_set"><label for="speed" id="speedlabel">语速: 5</label><div class="slider"><input type="range" id="speed" name="speed" min="0" max="15" value="5" class="slider__input" data-bi-id="demo-rate-slider" aria-label="语速"></div></div><div class="speech_set"><label for="pitch" id="pitchlabel">音调: 5</label><div class="slider"><input type="range" id="pitch" name="pitch" min="0" max="15" value="5" class="slider__input" data-bi-id="demo-pitch-slider" aria-label="音调"></div></div></div></div><div class="setting" id="about_card" style="display: none;"><div> 本项目由GAEE维护支持 <a href="https://greasyfork.org/zh-CN/scripts/429810-%E5%A4%A7%E5%A3%B0%E6%9C%97%E8%AF%BB">首页</a></div><div><img style="height:32%;width:32%;" src="https://img.github.luxe/2022/d1807e2d06008.png" alt="90kskmwly1smny0t4dz6vh750k8n.png" title="支持一下" /></div></div></div>';
  64.  
  65. if(!document.querySelector("#GAEE_TTS_IFRAME")){
  66. var b = document.createElement('iframe');
  67. b.setAttribute("id","GAEE_TTS_IFRAME");
  68. b.setAttribute("title","GAEE_TTS");
  69. b.style.cssText = "height:60px; width:70px; border: unset; scrolling:no; display: flex;";
  70. document.body.appendChild(b);
  71. }
  72. var _TTS_ = document.querySelector("#GAEE_TTS_IFRAME");
  73. TTS_GLOBAL = $($("#GAEE_TTS_IFRAME")[0].contentWindow.document);
  74. add_TTS_Style(_TTS_.contentWindow.document,'.div {bottom: 10px;transform: translate(10px);position: fixed;z-index: 1000;background-spanor: transparent;transform: translate(0);}.TTS_Button {display: flex;justify-content: center;align-items: center;height: 31px;width: 20px;border-radius: 8px;padding: 7px 12px;font-size: 12px;spanor: #969696;//border-radius: 50%;box-shadow: 0 2px 10px rgb(0 0 0 / 5%);background-spanor: white;background: rgba(255, 255, 255, 0.9);margin-left: 8px;transform-origin: center;transition: .2s;cursor: pointer;flex-direction: spanumn;}.TTS_Button:hover {background: #e3e5e7;}.TTS_Card {position: fixed;//position:relative;box-sizing: border-box;padding: 18px;width: 360px;height: 200px;border-radius: 8px;background: white;box-shadow: 0 3px 12px rgb(0 0 0 / 20%);font-size: 16px;bottom: unset;margin-left: 9px;-moz-user-select: none;-khtml-user-select: none;user-select: none;z-index: 1000;}.TTS_Card .close {position: absolute;top: 14px;right: 14px;width: 14px;height: 14px;cursor: pointer;}.TTS_Card .title {margin-bottom: 16px;margin-left: 2px;//spanor: black;//font-size: 16px;line-height: 22px;display: flex;}.TTS_Card .title .title_text {spanor: black;font-size: 16px;margin-right: 30px;}.TTS_Card .title .TTS_Change {display: flex;}.TTS_Card .title .TTS_Change .il {margin-left: 40px;font-size: 16px;font-family: "微软雅黑";color: #969696;border-bottom: 2px solid #ffffff;cursor: pointer;}.TTS_Card .title .TTS_Change .il:hover {border-bottom: 2px dashed #F00;}.TTS_Card .title .TTS_Change .il:focus {outline: none;border-bottom: 2px solid #F00;}.TTS_Card .login-tip-content-item>* {display: flex;align-items: center;margin-bottom: 14px;width: 50%;height: 26px;}.setting {//position:relative;position: absolute;weight: 100%;height: auto;//max-height: 145px;//background:green;//overflow: auto;}.setting .row {margin: auto;max-height: 50px;width: 100%;overflow: auto;// overflow-x: scroll;// overflow-y: hidden;//white-space: nowrap;margin-bottom: 12px;}.setting .col {width: auto;}.setting .span {width: 70px;height: 30px;float: left;margin-right: 1px;//color: red;color: #2C3E50;cursor: pointer;}.setting .setting_down {display: flex;}.setting .speech_set {font-size: 13px;margin-top: 3px;}.setting .slider {width: 170px;height: 20px;margin: 0;transform-origin: 75px 75px;}.setting .others {display: flex;font-size: inherit;margin-left: auto;}.setting .others .more {background-color: #DCDCDC;border: 1px solid #DCDCDC;color: #fff;display: inline-block;font-size: 9px;padding: 2px 18px;height: 20px;cursor: pointer;}.setting .others .listen {background-color: #0078d4;border: 1px solid #0078d4;border-radius: 3px;color: #fff;display: inline-block;font-size: 9px;padding: 5px 8px;cursor: pointer;}.setting .others .more:active {background-color: #C0C0C0;}.setting .others .listen:active {background-color: #0062ad;}::-webkit-scrollbar {width: 4px;height: 4px;background-color: transparent;}::-webkit-scrollbar-track {-webkit-box-shadow: inset 0 0 6px transparent;border-radius: 10px;background-color: white;}::-webkit-scrollbar-thumb {border-radius: 10px;-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .3);background-color: #555;}.setting a {color: #2a5caa;text-decoration: none;}');
  75. _TTS_.contentWindow.document.body.innerHTML = BUTTON;
  76.  
  77. UIinit();
  78. rebind();
  79.  
  80. var timeOutEvent,mobile_timeOutEvent;
  81. var longClick = 0;
  82. var mobile_longClick = 0;
  83. TTS_GLOBAL.find("#TTS_Button").on({
  84. mousedown: function(e) {
  85. if(e && e.preventDefault) {
  86. e.preventDefault();
  87. }
  88. longClick = 0;
  89. timeOutEvent = setTimeout(function() {
  90. longClick = 1;
  91. ShowCard();
  92. }, 300);
  93. },
  94. mouseup: function() {
  95. clearTimeout(timeOutEvent);
  96. },
  97. click: function(e) {
  98. clearTimeout(timeOutEvent);
  99. if (longClick == 0) {
  100. CLICKED();
  101. }
  102. return false;
  103. }
  104. });
  105. TTS_GLOBAL.find("#TTS_Button").on({
  106. touchstart: function(e) {
  107. mobile_longClick = 0;
  108. mobile_timeOutEvent = setTimeout(function() {
  109. mobile_longClick = 1;
  110. ShowCard();
  111. }, 300);
  112. },
  113. touchmove: function(e) {
  114. clearTimeout(mobile_timeOutEvent);
  115. mobile_timeOutEvent = 0;
  116. e.preventDefault();
  117. },
  118. touchend: function(e) {
  119. clearTimeout(mobile_timeOutEvent);
  120. if (mobile_timeOutEvent != 0 && mobile_longClick == 0) {
  121. CLICKED();
  122. }
  123. return false;
  124. }
  125. });
  126. function CLICKED(){
  127. init();
  128. var TEXT = "";
  129. if(setting.speech_type == "all_text"){
  130. TEXT = window.getSelection().toString() || Get_InnerText();
  131. }else if(setting.speech_type == "next_text"){
  132. TEXT = Get_InnerText().slice(Get_InnerText().indexOf(window.getSelection().toString()));
  133. }
  134. if(info.type == "baidu"){
  135. if(!BaiduTTS_info.status){
  136. BaiduTTS(TEXT);
  137. }
  138. }else if(info.type == "microsoft"){
  139. if(!MicrosoftTTS_info.status){
  140. AzureTTS(TEXT);
  141. }
  142. }
  143. }
  144. })();
  145.  
  146. function add_TTS_Style(_TTS_,css) {
  147. var head, style;
  148. head = _TTS_.getElementsByTagName('head')[0];
  149. if (!head) { console.log("未能添加TTS样式");return; }
  150. style = document.createElement('style');
  151. style.type = 'text/css';
  152. style.innerHTML = css;
  153. head.appendChild(style);
  154. }
  155.  
  156. function change_TTS_Size(w,h){
  157. $("#GAEE_TTS_IFRAME").width(w);
  158. $("#GAEE_TTS_IFRAME").height(h);
  159. }
  160.  
  161. function UIinit() {
  162. icon_change("init");
  163. TTS_GLOBAL.find('.span').css('color', '#2C3E50');
  164. TTS_GLOBAL.find('.span').each(function() {
  165. if (info.type == "baidu") {
  166. ShowBaiduCard();
  167. if ($(this).attr('aria-label') == BaiduTTS_info.person) {
  168. $(this).css('color', 'red');
  169. }
  170. } else if (info.type == "microsoft") {
  171. ShowMicrosoftCard();
  172. if ($(this).attr('aria-label') == MicrosoftTTS_info.person) {
  173. $(this).css('color', 'red');
  174. }
  175. }
  176. });
  177. TTS_GLOBAL.find("#microsoft_speedlabel").text("\u8bed\u901f: " + MicrosoftTTS_info.speed);
  178. TTS_GLOBAL.find("#microsoft_pitchlabel").text("\u97f3\u8c03: " + MicrosoftTTS_info.pitch);
  179. TTS_GLOBAL.find("#microsoft_speed").val(MicrosoftTTS_info.speed*100-100);
  180. TTS_GLOBAL.find("#microsoft_pitch").val(MicrosoftTTS_info.pitch*50-50);
  181. TTS_GLOBAL.find("#baidu_speedlabel").text("\u8bed\u901f: " + BaiduTTS_info.speed);
  182. TTS_GLOBAL.find("#baidu_pitchlabel").text("\u97f3\u8c03: " + BaiduTTS_info.pitch);
  183. TTS_GLOBAL.find("#baidu_speed").val(BaiduTTS_info.speed);
  184. TTS_GLOBAL.find("#baidu_pitch").val(BaiduTTS_info.pitch);
  185. }
  186.  
  187. function UIinit2(){
  188. if(setting.speech_type == "all_text"){
  189. TTS_MORE_GLOBAL.find("#c1").prop("checked",false);
  190. }else if(setting.speech_type == "next_text"){
  191. TTS_MORE_GLOBAL.find("#c1").prop("checked",true);
  192. }
  193. }
  194.  
  195. function ShowMicrosoftCard() {
  196. TTS_GLOBAL.find("#microsoft_card").show();
  197. TTS_GLOBAL.find("#baidu_card").hide();
  198. TTS_GLOBAL.find("#about_card").hide();
  199. TTS_GLOBAL.find("#microsoft").css("border-bottom", "2px solid #F00");
  200. TTS_GLOBAL.find("#baidu").css("border-bottom", "");
  201. TTS_GLOBAL.find("#about").css("border-bottom", "");
  202. }
  203.  
  204. function ShowBaiduCard() {
  205. TTS_GLOBAL.find("#microsoft_card").hide();
  206. TTS_GLOBAL.find("#baidu_card").show();
  207. TTS_GLOBAL.find("#about_card").hide();
  208. TTS_GLOBAL.find("#microsoft").css("border-bottom", "");
  209. TTS_GLOBAL.find("#baidu").css("border-bottom", "2px solid #F00");
  210. TTS_GLOBAL.find("#about").css("border-bottom", "");
  211. }
  212.  
  213. function ShowAboutCard() {
  214. TTS_GLOBAL.find("#microsoft_card").hide();
  215. TTS_GLOBAL.find("#baidu_card").hide();
  216. TTS_GLOBAL.find("#about_card").show();
  217. TTS_GLOBAL.find("#microsoft").css("border-bottom", "");
  218. TTS_GLOBAL.find("#baidu").css("border-bottom", "");
  219. TTS_GLOBAL.find("#about").css("border-bottom", "2px solid #F00");
  220. }
  221.  
  222. function rebind() {
  223. TTS_GLOBAL.find("#microsoft_speed").change(function() {
  224. var i = $(this).val();
  225. var n = (i - (-100)) / (200 - (-100)) * 3;
  226. var speedValue = Math.abs(n) < 1 ? n.toPrecision(2) : n.toPrecision(3);
  227. TTS_GLOBAL.find("#microsoft_speedlabel").text("\u8bed\u901f: " + speedValue);
  228. MicrosoftTTS_info.speed = speedValue;
  229. });
  230. TTS_GLOBAL.find("#microsoft_pitch").change(function() {
  231. var i = $(this).val();
  232. var n = (i - (-50)) / (50 - (-50)) * 2;
  233. var pitchValue = Math.abs(n) < 1 ? n.toPrecision(2) : n.toPrecision(3);
  234. TTS_GLOBAL.find("#microsoft_pitchlabel").text("\u97f3\u8c03: " + pitchValue);
  235. MicrosoftTTS_info.pitch = pitchValue;
  236. });
  237. TTS_GLOBAL.find("#baidu_speed").change(function() {
  238. var speedValue = $(this).val();
  239. TTS_GLOBAL.find("#baidu_speedlabel").text("\u8bed\u901f: " + speedValue);
  240. BaiduTTS_info.speed = speedValue;
  241. });
  242. TTS_GLOBAL.find("#baidu_pitch").change(function() {
  243. var pitchValue = $(this).val();
  244. TTS_GLOBAL.find("#baidu_pitchlabel").text("\u97f3\u8c03: " + pitchValue);
  245. BaiduTTS_info.pitch = pitchValue;
  246. });
  247. TTS_GLOBAL.find('.span').on('click', function(e) {
  248. TTS_GLOBAL.find('.span').css('color', '#2C3E50');
  249. TTS_GLOBAL.find(this).css('color', 'red');
  250. var id = $(this).parent().parent().parent().attr('id');
  251. if (id == "baidu_card") {
  252. BaiduTTS_info.person = $(this).attr('aria-label');
  253. info.type = "baidu";
  254. } else if (id == "microsoft_card") {
  255. MicrosoftTTS_info.person = $(this).attr('aria-label');
  256. info.type = "microsoft";
  257. }
  258. });
  259. TTS_GLOBAL.find(".more").click(function() {
  260. Show_more_card();
  261. });
  262. TTS_GLOBAL.find(".listen").click(function() {
  263. TryListen();
  264. });
  265. TTS_GLOBAL.find("#card_close").click(function() {
  266. TTS_GLOBAL.find("#TTS_Card").remove();
  267. change_TTS_Size(70,60);
  268. voice_setting();
  269. });
  270. TTS_GLOBAL.find("#microsoft").click(function() {
  271. ShowMicrosoftCard();
  272. });
  273. TTS_GLOBAL.find("#baidu").click(function() {
  274. ShowBaiduCard();
  275. });
  276. TTS_GLOBAL.find("#about").click(function() {
  277. ShowAboutCard();
  278. });
  279. }
  280.  
  281. function rebind2(){
  282. TTS_MORE_GLOBAL.find("#c1").click(function() {
  283. if($(this).prop("checked")){
  284. setting.speech_type = "next_text";
  285. }else{
  286. setting.speech_type = "all_text";
  287. }
  288. });
  289. TTS_MORE_GLOBAL.find("#card_close").click(function() {
  290. $("#GAEE_TTS_MORE").remove();
  291. voice_setting();
  292. });
  293. }
  294.  
  295. function ShowCard() {
  296. if (TTS_GLOBAL.find("#TTS_Card").length > 0) {
  297. return;
  298. }
  299. change_TTS_Size(387,275);
  300. let CARD =
  301. `<div class="TTS_Card" id="TTS_Card"><div class="close" id="card_close"><svg viewBox="0 0 100 100"><path d="M2 2 L98 98 M 98 2 L2 98Z" stroke-width="10px" stroke="#969696" stroke-linecap="round"></path></svg></div><div class="title"><div class="title_text"> TTS</div><div class="TTS_Change"><div id="microsoft" tabindex="1" class="il"> 微软</div><div id="baidu" tabindex="2" class="il" style="border-bottom: 2px solid #F00;"> 百度</div><div id="about" tabindex="3" class="il"> 关于</div></div></div><div class="card"><div class="setting" id="microsoft_card" style="display: none;"><div class="row"><div class="col"><div class="span" aria-label="zh-CN-XiaoxiaoNeural"> 晓晓</div><div class="span" aria-label="zh-CN-XiaochenNeural"> 晓辰</div><div class="span" aria-label="zh-CN-YunxiNeural"> 云希</div><div class="span" aria-label="zh-CN-YunyangNeural"> 云扬</div><div class="span" aria-label="zh-CN-XiaohanNeural"> 晓涵</div><div class="span" aria-label="zh-CN-XiaoqiuNeural"> 晓秋</div><div class="span" aria-label="zh-CN-XiaoxuanNeural"> 晓萱</div><div class="span" aria-label="zh-CN-XiaoyanNeural"> 晓颜</div><div class="span" aria-label="zh-CN-XiaoyouNeural"> 晓悠</div><div class="span" aria-label="zh-CN-XiaoshuangNeural"> 晓双</div><div class="span" aria-label="zh-CN-YunyeNeural"> 云野</div></div></div><div class="setting_down"><div class="setting_sp"><div class="speech_set"><label for="speed" id="microsoft_speedlabel">语速: 1.00</label><div class="slider"><input type="range" id="microsoft_speed" name="speed" min="-100" max="200" value="0" class="slider__input" data-bi-id="demo-rate-slider" aria-label="语速"></div></div><div class="speech_set"><label for="pitch" id="microsoft_pitchlabel">音调: 0.00</label><div class="slider"><input type="range" id="microsoft_pitch" name="pitch" min="-50" max="50" value="0" class="slider__input" data-bi-id="demo-pitch-slider" aria-label="音调"></div></div></div><div class="others"><div style="margin-right:80px;width:100%;display: flex;flex-wrap: wrap-reverse;"><button class="more" type="button">更多</button></div><button class="listen" type="button">试听</button></div></div></div><div class="setting" id="baidu_card" style="display: show;"><div class="row"><div class="col"><div class="span" aria-label="4003"> 度逍遥</div><div class="span" aria-label="4115"> 度小贤</div><div class="span" aria-label="4119"> 度小鹿</div><div class="span" aria-label="4100"> 度小雯</div><div class="span" aria-label="4106"> 度博文</div><div class="span" aria-label="4103"> 度米朵</div></div></div><div class="setting_down"><div class="setting_sp"><div class="speech_set"><label for="speed" id="baidu_speedlabel">语速: 5</label><div class="slider"><input type="range" id="baidu_speed" name="speed" min="0" max="15" value="5" class="slider__input" data-bi-id="demo-rate-slider" aria-label="语速"></div></div><div class="speech_set"><label for="pitch" id="baidu_pitchlabel">音调: 5</label><div class="slider"><input type="range" id="baidu_pitch" name="pitch" min="0" max="15" value="5" class="slider__input" data-bi-id="demo-pitch-slider" aria-label="音调"></div></div></div><div class="others"><div style="margin-right:80px;width:100%;display: flex;flex-wrap: wrap-reverse;"><button class="more" type="button">更多</button></div><button class="listen" type="button">试听</button></div></div></div></div><div class="setting" id="about_card" style="display: none;"><div style="font-family: 'Lucida Console', 'Courier New', monospace;"> 本项目由GAEE维护支持<a href="https://greasyfork.org/zh-CN/scripts/429810-%E5%A4%A7%E5%A3%B0%E6%9C%97%E8%AF%BB" target="_parent">首页</a></div><div><img style="height:auto;width:31%;" src="https://img.github.luxe/2022/d1807e2d06008.png" alt="90kskmwly1smny0t4dz6vh750k8n.png" title="支持一下" /></div></div></div>`;
  302. TTS_GLOBAL.find("body").append(CARD);
  303. UIinit();
  304. rebind();
  305. }
  306.  
  307. function Show_more_card(){
  308. if(!document.querySelector("#GAEE_TTS_MORE")){
  309. var a = document.createElement('div');
  310. a.setAttribute("id","GAEE_TTS_MORE");
  311. document.body.appendChild(a);
  312. var b = document.createElement('iframe');
  313. b.setAttribute("id","GAEE_TTS_MORE_IFRAME");
  314. b.setAttribute("title","GAEE_TTS_MORE_IFRAME");
  315. b.style.cssText = "position: fixed;display: block;border-radius: 8px;border: unset; scrolling:no;left: 50%;top: 50%;z-index: 10001;-webkit-transform: translate(-50%, -50%);-ms-transform: translate(-50%, -50%);-o-transform: translate(-50%, -50%);-moz-transform: translate(-50%, -50%);transform: translate(-50%, -50%);background-color: #fff;";
  316. a.appendChild(b);
  317. let CARD = `<div class="card"><div class="title"><div class="title_text">TTS 高级设置</div><div class="close" id="card_close"><svg viewBox="0 0 100 100"><path d="M2 2 L98 98 M 98 2 L2 98Z" stroke-width="10px" stroke="#969696" stroke-linecap="round"></path></svg></div></div><div class="line"><div class="info" style="float:left; margin-right:20px">从选中位置开始朗读</div><div class="click" style="float:right;"><input type="checkbox" name="checkbox" id="c1" class="chooseBtn" /><label for="c1" class="choose-label"></label></div></div></div>`;
  318. $($("#GAEE_TTS_MORE_IFRAME")[0].contentWindow.document).find("body").append(CARD);
  319. }
  320. var _TTS_ = document.querySelector("#GAEE_TTS_MORE_IFRAME");
  321. TTS_MORE_GLOBAL = $($("#GAEE_TTS_MORE_IFRAME")[0].contentWindow.document);
  322. add_TTS_Style(_TTS_.contentWindow.document,'.card {user-select: none;}.chooseBtn {display: none;}.choose-label {box-shadow: #ccc 0px 0px 0px 1px;width: 40px;height: 20px;display: inline-block;border-radius: 20px;position: relative;background-color: #bdbdbd;overflow: hidden;}.choose-label:before {content: "";position: absolute;left: 0;width: 20px;height: 20px;display: inline-block;border-radius: 20px;background-color: #fff;z-index: 20;-webkit-transition: all 0.5s;transition: all 0.5s;}.chooseBtn:checked+label.choose-label:before {left: 20px;}.chooseBtn:checked+label.choose-label {background-color: #51ccee;}.close {position: absolute;top: 14px;right: 14px;width: 14px;height: 14px;cursor: pointer;}.title {margin-bottom: 16px;margin-left: 2px;line-height: 22px;display: flex;}.title .title_text {spanor: black;font-size: 16px;margin-right: 30px;}');
  323. UIinit2();
  324. rebind2();
  325. }
  326.  
  327. function Get_InnerText(){
  328. var text = document.body.innerText;
  329. text = escapeHtml(text);
  330. text = cleanHtml(text);
  331. text = text.replace(/<[^<>]+>/g,"");
  332. //console.log(text);
  333. return text;
  334. }
  335. function escapeHtml(String) {
  336. return String.replace(/&quot;/g, '"').replace(/&#039;/g, "'").replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
  337. }
  338. function cleanHtml(String){
  339. let s_a = /<script[^<>]*>/g;
  340. let s_b = /<\/script>/g;
  341. var text = "";
  342. text = String.split(s_a)[0];
  343. for (var i = 1; i < String.split(s_a).length; i++) {
  344. var a = String.split(s_a)[i];a=a.split(s_b)[1];
  345. text+=a;
  346. }
  347. //console.log(text);
  348. return text;
  349. }
  350.  
  351. function init(){
  352. if(!document.querySelector("#GAEE_TTS")){
  353. var audio = document.createElement('audio');
  354. audio.setAttribute("id","GAEE_TTS");
  355. //audio.setAttribute("controls","controls");
  356. audio.setAttribute("hidden","true");
  357. document.body.appendChild(audio);
  358. audio.addEventListener('ended', function () {
  359. console.log("end");
  360. icon_change("end");
  361. BaiduTTS_info.status = false;
  362. if(Global_TEXT.length != 0){
  363. BaiduTTS(Global_TEXT);
  364. }
  365. }, false);
  366. }
  367. }
  368.  
  369. function play(data){
  370. $(document).ready(function() {
  371. BaiduTTS_info.status = true;
  372. console.log("start");
  373. icon_change("play");
  374. toPlay(data);
  375. TTS_GLOBAL.find("#TTS_Button").click(function() {
  376. if(BaiduTTS_info.status && info.type == "baidu"){
  377. console.log("pause");
  378. icon_change("end");
  379. var a = document.getElementById('GAEE_TTS');
  380. a !== null && a.pause();
  381. a = null;
  382. BaiduTTS_info.status = false;
  383. }
  384. });
  385. TTS_GLOBAL.find("#TTS_Button").on("touchstart", function() {
  386. if(BaiduTTS_info.status && info.type == "baidu"){
  387. console.log("pause");
  388. icon_change("end");
  389. var a = document.getElementById('GAEE_TTS');
  390. a !== null && a.pause();
  391. a = null;
  392. BaiduTTS_info.status = false;
  393. }
  394. });
  395. });
  396. }
  397.  
  398. function toPlay(data){
  399. var audioBlob = toBlob(data);
  400. var blobUrl = window.URL.createObjectURL(audioBlob);
  401. document.getElementById('GAEE_TTS').src = blobUrl;
  402. var audio = document.getElementById('GAEE_TTS');
  403. audio.play();
  404. if (audio.paused) {
  405. audio.paused=false;
  406. audio.play();
  407. }
  408. }
  409.  
  410. function toBlob(dataurl) {
  411. var arr = dataurl.split(','),
  412. mime = arr[0].match(/:(.*?);/)[1],
  413. bstr = atob(arr[1]),
  414. n = bstr.length,
  415. u8arr = new Uint8Array(n);
  416. while (n--) {
  417. u8arr[n] = bstr.charCodeAt(n);
  418. }
  419. return new Blob([u8arr], {
  420. type: mime
  421. });
  422. }
  423.  
  424. function icon_change(type){
  425. if(type=="play"){
  426. TTS_GLOBAL.find("#icon-start").hide();
  427. TTS_GLOBAL.find("#icon-playing").show();
  428. }else if(type=="end" || type=="init"){
  429. TTS_GLOBAL.find("#icon-start").show();
  430. TTS_GLOBAL.find("#icon-playing").hide();
  431. }
  432. }
  433.  
  434. function BaiduTTS(TEXT){
  435. var str = TEXT;
  436. var slen = 150;
  437. var elen = 200;
  438. var len = elen;
  439. var _a = str.slice(slen,elen);
  440. if(_a.indexOf("。")!=-1){
  441. len = slen + _a.indexOf("。") + 1;
  442. Global_TEXT = str.slice(len,TEXT.length);
  443. }else{
  444. Global_TEXT = str.slice(len,TEXT.length);
  445. }
  446. var BaiduTTS_postdata = "type=tns&per="+BaiduTTS_info.person+"&spd="+BaiduTTS_info.speed+"&pit="+BaiduTTS_info.pitch+"&vol=5&aue=6&tex="+encodeURIComponent(str.slice(0,len));
  447. GM_xmlhttpRequest({
  448. url:"https://ai.baidu.com/aidemo",
  449. method :"POST",
  450. data:BaiduTTS_postdata,
  451. headers: {
  452. 'Content-Type': 'application/x-www-form-urlencoded',
  453. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36 Edg/100.0.1185.29',
  454. 'Referer': 'https://ai.baidu.com/tech/speech/tts_online'
  455. },
  456. onload:function(r){
  457. //console.log(r.responseText);
  458. let result = JSON.parse(r.responseText);
  459. if(result.errno=="0"){
  460. play(result.data);
  461. BaiduTTS_info.status = false;
  462. }else if(result.errno=="110"){
  463. if(!BaiduTTS_info.status){
  464. BaiduTTS_info.status = true;
  465. BaiduTTS("当前文本中可能存在敏感内容,百度TTS已拒绝了该请求");
  466. }else{
  467. BaiduTTS_info.status = false;
  468. }
  469. }
  470. else{
  471. console.log("请求失败:"+r.responseText);
  472. BaiduTTS_info.status = false;
  473. }
  474. }
  475. });
  476. }
  477.  
  478. function AzureTTS(TEXT){
  479. M_TTS(TEXT,"97421c82cec5dff4eb742cc0246691d8820c81f04ab72b6edf4284924ef1a7a5");
  480. return;
  481. GM_xmlhttpRequest({
  482. url: "https://azure.microsoft.com/zh-cn/services/cognitive-services/text-to-speech/?Voice",
  483. method: "GET",
  484. headers: {
  485. 'Content-Type': 'application/x-www-form-urlencoded',
  486. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36 Edg/100.0.1185.29'
  487. },
  488. onload: function(r) {
  489. var a = r.responseText.split("global.instanceId = '")[1].split("';")[0];
  490. M_TTS(TEXT,a);
  491. }
  492. });
  493. }
  494.  
  495. var a = null;
  496. function M_TTS(TEXT, token) {
  497. var str = TEXT;
  498. var slen = 450;
  499. var elen = 500;
  500. var len = elen;
  501. var _a = str.slice(slen,elen);
  502. if(_a.indexOf("。")!=-1){
  503. len = slen + _a.indexOf("。") + 1;
  504. Global_TEXT = str.slice(len,TEXT.length);
  505. }else{
  506. Global_TEXT = str.slice(len,TEXT.length);
  507. }
  508. TEXT = str.slice(0,len);
  509. $(document).ready(function() {
  510. MicrosoftTTS_info.status = true;
  511. console.log("start");
  512. var s = window.SpeechSDK;
  513. function play(){
  514. var config = s.SpeechTranslationConfig.fromEndpoint(new URL('wss://eastus.api.speech.microsoft.com/cognitiveservices/websocket/v1?TrafficType=AzureDemo')),
  515. synthesizer,
  516. audioConfig;
  517. config.speechSynthesisOutputFormat = s.SpeechSynthesisOutputFormat.Audio24Khz96KBitRateMonoMp3;
  518. a = new s.SpeakerAudioDestination();
  519. icon_change("play");
  520. a.onAudioEnd = function() {
  521. console.log("end");
  522. icon_change("end");
  523. MicrosoftTTS_info.status = false;
  524. if(Global_TEXT.length != 0){
  525. AzureTTS(Global_TEXT);
  526. }
  527. };
  528. audioConfig = s.AudioConfig.fromSpeakerOutput(a);
  529. synthesizer = new s.SpeechSynthesizer(config, audioConfig);
  530. synthesizer.synthesisCompleted = function () {
  531. synthesizer.close();
  532. synthesizer = null;
  533. };
  534. synthesizer.SynthesisCanceled = function (s, e) {
  535. var r;
  536. r = s.CancellationDetails.fromResult(e);
  537. r.reason === s.CancellationReason.Error;
  538. };
  539. synthesizer.speakSsmlAsync(TextFormat(TEXT), function() {}, function(n) {
  540. console.log("Error:" + n);
  541. MicrosoftTTS_info.status = false;
  542. });
  543. }
  544. play();
  545. TTS_GLOBAL.find("#TTS_Button").click(function() {
  546. if(MicrosoftTTS_info.status && info.type == "microsoft"){
  547. console.log("pause");
  548. icon_change("end");
  549. a !== null && a.pause();
  550. a = null;
  551. MicrosoftTTS_info.status = false;
  552. }
  553. });
  554. TTS_GLOBAL.find("#TTS_Button").on("touchstart", function() {
  555. if(MicrosoftTTS_info.status && info.type == "microsoft"){
  556. console.log("pause");
  557. icon_change("end");
  558. a !== null && a.pause();
  559. a = null;
  560. MicrosoftTTS_info.status = false;
  561. }
  562. });
  563. function TextFormat(TEXT) {
  564. // var n = '<prosody rate="{SPEED}" pitch="{PITCH}">{TEXT}<\/prosody>',
  565. // t;
  566. // n = n.replace("{SPEED}", "0" + "%");
  567. // n = n.replace("{PITCH}", "0" + "%");
  568. // u.selectedIndex === 0 && (p.hidden || o.selectedIndex === 0) || (n = "<mstts:express-as {STYLE_ATTRIBUTE} {ROLE_PLAY_ATTRIBUTE}>{0}<\/mstts:express-as>".replace("{0}", n), n = u.selectedIndex !== 0 ? n.replace("{STYLE_ATTRIBUTE}",
  569. // 'style="' + u[u.selectedIndex].value + '"') : n.replace("{STYLE_ATTRIBUTE}", ""), n = p.hidden || o.selectedIndex === 0 ? n.replace("{ROLE_PLAY_ATTRIBUTE}", "") : n.replace("{ROLE_PLAY_ATTRIBUTE}", 'role="' + o[o
  570. // .selectedIndex].value + '"'));
  571. // n = '<voice name="{VOICE}">{0}<\/voice>'.replace("{0}", n);
  572. // n = n.replace("{VOICE}", i[Config.selectedIndex].value);
  573. // t = d.value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
  574. // k.hidden || (t = '<lang xml:lang="{SECONDARY_LOCALE}">{0}<\/lang>'.replace("{0}", t), t = t.replace("{SECONDARY_LOCALE}", c[c.selectedIndex].value));
  575. // n = '<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US">{0}<\/speak>'.replace("{0}", n);
  576. // n = n.replace("{TEXT}", t);
  577. var n =
  578. `<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US"><voice name="{|_PERSON_|}"><prosody rate="{|_SPEED_|}%" pitch="{|_PITCH_|}%">{|_TEXT_|}</prosody></voice></speak>`;
  579. n = n.replace("{|_PERSON_|}", MicrosoftTTS_info.person);
  580. n = n.replace("{|_SPEED_|}", MicrosoftTTS_info.speed*100-100);
  581. n = n.replace("{|_PITCH_|}", MicrosoftTTS_info.pitch*50-50);
  582. n = n.replace("{|_TEXT_|}", TEXT);
  583. return n;
  584. }
  585. });
  586. }
  587.  
  588. function TryListen(){
  589. init();
  590. let TEXT = "测试成功! 当前版本为 "+version+"。很高兴与你相遇!";
  591. if (info.type == "baidu") {
  592. BaiduTTS(TEXT);
  593. } else if (info.type == "microsoft") {
  594. AzureTTS(TEXT);
  595. }
  596. }
  597.  
  598. function init_voice_setting(){
  599. var Info_ALL = [MicrosoftTTS_info, BaiduTTS_info, info, setting];
  600. if(GM_getValue("GAEE_TTS_voice_info") == null || GM_getValue("GAEE_TTS_voice_info")[3] == null){
  601. GM_setValue("GAEE_TTS_voice_info", Info_ALL);
  602. }else{
  603. Info_ALL = GM_getValue("GAEE_TTS_voice_info");
  604. MicrosoftTTS_info = Info_ALL[0];
  605. BaiduTTS_info = Info_ALL[1];
  606. info = Info_ALL[2];
  607. setting = Info_ALL[3];
  608. }
  609. MicrosoftTTS_info.status = false;
  610. BaiduTTS_info.status = false;
  611. }
  612.  
  613. function voice_setting(){
  614. var Info_ALL = [MicrosoftTTS_info, BaiduTTS_info, info, setting];
  615. GM_setValue("GAEE_TTS_voice_info", Info_ALL);
  616. }
  617.  
  618. registerMenuCommand();
  619. function registerMenuCommand() {
  620. GM_registerMenuCommand(`🏁 \u7248\u672c\u4fe1\u606f ${version}`, function () {window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/429810', {active: true,insert: true,setParent: true});});
  621. //menu_ID[menu_ID.length] = GM_registerMenuCommand('💬 \u53cd\u9988 & \u5efa\u8bae', function () {window.GM_openInTab('', {active: true,insert: true,setParent: true});});
  622. }