Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CharIP-Electron
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
ali
CharIP-Electron
Commits
dff91c47
You need to sign in or sign up before continuing.
Commit
dff91c47
authored
Dec 26, 2023
by
ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 异常处理
parent
52ba82c4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
29 deletions
+117
-29
PhotoRole.ts
src/renderer/plugins/live/PhotoRole.ts
+3
-3
ShowPhoto.vue
src/renderer/screens/ShowPhoto.vue
+52
-8
ShowVideo.vue
src/renderer/screens/ShowVideo.vue
+62
-18
No files found.
src/renderer/plugins/live/PhotoRole.ts
View file @
dff91c47
...
...
@@ -509,9 +509,9 @@ export class PhotoRole extends EventEmitter {
}
async
destroy
()
{
this
.
_liveTaskQueue
.
length
=
0
;
await
this
.
_stopLive
(
this
.
sessionId
)
;
this
.
_liveStatus
=
'closing'
;
this
.
_liveTaskQueue
.
length
=
0
await
this
.
_stopLive
(
this
.
sessionId
)
this
.
_liveStatus
=
'closing'
// this.answerArgs = null;
// this._webRTCContainer && document.body.removeChild(this._webRTCContainer)
this
.
_rtc
?.
stopPlay
()
...
...
src/renderer/screens/ShowPhoto.vue
View file @
dff91c47
...
...
@@ -49,6 +49,13 @@ onMounted(() => {
document
.
body
.
style
.
overflow
=
'hidden'
})
const
errorSnackbar
=
ref
<
boolean
>
(
false
)
const
errorMsg
=
ref
<
string
>
(
''
);
const
showError
=
(
msg
:
string
)
=>
{
errorSnackbar
.
value
=
true
;
errorMsg
.
value
=
msg
;
}
function
loadImg
():
Promise
<
HTMLImageElement
>
{
const
img
=
new
Image
()
img
.
src
=
url
...
...
@@ -371,7 +378,7 @@ async function endAudioInput() {
}
inputContext.asrPartial = ''
inputContext.answerArray.length = 0
await photoRole?.destroy()
;
await photoRole?.destroy()
}
const checkSteps = async () => {
...
...
@@ -411,15 +418,21 @@ async function onQ(question: string) {
microphoneState.value = 'loading'
const ws = await initLLMSocket()
inputContext.ws = ws
const { pose, stepResolve, stepReject } = createStep()
const messageTimeout = setTimeout(async () => {
showError('llm:timeout!')
await endAudioInput()
microphoneState.value = 'waitInput'
}, 5000);
let sliceAnswer = ''
let answer = ''
let isTime = true
let sliceAnswerLength = 10
inputContext.ws = ws
inputContext.answerArray.length = 0
inputContext.steps.length = 0
const { pose, stepResolve, stepReject } = createStep()
inputContext.steps.push(pose)
photoRole!.answerArgs = new PhotoAnswer()
...
...
@@ -446,6 +459,7 @@ async function onQ(question: string) {
photoRole!.answerArgs!._typingAnswer.push(answer)
isTime && console.time('sliceAnswer')
isTime = false
clearTimeout(messageTimeout);
const textArr = text.split('')
for (let i = 0; i < textArr.length; i++) {
...
...
@@ -461,6 +475,10 @@ async function onQ(question: string) {
}
}
} catch (error) {
showError('llm:'+ error)
endAudioInput().then(() => {
microphoneState.value = 'waitInput'
})
stepReject(JSON.stringify(error))
}
}
...
...
@@ -507,6 +525,10 @@ async function runTTSTask() {
}
)
}
} catch (error) {
showError('tts:'+ error)
endAudioInput().then(() => {
microphoneState.value = 'waitInput'
})
stepReject(JSON.stringify(error))
}
...
...
@@ -552,7 +574,14 @@ async function down() {
await endAudioInput()
}
startVoskWsAudioInput()
try {
await startVoskWsAudioInput()
} catch (error) {
showError('start:'+ error)
endAudioInput().then(() => {
microphoneState.value = 'waitInput'
})
}
}
</
script
>
...
...
@@ -578,10 +607,7 @@ async function down() {
color=
"#fff"
variant=
"elevated"
size=
"x-large"
:disabled=
"
microphoneState === 'loading' ||
microphoneState === 'disabled'
"
:disabled=
"microphoneState === 'loading' || microphoneState === 'disabled'"
@
pointerdown=
"down"
>
<v-icon
v-if=
"microphoneState === 'waitInput'"
icon=
"mdi-microphone"
></v-icon>
...
...
@@ -604,6 +630,24 @@ async function down() {
</
template
>
</v-btn>
</div>
<v-snackbar
v-model=
"errorSnackbar"
multi-line
:timeout=
"3000"
>
{{ errorMsg }}
<
template
#
actions
>
<v-btn
color=
"red"
variant=
"text"
@
click=
"errorSnackbar = false"
>
Close
</v-btn>
</
template
>
</v-snackbar>
</template>
<
style
scoped
>
.voice
{
...
...
src/renderer/screens/ShowVideo.vue
View file @
dff91c47
...
...
@@ -47,6 +47,13 @@ router.beforeEach((g) => {
if
(
!
g
.
query
.
url
)
return
router
.
push
(
'/error'
)
})
const
errorSnackbar
=
ref
<
boolean
>
(
false
)
const
errorMsg
=
ref
<
string
>
(
''
);
const
showError
=
(
msg
:
string
)
=>
{
errorSnackbar
.
value
=
true
;
errorMsg
.
value
=
msg
;
}
async
function
initVosk
({
result
,
partialResult
...
...
@@ -160,11 +167,11 @@ async function startVoskWsAudioInput() {
if
(
microphoneState
.
value
===
'loading'
)
return
if
(
microphoneState
.
value
===
'input'
)
{
endAudioInput
()
await
endAudioInput
()
return
}
initVoskWS
()
await
initVoskWS
()
sampleRate
=
16000
const
mediaStream
=
await
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
{
...
...
@@ -315,25 +322,37 @@ async function onQ(question: string) {
if
(
!
role
)
return
microphoneState
.
value
=
'loading'
if
(
await
qNLP
(
question
))
{
loadVideo
(
url
)
microphoneState
.
value
=
'reply'
const
videoEle
=
videos
[
1
].
value
videoEle
!
.
loop
=
false
videoEle
!
.
muted
=
false
videoEle
!
.
onended
=
()
=>
{
videoEle
!
.
onended
=
null
microphoneState
.
value
=
'input'
// TODO: 是否需要初始化
try
{
const
nlpUrl
=
await
qNLP
(
question
)
if
(
nlpUrl
)
{
loadVideo
(
nlpUrl
)
microphoneState
.
value
=
'reply'
const
videoEle
=
videos
[
1
].
value
videoEle
!
.
loop
=
false
videoEle
!
.
muted
=
false
videoEle
!
.
onended
=
()
=>
{
videoEle
!
.
onended
=
null
microphoneState
.
value
=
'input'
// TODO: 是否需要初始化
}
return
}
}
catch
(
error
)
{
microphoneState
.
value
=
'input'
showError
(
`nlp:
${
error
}
`
)
return
}
// 视频链接匹配不上,直接走大模型
const
ws
=
await
initLLMSocket
()
const
answerArray
:
string
[]
=
[]
const
messageTimeout
=
setTimeout
(()
=>
{
showError
(
'llm:timeout!'
)
endAudioInput
()
microphoneState
.
value
=
'waitInput'
},
5000
);
let
sliceAnswer
=
''
let
answer
=
''
const
answerArray
:
string
[]
=
[]
let
isTime
=
true
let
sliceAnswerLength
=
10
inputContext
.
ws
=
ws
...
...
@@ -365,6 +384,7 @@ async function onQ(question: string) {
answer
+=
text
isTime
&&
console
.
time
(
'sliceAnswer'
)
isTime
=
false
clearTimeout
(
messageTimeout
);
const
textArr
=
text
.
split
(
''
)
for
(
let
i
=
0
;
i
<
textArr
.
length
;
i
++
)
{
...
...
@@ -380,8 +400,9 @@ async function onQ(question: string) {
}
}
}
catch
(
error
)
{
console
.
log
(
'返回答案错误 -----> '
+
JSON
.
stringify
(
error
))
microphoneState
.
value
=
'input'
console
.
error
(
error
);
showError
(
`message:
${
error
}
`
)
microphoneState
.
value
=
'waitInput'
}
}
...
...
@@ -423,7 +444,8 @@ async function runTTSTask(tasks: string[]) {
runAudioPlay
()
}
}
catch
(
error
)
{
microphoneState
.
value
=
'input'
showError
(
`tts:
${
error
}
`
)
microphoneState
.
value
=
'waitInput'
console
.
error
(
error
)
}
...
...
@@ -470,12 +492,16 @@ async function xfTTS(text: string) {
console
.
log
(
'----------------> tts:'
,
res
)
}
function
down
()
{
async
function
down
()
{
if
(
microphoneState
.
value
===
'reply'
)
{
endAudioInput
()
}
startVoskWsAudioInput
()
try
{
await
startVoskWsAudioInput
()
}
catch
(
error
)
{
showError
(
`
${
error
}
`
)
}
}
</
script
>
...
...
@@ -533,6 +559,24 @@ function down() {
{{ item.q }}
</v-chip>
</div>
<v-snackbar
v-model=
"errorSnackbar"
multi-line
:timeout=
"3000"
>
{{ errorMsg }}
<
template
#
actions
>
<v-btn
color=
"red"
variant=
"text"
@
click=
"errorSnackbar = false"
>
Close
</v-btn>
</
template
>
</v-snackbar>
</template>
<
style
scoped
>
...
...
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