接入语音

This commit is contained in:
aixianling
2023-11-10 17:13:55 +08:00
parent ad77470063
commit 24a775f94a
5 changed files with 55 additions and 22 deletions

View File

@@ -198,7 +198,7 @@ export class ChatGLM extends BaseModel {
} else return Promise.reject("没有权限或者网络异常,请重新尝试!")
}
streamOutput(reader, chat) {
streamOutput(reader, chat, cb) {
return reader.read().then(({done, value}) => {
if (done) {
return;
@@ -206,8 +206,13 @@ export class ChatGLM extends BaseModel {
const decode = new TextDecoder().decode(value)
const dialogue = decode.split("event:").at(-1)
const msg = dialogue.split("\n").filter(e => e.startsWith("data:"))?.map(e => e.replace("data:", '')).join("\n")
if (msg?.length > 0) chat.msg = msg
return this.streamOutput(reader, chat)
if (msg?.length > 0) {
chat.msg = msg
if (typeof cb == "function") {
cb(msg)
}
}
return this.streamOutput(reader, chat, cb)
})
}
}