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