This commit is contained in:
weipengfei 2023-10-13 21:24:25 +08:00
parent 8e39d23b3b
commit 5dd3c67bb2
7 changed files with 75 additions and 17 deletions

View File

@ -12,7 +12,7 @@
<div /> <div />
</div> </div>
<p class="text"> <p class="text">
等待中 AI等待指令
</p> </p>
</div> </div>
</template> </template>

View File

@ -1,4 +1,5 @@
<template> <template>
<div style="position: relative;">
<div class="spin"> <div class="spin">
<div class="loader"> <div class="loader">
<div class="outer" /> <div class="outer" />
@ -6,9 +7,22 @@
<div class="inner" /> <div class="inner" />
</div> </div>
</div> </div>
<p class="text">
思考中
</p>
</div>
</template> </template>
<style scoped> <style scoped>
.text{
display: block;
width: 100%;
font-size: 1.5em;
text-align: center;
position: absolute;
left: 0;
bottom: -2em;
}
.spin{ .spin{
display: flex; display: flex;
justify-content: center; justify-content: center;

View File

@ -20,7 +20,7 @@
text-align: center; text-align: center;
position: absolute; position: absolute;
left: 0; left: 0;
bottom: -2em; bottom: -6em;
} }
.div { .div {
display: flex; display: flex;

View File

@ -3,6 +3,7 @@ declare namespace Chat {
interface Chat { interface Chat {
dateTime: string dateTime: string
text: string text: string
tts?: string
inversion?: boolean inversion?: boolean
error?: boolean error?: boolean
loading?: boolean loading?: boolean

View File

@ -1,5 +1,5 @@
<script setup lang='ts'> <script setup lang='ts'>
import { computed, reactive, ref, watch } from 'vue' import { computed, reactive, ref, watch, toRef, nextTick } from 'vue'
import { NDropdown, useMessage } from 'naive-ui' import { NDropdown, useMessage } from 'naive-ui'
import AvatarComponent from './Avatar.vue' import AvatarComponent from './Avatar.vue'
import TextComponent from './Text.vue' import TextComponent from './Text.vue'
@ -12,7 +12,7 @@ import { copyToClip } from '@/utils/copy'
interface Props { interface Props {
dateTime?: string dateTime?: string
text?: string text?: string
mp3?: Array<any> tts?: string
inversion?: boolean inversion?: boolean
error?: boolean error?: boolean
loading?: boolean loading?: boolean
@ -92,11 +92,43 @@ async function handleCopy() {
message.error('复制失败') message.error('复制失败')
} }
} }
import axios from "axios"
function loadTTS(){
let tts = props.tts?JSON.parse(props.tts):[]
for(let i=0;i<tts.length;i++){
axios.post('https://chat.lihaink.cn/index/tts',{data: '你好'})
.then(response => {
//
console.log('请求成功',response.data);
const a = new Audio(response.data.mp3)
a.addEventListener('ended', () => {
onAudioEnd()
})
audioElements.push(a)
if (i == 0)
playAudio(i)
})
.catch(error => {
//
console.error('请求失败',error);
});
}
}
//
watch(()=>props.tts, async (n:any, o:any)=>{
loadTTS();
},{immediate:true,deep:true})
console.log( '组件渲染 ', props.text, props.tts);
const playStatus = ref('end') const playStatus = ref('end')
let playing = 0 let playing = 0
let sok = false let sok = false
async function radioPlay() { async function radioPlay() {
console.log('播放', props.mp3) return console.log('播放', props.tts[0])
audioElements.length = 0 audioElements.length = 0
emit('changeNowStatus', 'loding') emit('changeNowStatus', 'loding')
const socket = new WebSocket('wss://chat.lihaink.cn/zhanti/tts') const socket = new WebSocket('wss://chat.lihaink.cn/zhanti/tts')
@ -128,7 +160,6 @@ async function radioPlay() {
// })) // }))
socket.send(JSON.stringify({ socket.send(JSON.stringify({
data: props.text, data: props.text,
data: props.text,
})) }))
playStatus.value = 'playing' playStatus.value = 'playing'
let i = 0 let i = 0

View File

@ -108,7 +108,7 @@ const conversationList = computed(() =>
const prompt = ref<string>('') const prompt = ref<string>('')
const loading = ref<boolean>(false) const loading = ref<boolean>(false)
const inputRef = ref<Ref | null>(null) const inputRef = ref<Ref | null>(null)
const nowStatus = ref('record') // , input, loding, record, start const nowStatus = ref('input') // , input, loding, record,
const nowStart = ref(true) // , const nowStart = ref(true) // ,
// PromptStore // PromptStore
@ -166,6 +166,7 @@ async function onConversation() {
addChat(+uuid, { addChat(+uuid, {
dateTime: new Date().toLocaleString(), dateTime: new Date().toLocaleString(),
text: message, text: message,
tts: '',
inversion: true, inversion: true,
error: false, error: false,
conversationOptions: null, conversationOptions: null,
@ -187,6 +188,7 @@ async function onConversation() {
addChat(+uuid, { addChat(+uuid, {
dateTime: new Date().toLocaleString(), dateTime: new Date().toLocaleString(),
text: '思考中', text: '思考中',
tts: '',
loading: true, loading: true,
inversion: false, inversion: false,
error: false, error: false,
@ -197,6 +199,7 @@ async function onConversation() {
try { try {
let lastText = '' let lastText = ''
const tts:any = [];
console.log('发送消息', message) console.log('发送消息', message)
const fetchChatAPIOnce = async () => { const fetchChatAPIOnce = async () => {
@ -218,6 +221,8 @@ async function onConversation() {
// console.log(`: `, msg.payload.choices.text[0].content); // console.log(`: `, msg.payload.choices.text[0].content);
// console.log(`: `, dataSources.value[dataSources.value.length - 1].text); // console.log(`: `, dataSources.value[dataSources.value.length - 1].text);
lastText += msg.payload.choices.text[0].content lastText += msg.payload.choices.text[0].content
console.log('tts:', msg.payload.choices.tts_text);
msg.payload.choices.tts_text != '' ? tts.push(msg.payload.choices.tts_text): null;
const loading = false const loading = false
nowStart.value = false nowStart.value = false
updateChat( updateChat(
@ -227,6 +232,7 @@ async function onConversation() {
dateTime: new Date().toLocaleString(), dateTime: new Date().toLocaleString(),
text: lastText, text: lastText,
inversion: false, inversion: false,
tts: JSON.stringify(tts),
error: false, error: false,
loading, loading,
conversationOptions: { conversationId: msg.header.sid, parentMessageId: msg.header.sid }, conversationOptions: { conversationId: msg.header.sid, parentMessageId: msg.header.sid },
@ -618,9 +624,9 @@ window.addEventListener('test', (e) => {
prompt.value = window.winText prompt.value = window.winText
}) })
// setTimeout(() => { setTimeout(() => {
// nowStart.value = false nowStart.value = false
// }, 800) }, 800)
</script> </script>
<template> <template>
@ -678,6 +684,7 @@ window.addEventListener('test', (e) => {
:key="index" :key="index"
:date-time="item.dateTime" :date-time="item.dateTime"
:text="item.text" :text="item.text"
:tts="item.tts"
:inversion="item.inversion" :inversion="item.inversion"
:error="item.error" :error="item.error"
:loading="item.loading" :loading="item.loading"

View File

@ -41,6 +41,11 @@ export default defineConfig((env) => {
changeOrigin: true, // 允许跨域 changeOrigin: true, // 允许跨域
rewrite: path => path.replace('/api/', '/'), rewrite: path => path.replace('/api/', '/'),
}, },
// 'http://chat.lihaink.cn/zhanti/tts': {
// target: 'http://chat.lihaink.cn/zhanti/tts',
// changeOrigin: true, // 允许跨域
// rewrite: path => path.replace('http://chat.lihaink.cn/zhanti/tts', '/'),
// },
}, },
}, },
build: { build: {