Commit 329f53c3 authored by ali's avatar ali

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

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