From 73b406814ae9fcfe68c10920e0a5373673d66c33 Mon Sep 17 00:00:00 2001 From: zhc077 <565291854> Date: Sat, 22 Apr 2023 14:07:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E5=AD=97=E8=BD=AC=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=204.22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ant-design-vue-jeecg/src/App.vue | 64 +++++----- .../src/views/message/Speak-TTS.vue | 119 ++++++++++++++++++ .../src/views/message/ZySpeechMessageList.vue | 19 ++- .../src/views/system/UserAnnouncementList.vue | 37 +++++- 4 files changed, 205 insertions(+), 34 deletions(-) create mode 100644 ant-design-vue-jeecg/src/views/message/Speak-TTS.vue diff --git a/ant-design-vue-jeecg/src/App.vue b/ant-design-vue-jeecg/src/App.vue index b0122c15..64c2753d 100644 --- a/ant-design-vue-jeecg/src/App.vue +++ b/ant-design-vue-jeecg/src/App.vue @@ -21,7 +21,7 @@ export default { // 定时器ID timer: null, // 定时器周期 - millisec: 30000, + millisec: 10000, url: { list: "/org.jeecg.modules.message/zySpeechMessage/list", edit: "/org.jeecg.modules.message/zySpeechMessage/edit", @@ -64,34 +64,42 @@ export default { } else { console.log("sorry,this browser,not supported TTS!!!") } - // this.speech.setLanguage('zh-CN'); this.speech.init({ 'volume': 1, - // 'lang': 'en-GB', 'lang': 'zh-CN', 'rate': 1, 'pitch': 1, - 'voice':'Google UK English Male', 'splitSentences': true, - }).then((data) => { - console.log('语音播报初始化完成...,配置参数:',data) + }).then((conf) => { + console.log('语音播报初始化完成...,Speech配置参数:', conf) }).catch(e => { console.error("An error occured while init : ", e) }) }, //语音播报 MySpeak(obj) { - console.log("MySpeak()接受到的消息:" + JSON.stringify(obj)) - this.speech.speak({text: obj['message']}).then(() => { - // console.log("MySpeak()播报完成...") - }) - console.log("MySpeak()播报完成...") - // this.updateMessageStatus(obj['id']); - }, - - speak() { - this.speech.speak({text: "欢迎关注小编"}).then(() => { - console.log("播报完成") + let mess = obj['message']; + console.log("----------speak()接受到的消息-----------【" + mess + "】"); + this.speech.speak({ + text: mess, + listeners: { + //开始播放 + onstart: () => { + console.log("Start utterance") + }, + //判断播放是否完毕 + onend: () => { + // console.log("End utterance"); + console.log("------------delete----------【" + mess + "】消息播报完成,删除该消息") + this.updateMessageStatus(obj['id']); + }, + //恢复播放 + onresume: () => { + console.log("Resume utterance") + }, + }, + }).then(() => { + // console.log("消息" + obj['id'] + "播报完成") }) }, @@ -101,15 +109,11 @@ export default { } getAction(this.url.list, parma).then((res) => { if (res.success) { - console.log("文字转语音消息列表>:" + JSON.stringify(res.result.records)); + console.log("------------getMessageList----------文字转语音消息列表>>>:" + JSON.stringify(res.result.records)); this.dataSource = res.result.records; this.dataSource.forEach(obj => { if (obj['status'] === '0') { - // this.speak(); this.MySpeak(obj); - // console.log("MySpeak()播报开始..."); - // this.speech.speak(obj['message']).then(() => { - // this.speak(); } }) } else { @@ -122,15 +126,18 @@ export default { }, updateMessageStatus(id) { - console.log("删除已播报消息:" + id); + // console.log("删除已播报消息:" + id); let parma = { "id": id, "status": '1', } putAction(this.url.edit, parma).then((res) => { if (res.success) { - this.dataSource.pop().id; - console.log(id + ">>>>>>>()之后:" + JSON.stringify(this.dataSource)) + for (let i = 0; i < this.dataSource.length; i++) { + if (this.dataSource[i].id === id) { + this.dataSource.splice(i, 1); + } + } } else { this.$message.warning(res.message) } @@ -142,14 +149,13 @@ export default { console.log("timer初始化完成:" + new Date().toLocaleString()) //上次播报列表播报完后,再获取新数据 this.timer = setInterval(() => { - // debugger + console.log("---未播报消息数量:", this.dataSource.length) if (this.dataSource.length === 0) { - console.log("timer is exec,the current time:" + new Date().toLocaleString()) + console.log("--------timer is exec,the current time:" + new Date().toLocaleString()) this.getMessageList(); } else { - console.log("hole down") + console.log("-------上次消息列表未处理完---HOLD DOWN") } - }, this.millisec) }, diff --git a/ant-design-vue-jeecg/src/views/message/Speak-TTS.vue b/ant-design-vue-jeecg/src/views/message/Speak-TTS.vue new file mode 100644 index 00000000..d2bd4c63 --- /dev/null +++ b/ant-design-vue-jeecg/src/views/message/Speak-TTS.vue @@ -0,0 +1,119 @@ + + + \ No newline at end of file diff --git a/ant-design-vue-jeecg/src/views/message/ZySpeechMessageList.vue b/ant-design-vue-jeecg/src/views/message/ZySpeechMessageList.vue index 24f0a725..d39fce8e 100644 --- a/ant-design-vue-jeecg/src/views/message/ZySpeechMessageList.vue +++ b/ant-design-vue-jeecg/src/views/message/ZySpeechMessageList.vue @@ -218,8 +218,23 @@ export default { //语音播报 MySpeak(message) { console.log("MySpeak()接受到的消息:" + message) - this.speech.speak({text: message}).then(() => { - // alert("MySpeak()播报完成..."); + this.speech.speak({ + text: message, + listeners: { + //开始播放 + onstart: () => { + console.log("Start utterance") + }, + //判断播放是否完毕 + onend: () => { + console.log("End utterance"); + }, + //恢复播放 + onresume: () => { + console.log("Resume utterance") + }, + }, + }).then(() => { console.log("MySpeak()播报完成...") }) }, diff --git a/ant-design-vue-jeecg/src/views/system/UserAnnouncementList.vue b/ant-design-vue-jeecg/src/views/system/UserAnnouncementList.vue index 2027d6ee..5419e7bf 100644 --- a/ant-design-vue-jeecg/src/views/system/UserAnnouncementList.vue +++ b/ant-design-vue-jeecg/src/views/system/UserAnnouncementList.vue @@ -193,11 +193,42 @@ export default { //语音播报 MySpeak() { - this.speech.speak({text: "测试javascript语音合成"}).then(() => { + this.speech.speak({ + text: "测试javascript语音合成", + listeners: { + //开始播放 + onstart: () => { + console.log("Start utterance") + }, + //判断播放是否完毕 + onend: () => { + console.log("End utterance"); + }, + //恢复播放 + onresume: () => { + console.log("Resume utterance") + }, + }, + }).then(() => { // alert("MySpeak()播报完成..."); - console.log("MySpeak()播报完成...") + console.log("MySpeak()---------------播报完成...") }) - } + }, + + //暂停 + paused() { + this.speech.pause(); + }, + //从暂停处继续播放 + goahead() { + this.speech.resume(); + console.log("继续播放-----------------------------") + }, + + //离开页面取消语音 + // destroyed() { + // this.speech.cancel(); + // }, } }