文字转语音 4.22

zhc4dev
zhc077 2 years ago
parent 73b406814a
commit cb03926e0f
  1. 250
      ant-design-vue-jeecg/src/App.vue
  2. 134
      ant-design-vue-jeecg/src/views/message/ZySpeechMessageList.vue
  3. 5
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/message/controller/ZySpeechMessageController.java

@ -14,24 +14,22 @@ import {getAction, putAction} from "@api/manage";
export default { export default {
data() { data() {
return { return {
speech: null,
locale: zhCN, locale: zhCN,
// id
messageIds: [], // speech: null,
// ID // // ID
timer: null, // timer: null,
// // //
millisec: 10000, // millisec: 3000,
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",
}, // },
/* 数据源 */ // // id
dataSource: [], // messageList: [],
} }
}, },
created() { created() {
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> App is init")
let that = this let that = this
enquireScreen(deviceType => { enquireScreen(deviceType => {
// tablet // tablet
@ -51,119 +49,119 @@ export default {
}) })
}, },
mounted() { // mounted() {
this.speechInit(); // this.speechInit();
this.openTimer() // this.openTimer()
}, // },
methods: {
speechInit() {
this.speech = new Speech();
if (this.speech.hasBrowserSupport()) { // returns a boolean
console.log("this browser,supported TTS")
} else {
console.log("sorry,this browser,not supported TTS!!!")
}
this.speech.init({
'volume': 1,
'lang': 'zh-CN',
'rate': 1,
'pitch': 1,
'splitSentences': true,
}).then((conf) => {
console.log('语音播报初始化完成...,Speech配置参数:', conf)
}).catch(e => {
console.error("An error occured while init : ", e)
})
},
//
MySpeak(obj) {
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'] + "")
})
},
getMessageList() {
let parma = {
"status": '0',
}
getAction(this.url.list, parma).then((res) => {
if (res.success) {
console.log("------------getMessageList----------文字转语音消息列表>>>:" + JSON.stringify(res.result.records));
this.dataSource = res.result.records;
this.dataSource.forEach(obj => {
if (obj['status'] === '0') {
this.MySpeak(obj);
}
})
} else {
this.$message.warning(res.message)
}
}).finally(() => {
// this.loading = false
// this.loadData();
})
},
updateMessageStatus(id) {
// console.log("" + id);
let parma = {
"id": id,
"status": '1',
}
putAction(this.url.edit, parma).then((res) => {
if (res.success) {
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)
}
})
},
openTimer() {
this.closeTimer()
console.log("timer初始化完成:" + new Date().toLocaleString())
//
this.timer = setInterval(() => {
console.log("---未播报消息数量:", this.dataSource.length)
if (this.dataSource.length === 0) {
console.log("--------timer is exec,the current time:" + new Date().toLocaleString())
this.getMessageList();
} else {
console.log("-------上次消息列表未处理完---HOLD DOWN")
}
}, this.millisec)
},
/** 关闭定时器 */ // methods: {
closeTimer() { // speechInit() {
if (this.timer) clearInterval(this.timer) // this.speech = new Speech();
}, // if (this.speech.hasBrowserSupport()) { // returns a boolean
} // console.log("this browser,supported TTS")
// } else {
// console.log("sorry,this browser,not supported TTS!!!")
// }
// this.speech.init({
// 'volume': 1,
// 'lang': 'zh-CN',
// 'rate': 1,
// 'pitch': 1,
// 'splitSentences': true,
// }).then((conf) => {
// console.log('...,Speech:', conf)
// }).catch(e => {
// console.error("An error occured while init : ", e)
// })
// },
// //
// MySpeak(obj) {
// 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'] + "")
// })
// },
//
// getMessageList() {
// let parma = {
// "status": '0',
// }
// getAction(this.url.list, parma).then((res) => {
// if (res.success) {
// console.log("------------getMessageList---------->>>:" + JSON.stringify(res.result.records));
// this.messageList = res.result.records;
// this.messageList.forEach(obj => {
// if (obj['status'] === '0') {
// this.MySpeak(obj);
// }
// })
// } else {
// this.$message.warning(res.message)
// }
// }).finally(() => {
// // this.loading = false
// // this.loadData();
// })
// },
//
// updateMessageStatus(id) {
// // console.log("" + id);
// let parma = {
// "id": id,
// "status": '1',
// }
// putAction(this.url.edit, parma).then((res) => {
// if (res.success) {
// for (let i = 0; i < this.messageList.length; i++) {
// if (this.messageList[i].id === id) {
// this.messageList.splice(i, 1);
// }
// }
// } else {
// this.$message.warning(res.message)
// }
// })
// },
//
// openTimer() {
// this.closeTimer()
// console.log(">>>timer" + new Date().toLocaleString() + ",---: " + this.millisec+" ")
// //
// this.timer = setInterval(() => {
// console.log("---:", this.messageList.length)
// if (this.messageList.length === 0) {
// console.log("--------timer is exec,the current time:" + new Date().toLocaleString())
// this.getMessageList();
// } else {
// console.log("----------HOLD DOWN")
// }
// }, this.millisec)
// },
//
// /** */
// closeTimer() {
// if (this.timer) clearInterval(this.timer)
// },
// }
} }
</script> </script>
<style> <style>

@ -116,7 +116,7 @@ import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin' import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import ZySpeechMessageModal from './modules/ZySpeechMessageModal' import ZySpeechMessageModal from './modules/ZySpeechMessageModal'
import Speech from 'speak-tts' import Speech from 'speak-tts'
import {getAction} from "@api/manage"; import {getAction, putAction} from "@api/manage";
export default { export default {
name: 'ZySpeechMessageList', name: 'ZySpeechMessageList',
@ -175,51 +175,57 @@ export default {
], ],
url: { url: {
list: "/org.jeecg.modules.message/zySpeechMessage/list", list: "/org.jeecg.modules.message/zySpeechMessage/list",
edit: "/org.jeecg.modules.message/zySpeechMessage/edit",
getMessageList: "/org.jeecg.modules.message/zySpeechMessage/getMessageList", getMessageList: "/org.jeecg.modules.message/zySpeechMessage/getMessageList",
delete: "/org.jeecg.modules.message/zySpeechMessage/delete", delete: "/org.jeecg.modules.message/zySpeechMessage/delete",
deleteBatch: "/org.jeecg.modules.message/zySpeechMessage/deleteBatch", deleteBatch: "/org.jeecg.modules.message/zySpeechMessage/deleteBatch",
exportXlsUrl: "/org.jeecg.modules.message/zySpeechMessage/exportXls", exportXlsUrl: "/org.jeecg.modules.message/zySpeechMessage/exportXls",
importExcelUrl: "org.jeecg.modules.message/zySpeechMessage/importExcel",
}, },
dictOptions: {}, dictOptions: {},
superFieldList: [], superFieldList: [],
//
messageList: [], speech: null,
// ID // ID
timer: null, timer: null,
// //
millisec: 30000, millisec: 20000,
/* 数据源 */
messageList: [],
} }
}, },
created() {
// this.getMessageList(); mounted() {
// this.getSuperFieldList(); this.speechInit();
}, this.openTimer()
computed: {
importExcelUrl: function () {
return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
},
}, },
// mounted() {
// this.speechInit();
// this.openTimer()
// },
methods: { methods: {
speechInit() { speechInit() {
this.speech = new Speech(); this.speech = new Speech();
this.speech.setLanguage('zh-CN'); if (this.speech.hasBrowserSupport()) { // returns a boolean
this.speech.init().then(() => { console.log(">>>this browser,supported TTS")
console.log('语音播报初始化完成...') } else {
// this.MySpeak(); console.log("XXX----------------------sorry,this browser,not supported TTS!!!")
}
this.speech.init({
'volume': 1,
'lang': 'zh-CN',
'rate': 1,
'pitch': 1,
'splitSentences': true,
}).then((conf) => {
console.log('>>>语音播报初始化完成...,Speech配置参数:', conf)
}).catch(e => {
console.error("XXX------------------------An error occured while init : ", e)
}) })
}, },
// //
MySpeak(message) { MySpeak(obj) {
console.log("MySpeak()接受到的消息:" + message) let mess = obj['message'];
console.log("----------speak()接受到的消息-----------【" + mess + "】");
this.speech.speak({ this.speech.speak({
text: message, text: mess,
listeners: { listeners: {
// //
onstart: () => { onstart: () => {
@ -227,7 +233,9 @@ export default {
}, },
// //
onend: () => { onend: () => {
console.log("End utterance"); // console.log("End utterance");
console.log("------------delete----------【" + mess + "】消息播报完成,删除该消息")
this.updateMessageStatus(obj['id']);
}, },
// //
onresume: () => { onresume: () => {
@ -235,25 +243,22 @@ export default {
}, },
}, },
}).then(() => { }).then(() => {
console.log("MySpeak()播报完成...") // console.log("" + obj['id'] + "")
}) })
}, },
async getMessageList() { getMessageList() {
let parma = { let parma = {
"status": '0', "status": '0',
} }
let messageIds = [];
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)); console.log("------------getMessageList----------文字转语音消息列表>>>:" + JSON.stringify(res.result.records));
res.result.records.forEach(obj => { this.messageList = res.result.records;
// this.MySpeak(obj['message']); this.messageList.forEach(obj => {
// messageIds.push(obj['id']); if (obj['status'] === '0') {
this.speech.speak({text: obj['message']}).then(() => { this.MySpeak(obj);
// alert("MySpeak()..."); }
console.log("MySpeak()播报完成...")
})
}) })
} else { } else {
this.$message.warning(res.message) this.$message.warning(res.message)
@ -264,14 +269,39 @@ export default {
}) })
}, },
updateMessageStatus(id) {
// console.log("" + id);
let parma = {
"id": id,
"status": '1',
}
putAction(this.url.edit, parma).then((res) => {
if (res.success) {
for (let i = 0; i < this.messageList.length; i++) {
if (this.messageList[i].id === id) {
//datasource
this.messageList.splice(i, 1);
}
}
} else {
this.$message.warning(res.message)
}
})
},
openTimer() { openTimer() {
this.closeTimer() this.closeTimer()
console.log(">>>timer初始化完成【" + new Date().toLocaleString() + "】,---执行周期: " + this.millisec + " 毫秒")
//
this.timer = setInterval(() => { this.timer = setInterval(() => {
// if (this.$route.path === this.path) { console.log("---未播报消息数量:", this.messageList.length)
// this.loadData() // console.log("the messageList:", JSON.stringify(this.messageList));
// } if (this.messageList.length === 0) {
this.getMessageList(); console.log("--------timer is exec,the current time:" + new Date().toLocaleString())
console.log("the time is running,the current time:" + new Date().toLocaleString()) this.getMessageList();
} else {
console.log("-------上次消息列表未处理完---HOLD DOWN")
}
}, this.millisec) }, this.millisec)
}, },
@ -279,7 +309,25 @@ export default {
closeTimer() { closeTimer() {
if (this.timer) clearInterval(this.timer) if (this.timer) clearInterval(this.timer)
}, },
}
//
paused() {
this.speech.pause();
},
//
goahead() {
this.speech.resume();
console.log("继续播放-----------------------------")
},
},
//
destroyed() {
console.log("-----------关闭Timer、Speech---------------")
this.closeTimer();
this.speech.cancel();
},
} }
</script> </script>
<style scoped> <style scoped>

@ -44,7 +44,7 @@ public class ZySpeechMessageController extends JeecgController<ZySpeechMessage,
* @param req * @param req
* @return * @return
*/ */
@AutoLog(value = "生产消息播报-分页列表查询") // @AutoLog(value = "生产消息播报-分页列表查询")
@ApiOperation(value = "生产消息播报-分页列表查询", notes = "生产消息播报-分页列表查询") @ApiOperation(value = "生产消息播报-分页列表查询", notes = "生产消息播报-分页列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/list")
public Result<?> queryPageList(ZySpeechMessage zySpeechMessage, public Result<?> queryPageList(ZySpeechMessage zySpeechMessage,
@ -52,6 +52,7 @@ public class ZySpeechMessageController extends JeecgController<ZySpeechMessage,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) { HttpServletRequest req) {
QueryWrapper<ZySpeechMessage> queryWrapper = QueryGenerator.initQueryWrapper(zySpeechMessage, req.getParameterMap()); QueryWrapper<ZySpeechMessage> queryWrapper = QueryGenerator.initQueryWrapper(zySpeechMessage, req.getParameterMap());
queryWrapper.orderByAsc("create_time");
Page<ZySpeechMessage> page = new Page<ZySpeechMessage>(pageNo, pageSize); Page<ZySpeechMessage> page = new Page<ZySpeechMessage>(pageNo, pageSize);
IPage<ZySpeechMessage> pageList = zySpeechMessageService.page(page, queryWrapper); IPage<ZySpeechMessage> pageList = zySpeechMessageService.page(page, queryWrapper);
return Result.OK(pageList); return Result.OK(pageList);
@ -77,7 +78,7 @@ public class ZySpeechMessageController extends JeecgController<ZySpeechMessage,
* @param zySpeechMessage * @param zySpeechMessage
* @return * @return
*/ */
@AutoLog(value = "生产消息播报-编辑") // @AutoLog(value = "生产消息播报-编辑")
@ApiOperation(value = "生产消息播报-编辑", notes = "生产消息播报-编辑") @ApiOperation(value = "生产消息播报-编辑", notes = "生产消息播报-编辑")
@PutMapping(value = "/edit") @PutMapping(value = "/edit")
public Result<?> edit(@RequestBody ZySpeechMessage zySpeechMessage) { public Result<?> edit(@RequestBody ZySpeechMessage zySpeechMessage) {

Loading…
Cancel
Save