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

feat: 完成系统打断

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