Commit 19dfc9af authored by ali's avatar ali

fix: 修复相应bug

parent 38df065c
...@@ -351,7 +351,7 @@ export class PhotoRole extends EventEmitter { ...@@ -351,7 +351,7 @@ export class PhotoRole extends EventEmitter {
return new Promise<boolean>((resolve) => { return new Promise<boolean>((resolve) => {
let count = 0 let count = 0
const keepCalling = async () => { const keepCalling = async () => {
if (count >= 10) return resolve(false) if (count >= 30) return resolve(false)
count++ count++
const { status } = await this._getLiveStatus(taskId) const { status } = await this._getLiveStatus(taskId)
......
...@@ -368,6 +368,7 @@ function initLLMSocket(): Promise<WebSocket> { ...@@ -368,6 +368,7 @@ function initLLMSocket(): Promise<WebSocket> {
async function endAudioInput() { async function endAudioInput() {
microphoneState.value = 'waitInput' microphoneState.value = 'waitInput'
inputContext.ws?.close()
inputContext.mediaStream?.getTracks().forEach((track) => track.stop()) inputContext.mediaStream?.getTracks().forEach((track) => track.stop())
inputContext.audioContext?.close() inputContext.audioContext?.close()
inputContext.audioContext2?.close() inputContext.audioContext2?.close()
...@@ -443,8 +444,10 @@ async function onQ(question: string) { ...@@ -443,8 +444,10 @@ async function onQ(question: string) {
photoRole!.on('asyncAnswer', onAsyncAnswer) photoRole!.on('asyncAnswer', onAsyncAnswer)
ws.onmessage = (message) => { ws.onmessage = (message) => {
clearTimeout(messageTimeout)
try { try {
const { text, event } = JSON.parse(message.data) as { let { text, event } = JSON.parse(message.data) as {
event: string event: string
message_num: number message_num: number
text: string text: string
...@@ -460,12 +463,12 @@ async function onQ(question: string) { ...@@ -460,12 +463,12 @@ async function onQ(question: string) {
return return
} }
text = text.replace(/\u0000/g, '').trim()
answer += text answer += text
photoRole!.answerArgs!.answer += answer photoRole!.answerArgs!.answer += answer
photoRole!.answerArgs!._typingAnswer.push(answer) photoRole!.answerArgs!._typingAnswer.push(answer)
isTime && console.time('sliceAnswer') isTime && console.time('sliceAnswer')
isTime = false isTime = false
clearTimeout(messageTimeout)
const textArr = text.split('') const textArr = text.split('')
for (let i = 0; i < textArr.length; i++) { for (let i = 0; i < textArr.length; i++) {
......
...@@ -263,6 +263,7 @@ function initLLMSocket(): Promise<WebSocket> { ...@@ -263,6 +263,7 @@ function initLLMSocket(): Promise<WebSocket> {
function endAudioInput() { function endAudioInput() {
microphoneState.value = 'waitInput' microphoneState.value = 'waitInput'
inputContext.ws?.close()
inputContext.mediaStream?.getTracks().forEach((track) => track.stop()) inputContext.mediaStream?.getTracks().forEach((track) => track.stop())
inputContext.audioContext?.close() inputContext.audioContext?.close()
inputContext.audioContext2?.close() inputContext.audioContext2?.close()
...@@ -360,12 +361,14 @@ async function onQ(question: string) { ...@@ -360,12 +361,14 @@ async function onQ(question: string) {
let sliceAnswerLength = 10 let sliceAnswerLength = 10
inputContext.ws = ws inputContext.ws = ws
ws.onmessage = (message) => { ws.onmessage = (message) => {
clearTimeout(messageTimeout)
if (microphoneState.value === 'input') { if (microphoneState.value === 'input') {
return return
} }
try { try {
const { text, event } = JSON.parse(message.data) as { let { text, event } = JSON.parse(message.data) as {
event: string event: string
message_num: number message_num: number
text: string text: string
...@@ -375,18 +378,15 @@ async function onQ(question: string) { ...@@ -375,18 +378,15 @@ async function onQ(question: string) {
inputContext.answerArray.push(sliceAnswer) inputContext.answerArray.push(sliceAnswer)
runTTSTask() runTTSTask()
sliceAnswer = '' sliceAnswer = ''
inputContext.answerArray.push(sliceAnswer)
sliceAnswer = ''
inputContext.ws?.close() inputContext.ws?.close()
console.log('----------------> answer: ', answer) console.log('----------------> answer: ', answer)
return return
} }
text = text.replace(/\u0000/g, '').trim()
answer += text answer += text
isTime && console.time('sliceAnswer') isTime && console.time('sliceAnswer')
isTime = false isTime = false
clearTimeout(messageTimeout)
const textArr = text.split('') const textArr = text.split('')
for (let i = 0; i < textArr.length; i++) { for (let i = 0; i < textArr.length; i++) {
......
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