文字转语音 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 {
data() {
return {
speech: null,
locale: zhCN,
// id
messageIds: [],
// ID
timer: null,
//
millisec: 10000,
url: {
list: "/org.jeecg.modules.message/zySpeechMessage/list",
edit: "/org.jeecg.modules.message/zySpeechMessage/edit",
},
/* 数据源 */
dataSource: [],
// speech: null,
// // ID
// timer: null,
// //
// millisec: 3000,
// url: {
// list: "/org.jeecg.modules.message/zySpeechMessage/list",
// edit: "/org.jeecg.modules.message/zySpeechMessage/edit",
// },
// // id
// messageList: [],
}
},
created() {
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> App is init")
let that = this
enquireScreen(deviceType => {
// tablet
@ -51,119 +49,119 @@ export default {
})
},
mounted() {
this.speechInit();
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)
},
// mounted() {
// this.speechInit();
// this.openTimer()
// },
/** 关闭定时器 */
closeTimer() {
if (this.timer) clearInterval(this.timer)
},
}
// 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.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>
<style>

@ -116,7 +116,7 @@ import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import ZySpeechMessageModal from './modules/ZySpeechMessageModal'
import Speech from 'speak-tts'
import {getAction} from "@api/manage";
import {getAction, putAction} from "@api/manage";
export default {
name: 'ZySpeechMessageList',
@ -175,51 +175,57 @@ export default {
],
url: {
list: "/org.jeecg.modules.message/zySpeechMessage/list",
edit: "/org.jeecg.modules.message/zySpeechMessage/edit",
getMessageList: "/org.jeecg.modules.message/zySpeechMessage/getMessageList",
delete: "/org.jeecg.modules.message/zySpeechMessage/delete",
deleteBatch: "/org.jeecg.modules.message/zySpeechMessage/deleteBatch",
exportXlsUrl: "/org.jeecg.modules.message/zySpeechMessage/exportXls",
importExcelUrl: "org.jeecg.modules.message/zySpeechMessage/importExcel",
},
dictOptions: {},
superFieldList: [],
//
messageList: [],
speech: null,
// ID
timer: null,
//
millisec: 30000,
millisec: 20000,
/* 数据源 */
messageList: [],
}
},
created() {
// this.getMessageList();
// this.getSuperFieldList();
},
computed: {
importExcelUrl: function () {
return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
},
mounted() {
this.speechInit();
this.openTimer()
},
// mounted() {
// this.speechInit();
// this.openTimer()
// },
methods: {
speechInit() {
this.speech = new Speech();
this.speech.setLanguage('zh-CN');
this.speech.init().then(() => {
console.log('语音播报初始化完成...')
// this.MySpeak();
if (this.speech.hasBrowserSupport()) { // returns a boolean
console.log(">>>this browser,supported TTS")
} else {
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) {
console.log("MySpeak()接受到的消息:" + message)
MySpeak(obj) {
let mess = obj['message'];
console.log("----------speak()接受到的消息-----------【" + mess + "】");
this.speech.speak({
text: message,
text: mess,
listeners: {
//
onstart: () => {
@ -227,7 +233,9 @@ export default {
},
//
onend: () => {
console.log("End utterance");
// console.log("End utterance");
console.log("------------delete----------【" + mess + "】消息播报完成,删除该消息")
this.updateMessageStatus(obj['id']);
},
//
onresume: () => {
@ -235,25 +243,22 @@ export default {
},
},
}).then(() => {
console.log("MySpeak()播报完成...")
// console.log("" + obj['id'] + "")
})
},
async getMessageList() {
getMessageList() {
let parma = {
"status": '0',
}
let messageIds = [];
getAction(this.url.list, parma).then((res) => {
if (res.success) {
console.log("文字转语音消息列表>:" + JSON.stringify(res.result));
res.result.records.forEach(obj => {
// this.MySpeak(obj['message']);
// messageIds.push(obj['id']);
this.speech.speak({text: obj['message']}).then(() => {
// alert("MySpeak()...");
console.log("MySpeak()播报完成...")
})
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)
@ -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() {
this.closeTimer()
console.log(">>>timer初始化完成【" + new Date().toLocaleString() + "】,---执行周期: " + this.millisec + " 毫秒")
//
this.timer = setInterval(() => {
// if (this.$route.path === this.path) {
// this.loadData()
// }
this.getMessageList();
console.log("the time is running,the current time:" + new Date().toLocaleString())
console.log("---未播报消息数量:", this.messageList.length)
// console.log("the messageList:", JSON.stringify(this.messageList));
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)
},
@ -279,7 +309,25 @@ export default {
closeTimer() {
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>
<style scoped>

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

Loading…
Cancel
Save