Commit 32ff219e authored by xuchaozou's avatar xuchaozou

peraf: 优化语音逻辑

parent a32c8fae
Pipeline #85758 passed with stages
......@@ -67,9 +67,23 @@ const PandaUi = props => {
},
finish (data) {
event.emit("aiSound:finish", data)
},
fail ({data}) {
message.info(data.msg)
console.log(data)
emitSwitch({
loading: false,
checked: false
})
}
}
})
// await testText("请打开泵站。")
// await testText("第2个")
// await testText("请打开泵站。")
// await testText("第3个")
// await testText("关闭泵站。");
// await testText("第二个");
// await testText("我需要打开浩源孪生平台菜单")
// await testText("我需要返回首页")
// await testText("我需要打开礼泉孪生平台菜单")
......
......@@ -2,7 +2,7 @@
position: absolute;
right: 50px;
bottom: 50px;
z-index: 100;
z-index: 9999;
.image{
width: 80px;
height: 80px;
......
......@@ -216,6 +216,7 @@ class PandaRecordWebSocket extends PandaWebSocket {
}
// 开启wpgs会有此字段(前提:在控制台开通动态修正功能)
// 取值为 "apd"时表示该片结果是追加到前面的最终结果;取值为"rpl" 时表示替换前面的部分结果,替换范围为rg字段
if (data.pgs) {
if (data.pgs === 'apd') {
// 将resultTextTemp同步给resultText
......@@ -226,6 +227,9 @@ class PandaRecordWebSocket extends PandaWebSocket {
} else {
this.resultText = this.resultText + str;
}
if(!this.resultTextTemp) {
return
}
this.events.frame({
resultTextTemp: this.resultTextTemp,
resultText: this.resultText,
......@@ -234,8 +238,10 @@ class PandaRecordWebSocket extends PandaWebSocket {
});
}
if (jsonData.code == 0 && jsonData.data.status == 2) {
const resultText = this.resultTextTemp ? this.resultTextTemp : this.resultText
if(!resultText) return
this.events.finish({
resultText: this.resultTextTemp ? this.resultTextTemp : this.resultText,
resultText,
});
this.reconnect();
}
......@@ -245,8 +251,10 @@ class PandaRecordWebSocket extends PandaWebSocket {
msg: FAIL_TYPE_DATA_ERRRO_MSG,
data: {
code: jsonData.code,
msg : jsonData.message
},
});
console.log(jsonData)
this.destroy();
}
}
......
......@@ -3,7 +3,7 @@ import BaseDirective from "./BaseDirective";
class ByeDirective extends BaseDirective {
match () {
const {text} = this
if(/再见|拜拜|关闭/.test(text)) {
if(/再见|拜拜|关闭熊猫/.test(text)) {
return true
}
return false
......
import BaseDirective from "./BaseDirective";
import {store , event} from '@wisdom-utils/utils'
import Utils from "../utils/Utils";
class CloseMenuDirective extends BaseDirective {
match () {
const { text } = this
let result = null
if(this.getBeforeLastGroupDirective()) {
result = text.match(/第([一|二|三|四|五|六|七|八|九|十]+)个/)
if(result && result.length >= 2) {
this.matchResult = Utils.chineseToNumber(result[1])
} else if(!result) {
result = text.match(/第[\u4e00-\u9fa5]?(\d+)个/)
if(result && result.length >= 2) {
this.matchResult = Number(result[1])
}
}
}
result = text.match(/关闭(.*)(?=(?:菜单|功能|路径))/)
if (!result) {
result = text.match(/关闭(.*)(?=(?:,|,|。))/)
......@@ -15,11 +29,30 @@ class CloseMenuDirective extends BaseDirective {
return !!this.matchResult
}
getBeforeLastGroupDirective() {
const lastMenu = this.directives.at(-1)
if(!lastMenu) return false
if(!(lastMenu instanceof CloseMenuDirective) ) return false
if(!lastMenu.data || lastMenu.data.type != "widgets" || lastMenu.data.widgets.length == 0) return false
return true
}
async excute () {
let widgets = null
if(this.data) {
if(typeof this.matchResult == "number") {
const widgets = this.getOpenedMenus()
if(this.matchResult == 0 || this.matchResult > widgets.length) {
this.data = {}
this.data.type = "widgets"
this.data.widgets = widgets
return `索引超出了界限,请重新语音选择关闭第几个菜单`
} else {
const menu = widgets[this.matchResult]
event.emit("event:closeMenuByName", menu.name)
return `关闭${menu.name}菜单成功`
}
}
else {
widgets = this.getIsOneWdiget()
if(!widgets) {
widgets = this.getCompleteMenus()
......
......@@ -8,11 +8,11 @@ class OpenMenuDirective extends BaseDirective {
const { text } = this
let result = null
if(this.getBeforeLastGroupDirective()) {
result = text.match(/打开.*([一|二|三|四|五|六|七|八|九|十]+)/)
result = text.match(/([一|二|三|四|五|六|七|八|九|十]+)/)
if(result && result.length >= 2) {
this.matchResult = Utils.chineseToNumber(result[1])
} else if(!result) {
result = text.match(/打开[\u4e00-\u9fa5]?(\d+)/)
result = text.match(/[\u4e00-\u9fa5]?(\d+)/)
if(result && result.length >= 2) {
this.matchResult = Number(result[1])
}
......@@ -22,7 +22,7 @@ class OpenMenuDirective extends BaseDirective {
result = text.match(/打开(.*)(?=(?:菜单|功能|路径))/)
}
if (!result) {
result = text.match(/打开(.*)(?=(?:,|,|。|))/)
result = text.match(/打开(.*)(?=(?:,|,|。))/)
}
if (result && result.length >= 2 && !this.matchResult) {
this.matchResult = result[1]
......@@ -33,7 +33,7 @@ class OpenMenuDirective extends BaseDirective {
getBeforeLastGroupDirective () {
const lastMenu = this.directives.at(-1)
if(!lastMenu) return false
if(!lastMenu instanceof OpenMenuDirective ) return false
if(!(lastMenu instanceof OpenMenuDirective) ) return false
if(!lastMenu.data || lastMenu.data.type != "widgets" || lastMenu.data.widgets.length == 0) return false
return true
}
......@@ -86,7 +86,7 @@ class OpenMenuDirective extends BaseDirective {
}
widgetsToMsg (widgets) {
return `有以下${widgets.length}个菜单\n${widgets.map((widget, index) => `${index + 1}.${widget.label}`).join("\n")},\n请语音确认一下打开第几个菜单`
return `有以下${widgets.length}个菜单\n${widgets.map((widget, index) => `${index + 1}.${widget.label}`).join("\n")}\n请语音确认一下打开第几个菜单`
}
getCompleteMenus() {
......
......@@ -11,9 +11,6 @@ const SoundAi = props => {
try {
await getIsOpenConfig()
await getKey()
event.emit("record:changeVisible", {
visible: true
})
setVisible(true)
} catch (error) {
console.warn(error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment