Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
360a03af
Commit
360a03af
authored
1 year ago
by
xuchaozou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化加载页速度
parent
8548779f
Pipeline
#86011
passed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
38 deletions
+73
-38
index.jsx
src/components/SoundAi/Ui/Dialog/index.jsx
+42
-30
index.jsx
src/components/SoundAi/Ui/PandaTip/index.jsx
+24
-6
PandaRecordWebSocket.js
...ponents/SoundAi/core/core/sockets/PandaRecordWebSocket.js
+7
-2
No files found.
src/components/SoundAi/Ui/Dialog/index.jsx
View file @
360a03af
...
@@ -4,19 +4,31 @@ import { Tooltip, Typography } from 'antd'
...
@@ -4,19 +4,31 @@ import { Tooltip, Typography } from 'antd'
import
{
Fragment
,
useCallback
,
useContext
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
Fragment
,
useCallback
,
useContext
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
event
}
from
'@wisdom-utils/utils'
import
{
event
}
from
'@wisdom-utils/utils'
import
moment
from
'moment'
import
moment
from
'moment'
import
{
Directive
,
AllDirectiveTypes
}
from
'../../core'
import
{
Directive
,
AllDirectiveTypes
}
from
'../../core'
import
context
from
'../../config'
import
context
from
'../../config'
import
SparkDirective
from
'../../core/directive/SparkDirective'
import
SparkDirective
from
'../../core/directive/SparkDirective'
const
Dialog
=
props
=>
{
const
Dialog
=
props
=>
{
const
{
globalConfig
,
setGlobalConfig
}
=
useContext
(
context
)
const
{
globalConfig
,
setGlobalConfig
}
=
useContext
(
context
)
const
{
pandaRecordWebSocketRef
,
close
}
=
props
const
{
pandaRecordWebSocketRef
,
close
}
=
props
const
ulRef
=
useRef
(
null
)
const
ulRef
=
useRef
(
null
)
const
directiveRef
=
useRef
(
null
)
const
directiveRef
=
useRef
(
null
)
const
toolTipRef
=
useRef
(
null
)
const
toolTipRef
=
useRef
(
null
)
const
timeRef
=
useRef
(
null
)
const
timeRef
=
useRef
(
null
)
const
[
data
,
setData
]
=
useState
([])
const
templateData
=
[
"打开模型搭建功能菜单"
,
"打开场景搭建菜单组"
,
"回到首页"
,
"关闭当前菜单"
,
"熊猫智慧水务解决方案"
]
const
[
data
,
setData
]
=
useState
(()
=>
[{
role
:
"system"
,
content
:
`嗨,您好!猜测您可能问以下的问题\n
${
templateData
.
map
((
i
,
index
)
=>
`
${
index
+
1
}
.
${
i
}
。`
).
join
(
"
\
n"
)}
`
,
time
:
new
moment
().
format
(
"HH:mm:ss"
),
}])
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
ulRef
.
current
.
lastChild
)
return
if
(
!
ulRef
.
current
.
lastChild
)
return
...
@@ -30,10 +42,10 @@ const Dialog = props => {
...
@@ -30,10 +42,10 @@ const Dialog = props => {
useEffect
(()
=>
{
useEffect
(()
=>
{
directiveRef
.
current
=
new
Directive
({
directiveRef
.
current
=
new
Directive
({
params
:
{
params
:
{
sparkModelConfig
:
globalConfig
.
getIn
([
'key'
]).
shortSound
sparkModelConfig
:
globalConfig
.
getIn
([
'key'
]).
shortSound
}
}
})
})
if
(
globalConfig
.
get
(
'key'
).
isOpenSparkModel
)
{
if
(
globalConfig
.
get
(
'key'
).
isOpenSparkModel
)
{
directiveRef
.
current
.
directiveTypes
.
push
(
SparkDirective
)
directiveRef
.
current
.
directiveTypes
.
push
(
SparkDirective
)
}
}
event
.
on
(
"aiSound:finish"
,
finish
)
event
.
on
(
"aiSound:finish"
,
finish
)
...
@@ -47,7 +59,7 @@ const Dialog = props => {
...
@@ -47,7 +59,7 @@ const Dialog = props => {
},
[])
},
[])
const
finish
=
useCallback
(
async
({
resultText
})
=>
{
const
finish
=
useCallback
(
async
({
resultText
})
=>
{
if
(
!
resultText
)
return
if
(
!
resultText
)
return
pandaRecordWebSocketRef
.
current
.
setStatus
(
"pause"
)
pandaRecordWebSocketRef
.
current
.
setStatus
(
"pause"
)
const
directive
=
directiveRef
.
current
.
parse
({
const
directive
=
directiveRef
.
current
.
parse
({
text
:
resultText
text
:
resultText
...
@@ -57,12 +69,12 @@ const Dialog = props => {
...
@@ -57,12 +69,12 @@ const Dialog = props => {
role
:
"system"
,
role
:
"system"
,
content
:
"系统正在思考中,请稍后..."
content
:
"系统正在思考中,请稍后..."
})
})
let
resultMsg
=
""
let
resultMsg
=
""
await
directive
.
excute
({
await
directive
.
excute
({
sendMsg
:
msg
=>
{
sendMsg
:
msg
=>
{
resultMsg
+=
msg
resultMsg
+=
msg
updateLastData
({
updateLastData
({
content
:
resultMsg
content
:
resultMsg
})
})
}
}
})
})
...
@@ -78,7 +90,7 @@ const Dialog = props => {
...
@@ -78,7 +90,7 @@ const Dialog = props => {
const
frame
=
useCallback
((
data
)
=>
{
const
frame
=
useCallback
((
data
)
=>
{
const
{
resultText
,
resultTextTemp
}
=
data
const
{
resultText
,
resultTextTemp
}
=
data
if
(
!
resultTextTemp
)
return
if
(
!
resultTextTemp
)
return
setData
(
data
=>
{
setData
(
data
=>
{
const
length
=
data
.
length
const
length
=
data
.
length
const
lastData
=
data
.
at
(
-
1
)
const
lastData
=
data
.
at
(
-
1
)
...
@@ -105,15 +117,6 @@ const Dialog = props => {
...
@@ -105,15 +117,6 @@ const Dialog = props => {
})
})
},
[])
},
[])
const
sendContent
=
({
role
=
"system"
,
content
,
...
params
})
=>
{
setData
(
i
=>
i
.
concat
([{
role
,
time
:
new
moment
().
format
(
"HH:mm:ss"
),
content
,
...
params
}]))
}
const
updateLastData
=
({
content
,
...
params
})
=>
{
const
updateLastData
=
({
content
,
...
params
})
=>
{
setData
(
data
=>
data
.
map
((
item
,
index
)
=>
{
setData
(
data
=>
data
.
map
((
item
,
index
)
=>
{
if
(
index
<
data
.
length
-
1
)
{
if
(
index
<
data
.
length
-
1
)
{
...
@@ -130,6 +133,15 @@ const Dialog = props => {
...
@@ -130,6 +133,15 @@ const Dialog = props => {
}))
}))
}
}
const
sendContent
=
({
role
=
"system"
,
content
,
...
params
})
=>
{
setData
(
i
=>
i
.
concat
([{
role
,
time
:
new
moment
().
format
(
"HH:mm:ss"
),
content
,
...
params
}]))
}
const
startTime
=
()
=>
{
const
startTime
=
()
=>
{
destroyTime
()
destroyTime
()
timeRef
.
current
=
setTimeout
(()
=>
{
timeRef
.
current
=
setTimeout
(()
=>
{
...
@@ -138,7 +150,7 @@ const Dialog = props => {
...
@@ -138,7 +150,7 @@ const Dialog = props => {
}
}
const
destroyTime
=
()
=>
{
const
destroyTime
=
()
=>
{
if
(
timeRef
.
current
)
{
if
(
timeRef
.
current
)
{
clearTimeout
(
timeRef
.
current
)
clearTimeout
(
timeRef
.
current
)
timeRef
.
current
=
null
timeRef
.
current
=
null
}
}
...
@@ -152,22 +164,22 @@ const Dialog = props => {
...
@@ -152,22 +164,22 @@ const Dialog = props => {
<
div
className=
{
style
.
help
}
>
<
div
className=
{
style
.
help
}
>
<
Tooltip
<
Tooltip
placement=
"bottomRight"
placement=
"bottomRight"
title
=
{
title
=
{
<
div
className=
{
style
.
toolTipContent
}
>
<
div
className=
{
style
.
toolTipContent
}
>
<
p
className=
{
style
.
toolTipTitle
}
>
支持以下语音指令集
</
p
>
<
p
className=
{
style
.
toolTipTitle
}
>
支持以下语音指令集
</
p
>
<
div
className=
{
style
.
toolTipWrapper
}
>
<
div
className=
{
style
.
toolTipWrapper
}
>
<
ul
>
<
ul
>
{
{
AllDirectiveTypes
.
filter
(
item
=>
!!
item
.
name
).
map
((
item
,
index
)
=>
<
li
key=
{
index
}
>
{
index
+
1
}
.
{
item
.
name
}
</
li
>)
AllDirectiveTypes
.
filter
(
item
=>
!!
item
.
name
).
map
((
item
,
index
)
=>
<
li
key=
{
index
}
>
{
index
+
1
}
.
{
item
.
name
}
</
li
>)
}
}
</
ul
>
</
ul
>
</
div
>
</
div
>
</
div
>
</
div
>
}
}
getPopupContainer
=
{
()
=>
toolTipRef
.
current
}
getPopupContainer
=
{
()
=>
toolTipRef
.
current
}
arrowPointAtCenter
=
{
true
}
arrowPointAtCenter
=
{
true
}
>
>
<
span
className=
{
style
.
helpIcon
}
ref
=
{
toolTipRef
}
></
span
>
<
span
className=
{
style
.
helpIcon
}
ref
=
{
toolTipRef
}
></
span
>
</
Tooltip
>
</
Tooltip
>
</
div
>
</
div
>
</
div
>
</
div
>
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/Ui/PandaTip/index.jsx
View file @
360a03af
...
@@ -14,16 +14,32 @@ const PandaTip = props => {
...
@@ -14,16 +14,32 @@ const PandaTip = props => {
const
[
initOpen
,
setInitOpen
]
=
useState
(
false
)
const
[
initOpen
,
setInitOpen
]
=
useState
(
false
)
const
[
showTip
,
setShowTip
]
=
useState
(
true
)
const
[
showTip
,
setShowTip
]
=
useState
(
true
)
const
timeRef
=
useRef
(
null
)
const
timeRef
=
useRef
(
null
)
const
finish
=
useCallback
(({
resultText
})
=>
{
// const finish = useCallback(({ resultText }) => {
// console.log("说完")
// const directive = directiveRef.current.parse({
// text: resultText
// })
// if (!directive) return null
// if (directive instanceof AwakenDirective && status == "close") {
// setStatus("open")
// } else if (directive instanceof ByeDirective && status == "open") {
// // setStatus("close")
// close()
// }
// }, [status])
const
frame
=
useCallback
(({
resultTextTemp
})
=>
{
const
directive
=
directiveRef
.
current
.
parse
({
const
directive
=
directiveRef
.
current
.
parse
({
text
:
resultText
text
:
resultText
Temp
})
})
if
(
!
directive
)
return
null
console
.
log
(
resultTextTemp
)
if
(
!
directive
)
return
null
if
(
directive
instanceof
AwakenDirective
&&
status
==
"close"
)
{
if
(
directive
instanceof
AwakenDirective
&&
status
==
"close"
)
{
setStatus
(
"open"
)
setStatus
(
"open"
)
pandaRecordWebSocketRef
.
current
.
wsClose
()
}
else
if
(
directive
instanceof
ByeDirective
&&
status
==
"open"
)
{
}
else
if
(
directive
instanceof
ByeDirective
&&
status
==
"open"
)
{
// setStatus("close")
close
()
close
()
pandaRecordWebSocketRef
.
current
.
wsClose
()
}
}
},
[
status
])
},
[
status
])
...
@@ -34,7 +50,8 @@ const PandaTip = props => {
...
@@ -34,7 +50,8 @@ const PandaTip = props => {
},
[])
},
[])
useEffect
(()
=>
{
useEffect
(()
=>
{
event
.
on
(
"aiSound:finish"
,
finish
)
// event.on("aiSound:finish", finish)
event
.
on
(
"aiSound:frame"
,
frame
)
if
(
status
==
"open"
)
{
if
(
status
==
"open"
)
{
destroyTime
()
destroyTime
()
}
else
if
(
status
==
"close"
)
{
}
else
if
(
status
==
"close"
)
{
...
@@ -46,7 +63,8 @@ const PandaTip = props => {
...
@@ -46,7 +63,8 @@ const PandaTip = props => {
}
}
}
}
return
()
=>
{
return
()
=>
{
event
.
off
(
"aiSound:finish"
,
finish
)
// event.off("aiSound:finish", finish)
event
.
off
(
"aiSound:frame"
,
frame
)
}
}
},
[
status
,
initOpen
])
},
[
status
,
initOpen
])
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/core/sockets/PandaRecordWebSocket.js
View file @
360a03af
...
@@ -142,8 +142,13 @@ class PandaRecordWebSocket extends PandaWebSocket {
...
@@ -142,8 +142,13 @@ class PandaRecordWebSocket extends PandaWebSocket {
this
.
resultTextTemp
=
""
this
.
resultTextTemp
=
""
this
.
createWs
()
this
.
createWs
()
}
}
if
(
this
.
ws
&&
[
this
.
ws
.
CONNECTING
,
this
.
ws
.
OPEN
].
includes
(
this
.
ws
.
readyState
))
{
if
(
this
.
ws
)
{
this
.
frameBuffers
.
push
(
frameBuffer
)
if
([
this
.
ws
.
CONNECTING
,
this
.
ws
.
OPEN
].
includes
(
this
.
ws
.
readyState
))
{
this
.
frameBuffers
.
push
(
frameBuffer
)
}
else
if
(
this
.
ws
.
CLOSED
==
this
.
ws
.
readyState
){
this
.
frameBuffers
.
push
(
frameBuffer
)
this
.
ws
=
null
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment