fix: 监听语音结束逻辑

This commit is contained in:
white 2024-10-11 16:05:23 +08:00
parent f2d1f60941
commit f0a8f386ee
6 changed files with 148 additions and 244 deletions

View File

@ -159,6 +159,7 @@
const speakingTime = wordCount / wordsPerMinute; const speakingTime = wordCount / wordsPerMinute;
// 转换为秒数 // 转换为秒数
const speakingTimeInSeconds = speakingTime * 60; const speakingTimeInSeconds = speakingTime * 60;
console.log(speakingTimeInSeconds, '说完需要多少秒')
return speakingTimeInSeconds; return speakingTimeInSeconds;
} }
</script> </script>
@ -407,26 +408,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(filterString(str.output.text, ['*', ' '])); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -496,27 +489,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(voiceTxt.innerText); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -660,26 +644,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(content.data.choices[0].text); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });

View File

@ -159,6 +159,7 @@
const speakingTime = wordCount / wordsPerMinute; const speakingTime = wordCount / wordsPerMinute;
// 转换为秒数 // 转换为秒数
const speakingTimeInSeconds = speakingTime * 60; const speakingTimeInSeconds = speakingTime * 60;
console.log(speakingTimeInSeconds, '说完需要多少秒')
return speakingTimeInSeconds; return speakingTimeInSeconds;
} }
</script> </script>
@ -407,26 +408,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(filterString(str.output.text, ['*', ' '])); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -496,27 +489,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(voiceTxt.innerText); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -660,26 +644,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(content.data.choices[0].text); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });

View File

@ -159,6 +159,7 @@
const speakingTime = wordCount / wordsPerMinute; const speakingTime = wordCount / wordsPerMinute;
// 转换为秒数 // 转换为秒数
const speakingTimeInSeconds = speakingTime * 60; const speakingTimeInSeconds = speakingTime * 60;
console.log(speakingTimeInSeconds, '说完需要多少秒')
return speakingTimeInSeconds; return speakingTimeInSeconds;
} }
</script> </script>
@ -407,26 +408,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(filterString(str.output.text, ['*', ' '])); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -496,27 +489,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(voiceTxt.innerText); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -660,26 +644,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(content.data.choices[0].text); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });

View File

@ -159,6 +159,7 @@
const speakingTime = wordCount / wordsPerMinute; const speakingTime = wordCount / wordsPerMinute;
// 转换为秒数 // 转换为秒数
const speakingTimeInSeconds = speakingTime * 60; const speakingTimeInSeconds = speakingTime * 60;
console.log(speakingTimeInSeconds, '说完需要多少秒')
return speakingTimeInSeconds; return speakingTimeInSeconds;
} }
</script> </script>
@ -407,26 +408,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(filterString(str.output.text, ['*', ' '])); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -496,27 +489,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(voiceTxt.innerText); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown);
voice.stop(); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -660,26 +644,18 @@
// 循环视频 // 循环视频
replayVideoSegment(60, 120); replayVideoSegment(60, 120);
// 计算所需时间 // 监听播放技术
const speakingTime = calculateSpeakingTime(content.data.choices[0].text); myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 开始倒计时
var totalTime = speakingTime;
var countdown = setInterval(function() {
// 更新剩余时间
totalTime --;
if (totalTime <= 0) {
// 停止倒计时 // 停止倒计时
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
statusTxt.value = ''; statusTxt.value = '';
voiceTxt.innerText = ''; voiceTxt.innerText = '';
clearInterval(countdown); voice.stop();
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
}
}, 1000);
hideModal() hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });

Binary file not shown.