Commit 329f53c3 authored by ali's avatar ali

feat: 视频数字人麦克风状态流程优化

parent afe81980
......@@ -326,7 +326,7 @@ async function onAsr(question: string) {
isTime = false
sliceAnswer += text
if (/[。,?!;,.?!;]/.test(text) && sliceAnswer.length >= 20) {
if (/[。,?!;,.?!;]/.test(text) && sliceAnswer.length >= 10) {
console.timeEnd('sliceAnswer')
answerArray.push(sliceAnswer)
runTTSTask(answerArray)
......@@ -335,6 +335,7 @@ async function onAsr(question: string) {
}
} catch (error) {
console.log('返回答案错误 -----> ' + JSON.stringify(error))
microphoneState.value = 'input';
}
}
......@@ -362,13 +363,17 @@ async function runTTSTask(tasks: string[]) {
if (task.length < 1) continue
console.time(task + ' TTS: ')
microphoneState.value = 'loading';
const res = await localTTS({
url: settings.ttsHost,
text: task,
audio_path: settings.userData
})
console.log('----------------> TTS:', res[0].text)
console.timeEnd(task + ' TTS: ')
const audio = new Audio(`file://${res[0].text}`)
audio.load()
ttsAudios.push(audio)
......@@ -392,17 +397,18 @@ async function runAudioPlay() {
if (!audio) {
isPlayRunning = false;
videos[0].value!.pause();
microphoneState.value = 'input';
!isTTSRunning && (microphoneState.value = 'input');
return
}
audio.onended = () => {
isPlayRunning = false
loadVideo(new URL('/libai/10.mp4', import.meta.url).href)
videos[1].value!.loop = true
videos[1].value!.muted = true
runAudioPlay()
}
await audio.play();
loadVideo(new URL('/libai/10.mp4', import.meta.url).href)
videos[1].value!.loop = true
videos[1].value!.muted = true
microphoneState.value = 'reply';
}
......@@ -479,12 +485,13 @@ async function xfTTS(text: string) {
<style scoped>
.voice {
display: flex;
justify-content: center;
position: fixed;
top: 70%;
left: 0;
right: 0;
top: 70%;
z-index: 99;
display: flex;
justify-content: center;
margin: auto;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment