文字转语音 4.22

zhc4dev
zhc077 2 years ago
parent ae5d5108c1
commit 73b406814a
  1. 62
      ant-design-vue-jeecg/src/App.vue
  2. 119
      ant-design-vue-jeecg/src/views/message/Speak-TTS.vue
  3. 19
      ant-design-vue-jeecg/src/views/message/ZySpeechMessageList.vue
  4. 37
      ant-design-vue-jeecg/src/views/system/UserAnnouncementList.vue

@ -21,7 +21,7 @@ export default {
// ID // ID
timer: null, timer: null,
// //
millisec: 30000, millisec: 10000,
url: { url: {
list: "/org.jeecg.modules.message/zySpeechMessage/list", list: "/org.jeecg.modules.message/zySpeechMessage/list",
edit: "/org.jeecg.modules.message/zySpeechMessage/edit", edit: "/org.jeecg.modules.message/zySpeechMessage/edit",
@ -64,34 +64,42 @@ export default {
} else { } else {
console.log("sorry,this browser,not supported TTS!!!") console.log("sorry,this browser,not supported TTS!!!")
} }
// this.speech.setLanguage('zh-CN');
this.speech.init({ this.speech.init({
'volume': 1, 'volume': 1,
// 'lang': 'en-GB',
'lang': 'zh-CN', 'lang': 'zh-CN',
'rate': 1, 'rate': 1,
'pitch': 1, 'pitch': 1,
'voice':'Google UK English Male',
'splitSentences': true, 'splitSentences': true,
}).then((data) => { }).then((conf) => {
console.log('语音播报初始化完成...,配置参数:',data) console.log('语音播报初始化完成...,Speech配置参数:', conf)
}).catch(e => { }).catch(e => {
console.error("An error occured while init : ", e) console.error("An error occured while init : ", e)
}) })
}, },
// //
MySpeak(obj) { MySpeak(obj) {
console.log("MySpeak()接受到的消息:" + JSON.stringify(obj)) let mess = obj['message'];
this.speech.speak({text: obj['message']}).then(() => { console.log("----------speak()接受到的消息-----------【" + mess + "】");
// console.log("MySpeak()...") this.speech.speak({
}) text: mess,
console.log("MySpeak()播报完成...") listeners: {
// this.updateMessageStatus(obj['id']); //
onstart: () => {
console.log("Start utterance")
}, },
//
speak() { onend: () => {
this.speech.speak({text: "欢迎关注小编"}).then(() => { // console.log("End utterance");
console.log("播报完成") 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) => { getAction(this.url.list, parma).then((res) => {
if (res.success) { 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 = res.result.records;
this.dataSource.forEach(obj => { this.dataSource.forEach(obj => {
if (obj['status'] === '0') { if (obj['status'] === '0') {
// this.speak();
this.MySpeak(obj); this.MySpeak(obj);
// console.log("MySpeak()...");
// this.speech.speak(obj['message']).then(() => {
// this.speak();
} }
}) })
} else { } else {
@ -122,15 +126,18 @@ export default {
}, },
updateMessageStatus(id) { updateMessageStatus(id) {
console.log("删除已播报消息:" + id); // console.log("" + id);
let parma = { let parma = {
"id": id, "id": id,
"status": '1', "status": '1',
} }
putAction(this.url.edit, parma).then((res) => { putAction(this.url.edit, parma).then((res) => {
if (res.success) { if (res.success) {
this.dataSource.pop().id; for (let i = 0; i < this.dataSource.length; i++) {
console.log(id + ">>>>>>>()之后:" + JSON.stringify(this.dataSource)) if (this.dataSource[i].id === id) {
this.dataSource.splice(i, 1);
}
}
} else { } else {
this.$message.warning(res.message) this.$message.warning(res.message)
} }
@ -142,14 +149,13 @@ export default {
console.log("timer初始化完成:" + new Date().toLocaleString()) console.log("timer初始化完成:" + new Date().toLocaleString())
// //
this.timer = setInterval(() => { this.timer = setInterval(() => {
// debugger console.log("---未播报消息数量:", this.dataSource.length)
if (this.dataSource.length === 0) { 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(); this.getMessageList();
} else { } else {
console.log("hole down") console.log("-------上次消息列表未处理完---HOLD DOWN")
} }
}, this.millisec) }, this.millisec)
}, },

@ -0,0 +1,119 @@
<template>
<a-card :bordered="false">
<!-- 查询区域 -->
<div class="table-page-search-wrapper">
<a-form layout="inline" @keyup.enter.native="searchQuery">
<a-row :gutter="24">
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<a-button type="primary" @click="mySpeak" icon="search" style="margin-left: 8px">mySpeak</a-button>
<a-button type="primary" @click="play" icon="search" style="margin-left: 8px">读取</a-button>
<a-button type="primary" @click="goahead" icon="search" style="margin-left: 8px">前进</a-button>
<a-button type="primary" @click="paused" icon="reload" style="margin-left: 8px">暂停</a-button>
</span>
</a-col>
</a-row>
</a-form>
</div>
</a-card>
</template>
<script>
import Speech from 'speak-tts'
export default {
data() {
return {
speech: null
}
},
mounted() {
this.SpeechInit()
},
methods: {
SpeechInit() {
this.speech = new Speech()
this.speech.setLanguage('zh-CN')
/* this.speech.init({
'volume': 1,
// 'lang': 'en-US',
'lang': 'zh-CN',
'rate': 1,
'pitch': 1,
// 'voice':'Google UK English Male',
'splitSentences': true,
'listeners': {
'onvoiceschanged': (voices) => {
console.log("Event voiceschanged", voices)
}
}
})*/
// this.speech.init({
// 'volume': 1,
// 'lang': 'en-GB',
// 'rate': 1,
// 'pitch': 1,
// 'voice':'Google UK English Male',
// 'splitSentences': true,
// 'listeners': {
// 'onvoiceschanged': (voices) => {
// console.log("Event voiceschanged", voices)
// }
// }
// }).then((conf) => {
// console.log("the speech init,the config:",conf)
// })
},
mySpeak() {
this.speech.speak({
text: 'Hello, how are you today ?',
}).then(() => {
console.log("Success !")
}).catch(e => {
console.error("An error occurred :", e)
})
},
//
play() {
this.speech.speak({
text: "today ,tom收款203230元",
listeners: {
//
onstart: () => {
console.log("Start utterance")
},
//
onend: () => {
console.log("End utterance");
},
//
onresume: () => {
console.log("Resume utterance")
},
},
}).then(() => {
console.log("读取成功--------------------------------")
})
},
//
paused() {
this.speech.pause();
},
//
goahead() {
this.speech.resume();
console.log("继续播放-----------------------------")
},
//
// destroyed() {
// this.speech.cancel();
// },
}
}
</script>

@ -218,8 +218,23 @@ export default {
// //
MySpeak(message) { MySpeak(message) {
console.log("MySpeak()接受到的消息:" + message) console.log("MySpeak()接受到的消息:" + message)
this.speech.speak({text: message}).then(() => { this.speech.speak({
// alert("MySpeak()..."); text: message,
listeners: {
//
onstart: () => {
console.log("Start utterance")
},
//
onend: () => {
console.log("End utterance");
},
//
onresume: () => {
console.log("Resume utterance")
},
},
}).then(() => {
console.log("MySpeak()播报完成...") console.log("MySpeak()播报完成...")
}) })
}, },

@ -193,11 +193,42 @@ export default {
// //
MySpeak() { 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()..."); // alert("MySpeak()...");
console.log("MySpeak()播报完成...") console.log("MySpeak()---------------播报完成...")
}) })
} },
//
paused() {
this.speech.pause();
},
//
goahead() {
this.speech.resume();
console.log("继续播放-----------------------------")
},
//
// destroyed() {
// this.speech.cancel();
// },
} }
} }
</script> </script>

Loading…
Cancel
Save