From f494aae2c7f024ad17c6e27cdf8c6450c5146d72 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <1179705413@qq.com> Date: Wed, 7 Feb 2024 14:23:32 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=A8=A1=E7=89=88=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../green/html/mobile/book/book_content.html | 95 ++++++++++++++- templates/green/html/mobile/common/js.html | 2 +- templates/green/html/mobile/index.html | 111 +++++------------- templates/green/html/mobile/pay/index.html | 2 +- templates/green/html/mobile/user/login.html | 40 +++---- .../green/html/mobile/user/register.html | 23 ++-- templates/green/html/user/set_name.html | 2 +- templates/green/static/mobile/js/common.js | 12 +- 8 files changed, 163 insertions(+), 124 deletions(-) diff --git a/templates/green/html/mobile/book/book_content.html b/templates/green/html/mobile/book/book_content.html index d884013..59c91da 100644 --- a/templates/green/html/mobile/book/book_content.html +++ b/templates/green/html/mobile/book/book_content.html @@ -210,6 +210,26 @@ 字体: + + + + + + + + + + + +

@@ -241,7 +261,7 @@
-

     +

@@ -389,6 +409,79 @@ } + console.log(speechSynthesis.getVoices()); + + $(window).on('beforeunload', function () { + if (speechSynthesis.speaking) { + speechSynthesis.cancel() + } + }); + + function speakChapter() { + console.log('speechSynthesis.paused', speechSynthesis.paused) + console.log('speechSynthesis.pending', speechSynthesis.pending) + console.log('speechSynthesis.speaking', speechSynthesis.speaking) + if (speechSynthesis.speaking && !speechSynthesis.paused) { + speechSynthesis.pause(); + return; + } + if (speechSynthesis.speaking && speechSynthesis.paused) { + speechSynthesis.resume(); + } + speak({ + 'text': $('#chaptercontent').text(), + 'speechRate': 0.5, + 'pitch': 1, + 'lang': 'zh-CN' + }, function () { + console.log('语音播放结束'); + }, function () { + console.log('语音开始播放'); + }); + + + } + + /** + * @description 文字转语音方法 + * @public + * @param { text, rate, lang, volume, pitch } object + * @param text 要合成的文字内容,字符串 + * @param speechRate 读取文字的语速 0.1~10 正常1 + * @param lang 读取文字时的语言 + * @param volume 读取时声音的音量 0~1 正常1 + * @param voice 读取文字的语音服务 + * @param pitch 读取时声音的音高 0~2 正常1 + * @returns SpeechSynthesisUtterance + */ + function speak({text, speechRate, lang, volume, pitch, voice}, endEvent, startEvent) { + if (!window.SpeechSynthesisUtterance) { + console.warn('当前浏览器不支持文字转语音服务') + return; + } + + if (!text) { + return; + } + + const speechUtterance = new SpeechSynthesisUtterance(); + speechUtterance.text = text; + speechUtterance.rate = speechRate || 1; + speechUtterance.lang = lang || 'zh-CN'; + speechUtterance.volume = volume || 1; + speechUtterance.pitch = pitch || 1; + speechUtterance.voice = voice || null; + speechUtterance.onend = function () { + endEvent && endEvent(); + }; + speechUtterance.onstart = function () { + startEvent && startEvent(); + }; + speechSynthesis.speak(speechUtterance); + + return speechUtterance; + } + diff --git a/templates/green/html/mobile/common/js.html b/templates/green/html/mobile/common/js.html index e022d12..670ff69 100644 --- a/templates/green/html/mobile/common/js.html +++ b/templates/green/html/mobile/common/js.html @@ -1,3 +1,3 @@ - + diff --git a/templates/green/html/mobile/index.html b/templates/green/html/mobile/index.html index 25e1aa8..90ba611 100644 --- a/templates/green/html/mobile/index.html +++ b/templates/green/html/mobile/index.html @@ -41,18 +41,16 @@ } .user_link { - position: relative; - display: inline-block; vertical-align: middle; - line-height: 50px; - padding: 0 5px; - color: #fff; + line-height: 40px; float: right; + color: #3eaf7c; + padding: 11px 12px 0; } .user_link a { - color: #fff; + color: #3eaf7c; } @@ -64,92 +62,39 @@ - - - - -
+
-
+
-
+
diff --git a/templates/green/html/mobile/pay/index.html b/templates/green/html/mobile/pay/index.html index 35e75bf..362856b 100644 --- a/templates/green/html/mobile/pay/index.html +++ b/templates/green/html/mobile/pay/index.html @@ -5,7 +5,7 @@ - + diff --git a/templates/green/html/mobile/user/login.html b/templates/green/html/mobile/user/login.html index 5622acb..a5ac748 100644 --- a/templates/green/html/mobile/user/login.html +++ b/templates/green/html/mobile/user/login.html @@ -25,19 +25,20 @@
-
+
-
-
@@ -49,8 +50,8 @@
- - + + 注册
@@ -62,25 +63,25 @@
- \ No newline at end of file diff --git a/templates/green/html/mobile/user/register.html b/templates/green/html/mobile/user/register.html index 343606d..d9b2370 100644 --- a/templates/green/html/mobile/user/register.html +++ b/templates/green/html/mobile/user/register.html @@ -25,20 +25,21 @@
-
+
-
-
@@ -46,7 +47,7 @@
-
- - + + 登录
@@ -68,9 +69,9 @@
- \ No newline at end of file diff --git a/templates/green/html/user/set_name.html b/templates/green/html/user/set_name.html index 40e8037..e9cd0d8 100644 --- a/templates/green/html/user/set_name.html +++ b/templates/green/html/user/set_name.html @@ -27,7 +27,7 @@
  • 我的昵称
  •  用户名只能包括汉字、英文字母、数字和下划线
  •  登录|注册"); + // $(".user_link").html("登录注册"); } else { $.ajax({ type: "POST", @@ -118,10 +118,10 @@ if (!token) { dataType: "json", success: function (data) { if (data.code == 200) { - $(".user_link").html("" + - "\n" + - ""); + // $(".user_link").html("" + + // "\n" + + // ""); if ("/user/login.html" == window.location.pathname) { var orginUrl = getSearchString("originUrl"); window.location.href = orginUrl == undefined || orginUrl.isBlank() ? "/" : orginUrl; @@ -137,7 +137,7 @@ if (!token) { if (needLoginPath.indexOf(window.location.pathname) != -1) { location.href = '/user/login.html'; } - $(".user_link").html("登录注册"); + // $(".user_link").html("登录注册"); } }, error: function () {