This commit is contained in:
weipengfei 2023-10-13 21:37:55 +08:00
parent 3ae1ea5dc8
commit 4e310b1a05
1 changed files with 17 additions and 9 deletions

View File

@ -95,25 +95,33 @@ async function handleCopy() {
import axios from "axios" import axios from "axios"
function loadTTS(){ const http = ()=>{
let tts = props.tts?JSON.parse(props.tts):[] return new Promise((resolve, reject)=>{
for(let i=0;i<tts.length;i++){
axios.post('https://chat.lihaink.cn/index/tts',{data: '你好'}) axios.post('https://chat.lihaink.cn/index/tts',{data: '你好'})
.then(response => { .then(response => {
// //
console.log('请求成功',response.data); console.log('请求成功',response.data);
const a = new Audio(response.data.mp3) resolve(response.data)
})
.catch(error => {
//
console.error('请求失败',error);
reject(error)
});
})
}
async function loadTTS(){
let tts = props.tts?JSON.parse(props.tts):[]
for(let i=0;i<tts.length;i++){
let res = await http(tts[i])
const a = new Audio(res.data.mp3)
a.addEventListener('ended', () => { a.addEventListener('ended', () => {
onAudioEnd() onAudioEnd()
}) })
audioElements.push(a) audioElements.push(a)
if (i == 0) if (i == 0)
playAudio() playAudio()
})
.catch(error => {
//
console.error('请求失败',error);
});
} }
} }