This commit is contained in:
weipengfei 2023-10-12 16:06:59 +08:00
parent 2fd4cd8798
commit 0301413779
3 changed files with 42 additions and 3 deletions

View File

@ -3,6 +3,7 @@ declare namespace Chat {
interface Chat {
dateTime: string
text: string
mp3: Array<any> | null
inversion?: boolean
error?: boolean
loading?: boolean

View File

@ -1,5 +1,5 @@
<script setup lang='ts'>
import { computed, ref } from 'vue'
import { computed, ref, reactive } from 'vue'
import { NDropdown, useMessage } from 'naive-ui'
import AvatarComponent from './Avatar.vue'
import TextComponent from './Text.vue'
@ -12,6 +12,7 @@ import { copyToClip } from '@/utils/copy'
interface Props {
dateTime?: string
text?: string
mp3?: Array<any>
inversion?: boolean
error?: boolean
loading?: boolean
@ -90,6 +91,31 @@ async function handleCopy() {
message.error('复制失败')
}
}
function radioPlay(){
console.log('播放', props.mp3);
for (let i = 0; i < props.mp3.value.length; i++) {
audioElements.push(new Audio(props.mp3.value[i]));
}
playAudio()
}
//
const audioElements = reactive([]);
//
const playAudio = () => {
for (let i = 0; i < audioElements.length; i++) {
audioElements[i].play();
}
};
//
const pauseAudio = () => {
for (let i = 0; i < audioElements.length; i++) {
audioElements[i].pause();
}
};
</script>
<template>
@ -127,6 +153,14 @@ async function handleCopy() {
@click="handleRegenerate"
>
<SvgIcon icon="ri:restart-line" />
</button>
<button
v-if="!inversion"
class="mb-2 transition text-neutral-300 hover:text-neutral-800 dark:hover:text-neutral-300"
@click="radioPlay"
>
播放
<!-- <SvgIcon icon="ri:restart-line" /> -->
</button>
<NDropdown
:trigger="isMobile ? 'click' : 'hover'"

View File

@ -169,11 +169,12 @@ async function onConversation() {
try {
let lastText = ''
let mp3: any = []
console.log('发送消息', message)
const fetchChatAPIOnce = async () => {
socket.send(JSON.stringify({
tts: 0,
tts: 1,
data: [
{
role: 'user',
@ -187,13 +188,15 @@ async function onConversation() {
const msg = JSON.parse(event.data)
// console.log(`: `, msg.payload.choices.text[0].content);
// console.log(`: `, dataSources.value[dataSources.value.length - 1].text);
lastText += msg.payload.choices.text[0].content
lastText += msg.payload.choices.text[0].content;
mp3.push(msg.payload.choices.mp3)
updateChat(
+uuid,
dataSources.value.length - 1,
{
dateTime: new Date().toLocaleString(),
text: lastText,
mp3: mp3,
inversion: false,
error: false,
loading: true,
@ -632,6 +635,7 @@ const click = () => {
:key="index"
:date-time="item.dateTime"
:text="item.text"
:mp3="item.mp3"
:inversion="item.inversion"
:error="item.error"
:loading="item.loading"