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
4effee3c
Commit
4effee3c
authored
Mar 12, 2024
by
xuchaozou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复语音识别失败
parent
274212ae
Pipeline
#85919
passed with stages
Changes
14
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
149 additions
and
60 deletions
+149
-60
PandaUi.js
src/components/SoundAi/PandaUi.js
+4
-3
index.jsx
src/components/SoundAi/Ui/Dialog/index.jsx
+17
-7
index.jsx
src/components/SoundAi/Ui/PandaTip/index.jsx
+4
-4
config.js
src/components/SoundAi/config.js
+11
-6
PandaRecordWebSocket.js
...ponents/SoundAi/core/core/sockets/PandaRecordWebSocket.js
+7
-5
PandaSparkWebSocket.js
...mponents/SoundAi/core/core/sockets/PandaSparkWebSocket.js
+7
-1
PandaWebSocket.js
src/components/SoundAi/core/core/sockets/PandaWebSocket.js
+9
-9
AwakenDirective.js
src/components/SoundAi/core/directive/AwakenDirective.js
+1
-1
BaseDirective.js
src/components/SoundAi/core/directive/BaseDirective.js
+3
-1
CloseMenuDirective.js
src/components/SoundAi/core/directive/CloseMenuDirective.js
+10
-8
HomePageDirective.js
src/components/SoundAi/core/directive/HomePageDirective.js
+5
-3
OpenMenuDirective.js
src/components/SoundAi/core/directive/OpenMenuDirective.js
+9
-7
SparkDirective.js
src/components/SoundAi/core/directive/SparkDirective.js
+41
-0
index.js
src/components/SoundAi/index.js
+21
-5
No files found.
src/components/SoundAi/PandaUi.js
View file @
4effee3c
import
{
request
,
event
}
from
'@wisdom-utils/utils'
;
import
{
request
,
event
}
from
'@wisdom-utils/utils'
;
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
;
import
{
useCallback
,
use
Context
,
use
Effect
,
useRef
,
useState
}
from
'react'
;
import
{
message
}
from
'antd'
;
import
{
message
}
from
'antd'
;
import
{
init
,
cut
,
extract
,
ready
}
from
'@congcongcai/jieba.js'
;
import
{
init
,
cut
,
extract
,
ready
}
from
'@congcongcai/jieba.js'
;
import
{
PandaRecordWebSocket
}
from
'./core'
;
import
{
PandaRecordWebSocket
}
from
'./core'
;
import
PandaTip
from
'./Ui/PandaTip'
;
import
PandaTip
from
'./Ui/PandaTip'
;
import
context
from
'./config'
const
PandaUi
=
props
=>
{
const
PandaUi
=
props
=>
{
const
pandaRecordWebSocketRef
=
useRef
(
null
);
const
pandaRecordWebSocketRef
=
useRef
(
null
);
const
[
isStartRecorder
,
setIsStartRecorder
]
=
useState
(
false
);
const
[
isStartRecorder
,
setIsStartRecorder
]
=
useState
(
false
);
const
{
keyRef
}
=
props
;
const
{
globalConfig
,
setGlobalConfig
}
=
useContext
(
context
)
useEffect
(
async
()
=>
{
useEffect
(
async
()
=>
{
try
{
try
{
...
@@ -61,7 +62,7 @@ const PandaUi = props => {
...
@@ -61,7 +62,7 @@ const PandaUi = props => {
const
createPandaRecordWebSocket
=
async
()
=>
{
const
createPandaRecordWebSocket
=
async
()
=>
{
destroyPandaRecorderWebSocket
();
destroyPandaRecorderWebSocket
();
pandaRecordWebSocketRef
.
current
=
new
PandaRecordWebSocket
({
pandaRecordWebSocketRef
.
current
=
new
PandaRecordWebSocket
({
config
:
keyRef
.
current
.
shortSound
,
config
:
globalConfig
.
get
(
'key'
)
.
shortSound
,
events
:
{
events
:
{
frame
(
data
)
{
frame
(
data
)
{
event
.
emit
(
'aiSound:frame'
,
data
);
event
.
emit
(
'aiSound:frame'
,
data
);
...
...
src/components/SoundAi/Ui/Dialog/index.jsx
View file @
4effee3c
import
style
from
'./style.less'
import
style
from
'./style.less'
import
{
withRouter
}
from
'@wisdom-utils/runtime'
import
{
withRouter
}
from
'@wisdom-utils/runtime'
import
{
Tooltip
,
Typography
}
from
'antd'
import
{
Tooltip
,
Typography
}
from
'antd'
import
{
Fragment
,
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
Fragment
,
useCallback
,
use
Context
,
use
Effect
,
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
config
from
'../../config'
import
context
from
'../../config'
import
SparkDirective
from
'../../core/directive/SparkDirective'
const
Dialog
=
props
=>
{
const
Dialog
=
props
=>
{
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
)
...
@@ -29,8 +30,12 @@ const Dialog = props => {
...
@@ -29,8 +30,12 @@ const Dialog = props => {
useEffect
(()
=>
{
useEffect
(()
=>
{
directiveRef
.
current
=
new
Directive
({
directiveRef
.
current
=
new
Directive
({
params
:
{
params
:
{
sparkModelConfig
:
globalConfig
.
getIn
([
'key'
]).
shortSound
}
}
})
})
if
(
globalConfig
.
get
(
'key'
).
isOpenSparkModel
)
{
directiveRef
.
current
.
directiveTypes
.
push
(
SparkDirective
)
}
event
.
on
(
"aiSound:finish"
,
finish
)
event
.
on
(
"aiSound:finish"
,
finish
)
event
.
on
(
"aiSound:frame"
,
frame
)
event
.
on
(
"aiSound:frame"
,
frame
)
startTime
()
startTime
()
...
@@ -52,9 +57,14 @@ const Dialog = props => {
...
@@ -52,9 +57,14 @@ const Dialog = props => {
role
:
"system"
,
role
:
"system"
,
content
:
"系统正在思考中,请稍后..."
content
:
"系统正在思考中,请稍后..."
})
})
const
msg
=
await
directive
.
excute
()
let
resultMsg
=
""
updateLastData
({
await
directive
.
excute
({
content
:
msg
sendMsg
:
msg
=>
{
resultMsg
+=
msg
updateLastData
({
content
:
resultMsg
})
}
})
})
pandaRecordWebSocketRef
.
current
.
setStatus
(
"playing"
)
pandaRecordWebSocketRef
.
current
.
setStatus
(
"playing"
)
return
return
...
@@ -124,7 +134,7 @@ const Dialog = props => {
...
@@ -124,7 +134,7 @@ const Dialog = props => {
destroyTime
()
destroyTime
()
timeRef
.
current
=
setTimeout
(()
=>
{
timeRef
.
current
=
setTimeout
(()
=>
{
close
&&
close
()
close
&&
close
()
},
config
.
closePandaAiTime
)
},
globalConfig
.
getIn
([
'closePandaAiTime'
])
)
}
}
const
destroyTime
=
()
=>
{
const
destroyTime
=
()
=>
{
...
...
src/components/SoundAi/Ui/PandaTip/index.jsx
View file @
4effee3c
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
useCallback
,
use
Context
,
use
Effect
,
useRef
,
useState
}
from
'react'
import
style
from
'./style.less'
import
style
from
'./style.less'
import
image
from
'@/assets/images/soundAi/眨眼.gif'
import
image
from
'@/assets/images/soundAi/眨眼.gif'
import
{
event
}
from
'@wisdom-utils/utils'
import
{
event
}
from
'@wisdom-utils/utils'
import
{
AwakenDirective
,
ByeDirective
,
Directive
}
from
'../../core'
import
{
AwakenDirective
,
ByeDirective
,
Directive
}
from
'../../core'
import
Dialog
from
'../Dialog'
import
Dialog
from
'../Dialog'
import
con
fig
from
'../../config'
import
con
text
from
'../../config'
const
PandaTip
=
props
=>
{
const
PandaTip
=
props
=>
{
const
{
pandaRecordWebSocketRef
}
=
props
const
{
pandaRecordWebSocketRef
}
=
props
const
{
globalConfig
,
setGlobalConfig
}
=
useContext
(
context
)
const
[
status
,
setStatus
]
=
useState
(
"close"
)
const
[
status
,
setStatus
]
=
useState
(
"close"
)
const
directiveRef
=
useRef
(
null
)
const
directiveRef
=
useRef
(
null
)
const
[
initOpen
,
setInitOpen
]
=
useState
(
false
)
const
[
initOpen
,
setInitOpen
]
=
useState
(
false
)
...
@@ -54,7 +54,7 @@ const PandaTip = props => {
...
@@ -54,7 +54,7 @@ const PandaTip = props => {
destroyTime
()
destroyTime
()
timeRef
.
current
=
setTimeout
(()
=>
{
timeRef
.
current
=
setTimeout
(()
=>
{
setShowTip
(
true
)
setShowTip
(
true
)
},
config
.
showOpenAiTipTime
)
},
globalConfig
.
getIn
([
'showOpenAiTipTime'
])
)
}
}
const
destroyTime
=
()
=>
{
const
destroyTime
=
()
=>
{
...
...
src/components/SoundAi/config.js
View file @
4effee3c
const
config
=
{
import
{
fromJS
}
from
"immutable"
closePandaAiTime
:
1000
*
60
,
import
{
createContext
}
from
"react"
showOpenAiTipTime
:
1000
*
60
}
export
default
createContext
(
null
)
export
default
config
export
const
contextData
=
data
=>
fromJS
({
\ No newline at end of file
closePandaAiTime
:
1000
*
60
,
showOpenAiTipTime
:
1000
*
60
,
key
:
null
,
...
data
??
{}
})
\ No newline at end of file
src/components/SoundAi/core/core/sockets/PandaRecordWebSocket.js
View file @
4effee3c
...
@@ -29,7 +29,11 @@ class PandaRecordWebSocket extends PandaWebSocket {
...
@@ -29,7 +29,11 @@ class PandaRecordWebSocket extends PandaWebSocket {
}
}
async
start
()
{
async
start
()
{
const
data
=
await
super
.
start
();
let
data
=
super
.
start
();
if
(
!
data
.
isSuccess
)
{
return
data
;
}
data
=
await
this
.
checkRecorder
()
if
(
!
data
.
isSuccess
)
{
if
(
!
data
.
isSuccess
)
{
return
data
;
return
data
;
}
}
...
@@ -41,10 +45,8 @@ class PandaRecordWebSocket extends PandaWebSocket {
...
@@ -41,10 +45,8 @@ class PandaRecordWebSocket extends PandaWebSocket {
}
}
async
checkParams
()
{
async
checkRecorder
()
{
let
data
=
super
.
checkParams
();
const
data
=
await
Utils
.
isCanableRecorder
(
this
.
config
.
checkDelayDeciveTime
);
if
(
!
data
.
isSuccess
)
return
data
;
data
=
await
Utils
.
isCanableRecorder
(
this
.
config
.
checkDelayDeciveTime
);
if
(
!
data
.
isSuccess
)
return
data
;
if
(
!
data
.
isSuccess
)
return
data
;
return
data
;
return
data
;
}
}
...
...
src/components/SoundAi/core/core/sockets/PandaSparkWebSocket.js
View file @
4effee3c
...
@@ -22,6 +22,7 @@ class PandaSparkWebSocket extends PandaWebSocket {
...
@@ -22,6 +22,7 @@ class PandaSparkWebSocket extends PandaWebSocket {
this
.
recordData
=
null
;
this
.
recordData
=
null
;
this
.
resolve
=
null
;
this
.
resolve
=
null
;
this
.
reject
=
null
;
this
.
reject
=
null
;
this
.
frame
=
null
}
}
initConfig
()
{
initConfig
()
{
...
@@ -115,7 +116,7 @@ class PandaSparkWebSocket extends PandaWebSocket {
...
@@ -115,7 +116,7 @@ class PandaSparkWebSocket extends PandaWebSocket {
}
}
}
}
sendMessag
({
content
,
role
,
isLinkContext
=
true
})
{
sendMessag
({
content
,
role
,
isLinkContext
=
true
,
frame
=
function
()
{}
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
resolve
)
{
if
(
this
.
resolve
)
{
return
reject
({
return
reject
({
...
@@ -127,6 +128,7 @@ class PandaSparkWebSocket extends PandaWebSocket {
...
@@ -127,6 +128,7 @@ class PandaSparkWebSocket extends PandaWebSocket {
this
.
resultTextTemp
=
''
;
this
.
resultTextTemp
=
''
;
this
.
resolve
=
resolve
;
this
.
resolve
=
resolve
;
this
.
reject
=
reject
;
this
.
reject
=
reject
;
this
.
frame
=
frame
this
.
recordData
=
{
this
.
recordData
=
{
content
,
content
,
role
,
role
,
...
@@ -172,6 +174,10 @@ class PandaSparkWebSocket extends PandaWebSocket {
...
@@ -172,6 +174,10 @@ class PandaSparkWebSocket extends PandaWebSocket {
resultTextTemp
:
content
,
resultTextTemp
:
content
,
resultText
:
this
.
resultText
,
resultText
:
this
.
resultText
,
});
});
this
.
frame
&&
this
.
frame
({
resultTextTemp
:
content
,
resultText
:
this
.
resultText
,
})
}
else
if
(
status
==
2
)
{
}
else
if
(
status
==
2
)
{
this
.
data
.
push
({
this
.
data
.
push
({
role
:
'assistant'
,
role
:
'assistant'
,
...
...
src/components/SoundAi/core/core/sockets/PandaWebSocket.js
View file @
4effee3c
...
@@ -18,20 +18,20 @@ class PandaWebSocket {
...
@@ -18,20 +18,20 @@ class PandaWebSocket {
this
.
events
=
Object
.
assign
(
this
.
events
=
Object
.
assign
(
{},
{},
{
{
wsOpen
:
function
()
{},
wsOpen
:
function
()
{
},
wsOnmessage
:
function
()
{},
wsOnmessage
:
function
()
{
},
wsOnerror
:
function
()
{},
wsOnerror
:
function
()
{
},
wsOnclose
:
function
()
{},
wsOnclose
:
function
()
{
},
fail
:
function
()
{},
fail
:
function
()
{
},
frame
:
function
()
{},
frame
:
function
()
{
},
finish
:
function
()
{},
finish
:
function
()
{
},
},
},
options
.
events
||
{},
options
.
events
||
{},
);
);
}
}
async
start
()
{
start
()
{
const
data
=
await
this
.
checkParams
();
const
data
=
this
.
checkParams
();
if
(
!
data
.
isSuccess
)
{
if
(
!
data
.
isSuccess
)
{
return
data
;
return
data
;
}
}
...
...
src/components/SoundAi/core/directive/AwakenDirective.js
View file @
4effee3c
...
@@ -10,7 +10,7 @@ class AwakenDirective extends BaseDirective{
...
@@ -10,7 +10,7 @@ class AwakenDirective extends BaseDirective{
return
false
return
false
}
}
async
excute
()
{
async
excute
(
{
sendMsg
=
function
()
{}}
)
{
}
}
}
}
...
...
src/components/SoundAi/core/directive/BaseDirective.js
View file @
4effee3c
...
@@ -10,7 +10,9 @@ class BaseDirective {
...
@@ -10,7 +10,9 @@ class BaseDirective {
match
()
{
match
()
{
}
}
async
excute
()
{
async
excute
({
sendMsg
=
function
()
{}
})
{
}
}
}
}
...
...
src/components/SoundAi/core/directive/CloseMenuDirective.js
View file @
4effee3c
...
@@ -44,7 +44,9 @@ class CloseMenuDirective extends BaseDirective {
...
@@ -44,7 +44,9 @@ class CloseMenuDirective extends BaseDirective {
return
true
;
return
true
;
}
}
async
excute
()
{
async
excute
({
sendMsg
=
function
()
{}
})
{
let
widgets
=
null
;
let
widgets
=
null
;
if
(
typeof
this
.
matchResult
===
'number'
)
{
if
(
typeof
this
.
matchResult
===
'number'
)
{
const
widgets
=
this
.
getOpenedMenus
();
const
widgets
=
this
.
getOpenedMenus
();
...
@@ -52,33 +54,33 @@ class CloseMenuDirective extends BaseDirective {
...
@@ -52,33 +54,33 @@ class CloseMenuDirective extends BaseDirective {
this
.
data
=
{};
this
.
data
=
{};
this
.
data
.
type
=
'widgets'
;
this
.
data
.
type
=
'widgets'
;
this
.
data
.
widgets
=
widgets
;
this
.
data
.
widgets
=
widgets
;
return
`索引超出了界限,请重新语音选择关闭第几个菜单`
;
return
sendMsg
(
`索引超出了界限,请重新语音选择关闭第几个菜单`
)
;
}
}
const
menu
=
widgets
[
this
.
matchResult
];
const
menu
=
widgets
[
this
.
matchResult
];
event
.
emit
(
'event:closeMenuByName'
,
menu
.
name
);
event
.
emit
(
'event:closeMenuByName'
,
menu
.
name
);
return
`关闭
${
menu
.
name
}
菜单成功`
;
return
sendMsg
(
`关闭
${
menu
.
name
}
菜单成功`
)
;
}
}
if
(
this
.
matchResult
==
'所有'
)
{
if
(
this
.
matchResult
==
'所有'
)
{
return
this
.
closeAllMenu
(
);
return
sendMsg
(
this
.
closeAllMenu
()
);
}
}
if
(
this
.
matchResult
==
'当前'
)
{
if
(
this
.
matchResult
==
'当前'
)
{
return
this
.
closeCurrentMenu
(
);
return
sendMsg
(
this
.
closeCurrentMenu
()
);
}
}
widgets
=
this
.
getIsOneWdiget
();
widgets
=
this
.
getIsOneWdiget
();
if
(
!
widgets
)
{
if
(
!
widgets
)
{
widgets
=
this
.
getCompleteMenus
();
widgets
=
this
.
getCompleteMenus
();
}
}
if
(
!
widgets
)
{
if
(
!
widgets
)
{
return
'已打开菜单中没有查找到此菜单,请检查语音是否正确'
;
return
sendMsg
(
'已打开菜单中没有查找到此菜单,请检查语音是否正确'
)
;
}
}
if
(
widgets
.
length
==
1
)
{
if
(
widgets
.
length
==
1
)
{
event
.
emit
(
'event:closeMenuByName'
,
widgets
[
0
].
name
);
event
.
emit
(
'event:closeMenuByName'
,
widgets
[
0
].
name
);
return
`关闭
${
widgets
[
0
].
name
}
菜单成功`
;
return
sendMsg
(
`关闭
${
widgets
[
0
].
name
}
菜单成功`
)
;
}
}
this
.
data
=
{};
this
.
data
=
{};
this
.
data
.
type
=
'widgets'
;
this
.
data
.
type
=
'widgets'
;
this
.
data
.
widgets
=
widgets
;
this
.
data
.
widgets
=
widgets
;
return
this
.
widgetsToMsg
(
widgets
);
return
sendMsg
(
this
.
widgetsToMsg
(
widgets
)
);
}
}
widgetsToMsg
(
widgets
)
{
widgetsToMsg
(
widgets
)
{
...
...
src/components/SoundAi/core/directive/HomePageDirective.js
View file @
4effee3c
...
@@ -10,12 +10,14 @@ class HomePageDirective extends BaseDirective {
...
@@ -10,12 +10,14 @@ class HomePageDirective extends BaseDirective {
}
}
return
false
return
false
}
}
async
excute
()
{
async
excute
({
sendMsg
=
function
()
{}
})
{
if
(
!
window
.
globalConfig
.
homepage
)
{
if
(
!
window
.
globalConfig
.
homepage
)
{
return
"没有配置首页"
return
sendMsg
(
"没有配置首页"
)
}
}
Utils
.
openMenu
({
url
:
window
.
globalConfig
.
homepage
})
Utils
.
openMenu
({
url
:
window
.
globalConfig
.
homepage
})
return
"返回首页成功"
return
sendMsg
(
"返回首页成功"
)
}
}
}
}
...
...
src/components/SoundAi/core/directive/OpenMenuDirective.js
View file @
4effee3c
...
@@ -39,7 +39,9 @@ class OpenMenuDirective extends BaseDirective {
...
@@ -39,7 +39,9 @@ class OpenMenuDirective extends BaseDirective {
return
true
return
true
}
}
async
excute
()
{
async
excute
({
sendMsg
=
function
()
{}
})
{
let
widgets
=
null
let
widgets
=
null
if
(
typeof
this
.
matchResult
==
"number"
)
{
if
(
typeof
this
.
matchResult
==
"number"
)
{
const
lastMenu
=
this
.
directives
.
at
(
-
2
)
const
lastMenu
=
this
.
directives
.
at
(
-
2
)
...
@@ -48,11 +50,11 @@ class OpenMenuDirective extends BaseDirective {
...
@@ -48,11 +50,11 @@ class OpenMenuDirective extends BaseDirective {
this
.
data
=
{}
this
.
data
=
{}
this
.
data
.
type
=
"widgets"
this
.
data
.
type
=
"widgets"
this
.
data
.
widgets
=
widgets
this
.
data
.
widgets
=
widgets
return
`索引超出了界限,请重新语音选择第几个菜单`
return
sendMsg
(
`索引超出了界限,请重新语音选择第几个菜单`
)
}
else
{
}
else
{
const
currentMenu
=
widgets
[
this
.
matchResult
-
1
]
const
currentMenu
=
widgets
[
this
.
matchResult
-
1
]
this
.
openSingleMenu
(
currentMenu
)
this
.
openSingleMenu
(
currentMenu
)
return
`成功打开
${
currentMenu
.
label
}
菜单`
return
sendMsg
(
`成功打开
${
currentMenu
.
label
}
菜单`
)
}
}
}
}
else
{
else
{
...
@@ -61,15 +63,15 @@ class OpenMenuDirective extends BaseDirective {
...
@@ -61,15 +63,15 @@ class OpenMenuDirective extends BaseDirective {
widgets
=
this
.
getPatternMenus
()
widgets
=
this
.
getPatternMenus
()
}
}
if
(
!
widgets
)
{
if
(
!
widgets
)
{
return
"没有查找到此菜单,请检查语音是否正确"
return
sendMsg
(
"没有查找到此菜单,请检查语音是否正确"
)
}
}
if
(
widgets
.
length
==
1
)
{
if
(
widgets
.
length
==
1
)
{
return
this
.
handleOneSingleMenu
(
widgets
[
0
]
)
return
sendMsg
(
this
.
handleOneSingleMenu
(
widgets
[
0
])
)
}
else
{
}
else
{
this
.
data
=
{}
this
.
data
=
{}
this
.
data
.
type
=
"widgets"
this
.
data
.
type
=
"widgets"
this
.
data
.
widgets
=
widgets
this
.
data
.
widgets
=
widgets
return
`
${
this
.
widgetsToMsg
(
widgets
)}
`
sendMsg
(
`
${
this
.
widgetsToMsg
(
widgets
)}
`
)
}
}
}
}
}
}
...
@@ -81,7 +83,7 @@ class OpenMenuDirective extends BaseDirective {
...
@@ -81,7 +83,7 @@ class OpenMenuDirective extends BaseDirective {
}
else
{
}
else
{
this
.
data
=
{}
this
.
data
=
{}
this
.
data
.
type
=
"widgets"
this
.
data
.
type
=
"widgets"
this
.
data
.
widgets
=
widgets
this
.
data
.
widgets
=
widget
.
widget
s
return
`你打开的
${
widget
.
label
}
是一个菜单组,
${
this
.
widgetsToMsg
(
widget
.
widgets
)}
`
return
`你打开的
${
widget
.
label
}
是一个菜单组,
${
this
.
widgetsToMsg
(
widget
.
widgets
)}
`
}
}
}
}
...
...
src/components/SoundAi/core/directive/SparkDirective.js
0 → 100644
View file @
4effee3c
import
BaseDirective
from
"./BaseDirective"
import
PandaSparkWebSocket
from
'../core/sockets/PandaSparkWebSocket'
class
SparkDirective
extends
BaseDirective
{
constructor
(
options
)
{
super
(
options
)
this
.
pandaSparkWebSocket
=
new
PandaSparkWebSocket
({
config
:
this
.
params
.
sparkModelConfig
})
this
.
pandaSparkWebSocket
.
start
()
}
match
()
{
const
{
text
}
=
this
;
return
true
}
async
excute
({
sendMsg
=
function
()
{}
})
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
const
data
=
await
this
.
pandaSparkWebSocket
.
sendMessag
({
content
:
this
.
text
,
isLinkContext
:
false
,
frame
({
resultTextTemp
,
resultText
})
{
sendMsg
(
resultTextTemp
)
}
})
resolve
(
data
.
resultText
)
})
}
destroy
(){
if
(
this
.
pandaSparkWebSocket
)
{
this
.
pandaSparkWebSocket
.
destroy
()
this
.
pandaSparkWebSocket
=
null
}
}
}
export
default
SparkDirective
\ No newline at end of file
src/components/SoundAi/index.js
View file @
4effee3c
import
{
request
,
event
}
from
'@wisdom-utils/utils'
import
{
request
,
event
}
from
'@wisdom-utils/utils'
import
{
Suspense
,
lazy
,
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
Suspense
,
lazy
,
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
Context
,
{
contextData
}
from
'./config'
const
PandaUi
=
lazy
(()
=>
import
(
"./PandaUi"
))
const
PandaUi
=
lazy
(()
=>
import
(
"./PandaUi"
))
const
SoundAi
=
props
=>
{
const
SoundAi
=
props
=>
{
const
keyRef
=
useRef
(
null
)
const
keyRef
=
useRef
(
null
)
const
[
visible
,
setVisible
]
=
useState
(
false
)
const
[
visible
,
setVisible
]
=
useState
(
false
)
const
[
globalConfig
,
setGlobalConfig
]
=
useState
(
contextData
())
useEffect
(
async
()
=>
{
useEffect
(
async
()
=>
{
try
{
try
{
await
getIsOpenConfig
()
await
getKey
()
await
getKey
()
await
getIsOpenConfig
()
setVisible
(
true
)
setVisible
(
true
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
warn
(
error
)
console
.
warn
(
error
)
...
@@ -25,7 +27,7 @@ const SoundAi = props => {
...
@@ -25,7 +27,7 @@ const SoundAi = props => {
request
(
"/PandaOMS/OMS/DataManger/GetDicConfigs"
,
{
request
(
"/PandaOMS/OMS/DataManger/GetDicConfigs"
,
{
params
:
{
params
:
{
ParentName
:
"智能语音"
,
ParentName
:
"智能语音"
,
ChilName
:
"是否开启"
ChilName
:
"是否开启
,是否开启人机交互
"
}
}
}).
then
(
res
=>
{
}).
then
(
res
=>
{
if
(
res
.
code
!=
0
)
{
if
(
res
.
code
!=
0
)
{
...
@@ -42,6 +44,18 @@ const SoundAi = props => {
...
@@ -42,6 +44,18 @@ const SoundAi = props => {
reject
(
"字段开启字段值为空"
)
reject
(
"字段开启字段值为空"
)
return
return
}
}
const
spark
=
data
.
find
(
item
=>
item
.
nodeName
==
"是否开启人机交互"
)
if
(
spark
&&
spark
.
nodeValue
==
"开"
)
{
setGlobalConfig
(
globalConfig
=>
globalConfig
.
set
(
"key"
,
{
...
keyRef
.
current
,
isOpenSparkModel
:
true
}))
}
else
{
setGlobalConfig
(
globalConfig
=>
globalConfig
.
set
(
"key"
,
{
...
keyRef
.
current
,
isOpenSparkModel
:
false
}))
}
resolve
()
resolve
()
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
reject
(
error
)
reject
(
error
)
...
@@ -63,9 +77,11 @@ const SoundAi = props => {
...
@@ -63,9 +77,11 @@ const SoundAi = props => {
return
(
<>
return
(
<>
{
{
visible
?
<
Suspense
fallback
=
{
<><
/>}
>
visible
&&
globalConfig
.
get
(
"key"
)?
<
Context
.
Provider
value
=
{{
globalConfig
,
setGlobalConfig
}}
>
<
PandaUi
keyRef
=
{
keyRef
}
/
>
<
Suspense
fallback
=
{
<><
/>}
>
<
/Suspense> : nul
l
<
PandaUi
/>
<
/Suspense
>
<
/Context.Provider> : nul
l
}
}
<
/>
)
<
/>
)
}
}
...
...
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