Commit 6b3c9f37 authored by 邹绪超's avatar 邹绪超

feat: 完成系统打断

parent 51f02bbb
Pipeline #87245 waiting for manual action with stages
......@@ -69,15 +69,10 @@ const Dialog = props => {
const finish = useCallback(async ({ resultText }) => {
if (!resultText) return
pandaSpeechSynthesisUtteranceRef.current?.clear()
if(pandaRecordWebSocketRef.current) {
if (isOpenSystemSound) {
pandaRecordWebSocketRef.current.stopRecorderManager()
}
// else {
// pandaRecordWebSocketRef.current.setStatus("pause")
// }
if(currentDirectiveRef.current) {
return
}
pandaSpeechSynthesisUtteranceRef.current?.clear()
const directive = directiveRef.current.parse({
text: resultText
})
......@@ -102,14 +97,6 @@ const Dialog = props => {
await pandaSpeechSynthesisUtteranceRef.current.speakEnd()
startTime()
}
if(pandaRecordWebSocketRef.current) {
if(isOpenSystemSound) {
pandaRecordWebSocketRef.current.resumeRecorderManager()
}
// else {
// pandaRecordWebSocketRef.current.setStatus("playing")
// }
}
currentDirectiveRef.current = null
return
}
......@@ -122,38 +109,32 @@ const Dialog = props => {
pandaSpeechSynthesisUtteranceRef.current.push(defaultEmptyMsg)
await pandaSpeechSynthesisUtteranceRef.current.speakEnd()
}
if(pandaRecordWebSocketRef.current) {
if(isOpenSystemSound) {
pandaRecordWebSocketRef.current.resumeRecorderManager()
}
// else {
// pandaRecordWebSocketRef.current.setStatus("playing")
// }
}
}, [])
const frame = useCallback((data) => {
const { resultText, resultTextTemp } = data
console.log(resultTextTemp)
if (!resultTextTemp) return
const hasCloseSessionDirective = closeDirectiveRef.current.parse({
text: resultTextTemp
})
!currentDirectiveRef.current && updateUserData({ resultTextTemp })
if (hasCloseSessionDirective) {
closeSession({
resultText: resultTextTemp
})
} else {
!currentDirectiveRef.current && updateUserData({ resultTextTemp })
}
}, [])
const closeSession = ({ resultText }) => {
if (currentDirectiveRef.current) {
currentDirectiveRef.current.closeResponse()
delayStartSocket()
pandaSpeechSynthesisUtteranceRef.current?.clear()
closeSessionReocrder()
currentDirectiveRef.current = null
} else {
if (!isDebug) {
delayStartSocket()
closeSessionReocrder()
event.emit("aiSound:finish", {
resultText
})
......@@ -161,12 +142,8 @@ const Dialog = props => {
}
}
const delayStartSocket = () => {
pandaRecordWebSocketRef.current.wsClose()
pandaRecordWebSocketRef.current.setStatus("pause")
setTimeout(() => {
pandaRecordWebSocketRef.current.setStatus("playing")
}, 500)
const closeSessionReocrder = () => {
pandaRecordWebSocketRef.current?.wsClose?.()
}
const updateUserData = ({ resultTextTemp }) => {
......
......@@ -68,6 +68,9 @@ class PandaSpeechSynthesisUtterance {
clear() {
this.data = []
window.speechSynthesis.cancel()
if(this.resolve) {
this.resolve()
}
}
}
......
......@@ -3,7 +3,7 @@ import BaseDirective from './BaseDirective'
class CloseSessionDirective extends BaseDirective {
match (){
const {text} = this
if(/[熊猫熊猫|什么什么]/.test(text)) {
if(/(熊猫熊猫)|(什么什么)/.test(text)) {
return true
}
return false
......
......@@ -18,6 +18,7 @@ class SparkDirective extends BaseDirective {
sendMsg = function () {}
}) {
return new Promise(async (resolve, reject) => {
this.reject = reject
this.resolve = resolve
this.sendMsg = sendMsg
const data = await this.pandaSparkWebSocket.sendMessag({
......@@ -35,8 +36,8 @@ class SparkDirective extends BaseDirective {
if(this.pandaSparkWebSocket) {
this.pandaSparkWebSocket.stop()
}
this.resolve("")
this.sendMsg = null
this.reject("")
}
destroy(){
......
......@@ -23,7 +23,7 @@ class TestDirective extends BaseDirective {
clearInterval(this.timer)
this.timer = null
}
this.resolve && this.resolve()
this.reject && this.reject()
}
testCloseSession({sendMsg}) {
......
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