This commit is contained in:
weipengfei 2024-01-17 18:12:00 +08:00
parent 75564a95f0
commit 8f979f5478
2 changed files with 33 additions and 6 deletions

View File

@ -152,6 +152,8 @@ async function loadTTS() {
//
const watchTTS = watch(() => props.tts, async (n: any, o: any) => {
console.log('文本变化', n);
if (props.tts == '') {
for (let i = 0; i < audioElements.length; i++) {
audioElements[i].pause()

View File

@ -438,26 +438,51 @@ async function onConversation() {
// }
// }
socket.onmessage = (event: any)=>{
console.log(event.data);
lastText+=event.data;
socket.onmessage = (e: any)=>{
console.log(e.data);
let event = {
data: {
event: '',
text: '',
tts_text: ''
}
};
event.data = JSON.parse(e.data);
const loading = false;
nowStart.value = false;
if(!event.data.includes('[finish]')) updateChat(
event.data.tts_text != '' ? tts.push(event.data.tts_text) : null
if(!event.data.event.includes('finish')) {
lastText+=event.data.text;
updateChat(
+uuid,
dataSources.value.length - 1,
{
dateTime: new Date().toLocaleString(),
text: lastText,
inversion: false,
tts: JSON.stringify(+uuid),
tts: JSON.stringify(tts),
error: false,
loading,
conversationOptions: { conversationId: uuid, parentMessageId: uuid },
requestOptions: { prompt: message, options: { ...options } },
},
)
else{
} else if(event.data.tts_text){
updateChat(
+uuid,
dataSources.value.length - 1,
{
dateTime: new Date().toLocaleString(),
text: lastText,
inversion: false,
tts: JSON.stringify(tts),
error: false,
loading,
conversationOptions: { conversationId: uuid, parentMessageId: uuid },
requestOptions: { prompt: message, options: { ...options } },
},
)
} else{
//
nowStatus.value = 'input'
socket.close()