fix: 刷新页面处理

This commit is contained in:
white 2024-10-17 10:30:23 +08:00
parent 5be54dd239
commit b9dd70b658
5 changed files with 140 additions and 186 deletions

View File

@ -146,10 +146,6 @@
<!-- 讯飞语音识别 --> <!-- 讯飞语音识别 -->
<script> <script>
window.onload = function () { window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo'); var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位) var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位) var endTime = 10; // 结束时间(以秒为单位)
@ -211,7 +207,6 @@
endRec.style.display = "none"; endRec.style.display = "none";
stopRec.style.display = "none"; stopRec.style.display = "none";
var token = null; var token = null;
let times = null; let times = null;
@ -260,24 +255,24 @@
/* /*
* 实例化迅飞语音听写流式版WebAPI * 实例化迅飞语音听写流式版WebAPI
*/ */
var seconds = 10; var seconds = 5;
var gaptime = null; var gaptime = null;
const voice = new Voice({ var voice = new Voice({
// 服务接口认证信息 // 服务接口认证信息
appId: '5f4ffdeb', appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5', apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a', apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) { onWillStatusChange: function (oldStatus, newStatus) {},
console.log(oldStatus, newStatus, '交互逻辑')
},
onTextChange: function (text) { onTextChange: function (text) {
// 监听识别结果的变化 // 监听识别结果的变化
voiceTxt.innerText = text; voiceTxt.innerText = text;
marquee("marquee", "voice-txt"); marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它 // 如果已有定时器在运行,则清除它
if (gaptime) { if (gaptime) {
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null;
}; };
// 重置倒计时 // 重置倒计时
seconds = 10; seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1 console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null; gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭 // 3秒钟内没有说话就自动关闭
if (text) { if (text) {
@ -299,6 +295,7 @@
clearTimeout(times); clearTimeout(times);
times = setTimeout(() => { times = setTimeout(() => {
this.stop(); this.stop();
statusTxt.value = '正在说话';
const params = { msg: text }; const params = { msg: text };
@ -475,7 +472,12 @@
} }
} }
} else if (seconds == 0){ } else if (seconds == 0){
reset(); clearInterval(gaptime);
closeShibie();
// 重置
location.reload();
return;
} }
}, 1000); }, 1000);
} }
@ -527,13 +529,8 @@
// 先静音即可处理解决(提前做交互) // 先静音即可处理解决(提前做交互)
audioElement.muted = false; audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0; audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
};
seconds = 10;
voice.start(); voice.start();
@ -544,28 +541,18 @@
} }
function closeShibie() { function closeShibie() {
reset();
/**关闭识别**/ /**关闭识别**/
voiceTxt.innerText = ''; voiceTxt.innerText = '';
statusTxt.value = ''; statusTxt.value = '';
stopRec.textContent = '暂停'; stopRec.textContent = '暂停';
voice.stop();
// 音频 // 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
}; audioElement.currentTime = 0;
// 视频 // 视频
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
isCallbackExecuted = false; isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
@ -779,7 +766,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>

View File

@ -146,10 +146,6 @@
<!-- 讯飞语音识别 --> <!-- 讯飞语音识别 -->
<script> <script>
window.onload = function () { window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo'); var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位) var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位) var endTime = 10; // 结束时间(以秒为单位)
@ -211,7 +207,6 @@
endRec.style.display = "none"; endRec.style.display = "none";
stopRec.style.display = "none"; stopRec.style.display = "none";
var token = null; var token = null;
let times = null; let times = null;
@ -260,24 +255,24 @@
/* /*
* 实例化迅飞语音听写流式版WebAPI * 实例化迅飞语音听写流式版WebAPI
*/ */
var seconds = 10; var seconds = 5;
var gaptime = null; var gaptime = null;
const voice = new Voice({ var voice = new Voice({
// 服务接口认证信息 // 服务接口认证信息
appId: '5f4ffdeb', appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5', apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a', apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) { onWillStatusChange: function (oldStatus, newStatus) {},
console.log(oldStatus, newStatus, '交互逻辑')
},
onTextChange: function (text) { onTextChange: function (text) {
// 监听识别结果的变化 // 监听识别结果的变化
voiceTxt.innerText = text; voiceTxt.innerText = text;
marquee("marquee", "voice-txt"); marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它 // 如果已有定时器在运行,则清除它
if (gaptime) { if (gaptime) {
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null;
}; };
// 重置倒计时 // 重置倒计时
seconds = 10; seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1 console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null; gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭 // 3秒钟内没有说话就自动关闭
if (text) { if (text) {
@ -478,9 +474,16 @@
} else if (seconds == 0){ } else if (seconds == 0){
clearInterval(gaptime); clearInterval(gaptime);
closeShibie(); closeShibie();
reset();
gaptime = null; // 重置
seconds = 10; voiceTxt.innerText = '';
statusTxt.value = '';
replayVideoSegment(0, 60);
hideModal();
stopVideo();
window.onload();
return;
} }
}, 1000); }, 1000);
} }
@ -532,13 +535,8 @@
// 先静音即可处理解决(提前做交互) // 先静音即可处理解决(提前做交互)
audioElement.muted = false; audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0; audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
};
seconds = 10;
voice.start(); voice.start();
@ -553,22 +551,14 @@
voiceTxt.innerText = ''; voiceTxt.innerText = '';
statusTxt.value = ''; statusTxt.value = '';
stopRec.textContent = '暂停'; stopRec.textContent = '暂停';
voice.stop();
// 音频 // 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
}; audioElement.currentTime = 0;
// 视频 // 视频
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
isCallbackExecuted = false; isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
@ -782,7 +772,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>

View File

@ -146,10 +146,6 @@
<!-- 讯飞语音识别 --> <!-- 讯飞语音识别 -->
<script> <script>
window.onload = function () { window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo'); var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位) var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位) var endTime = 10; // 结束时间(以秒为单位)
@ -211,7 +207,6 @@
endRec.style.display = "none"; endRec.style.display = "none";
stopRec.style.display = "none"; stopRec.style.display = "none";
var token = null; var token = null;
let times = null; let times = null;
@ -260,24 +255,24 @@
/* /*
* 实例化迅飞语音听写流式版WebAPI * 实例化迅飞语音听写流式版WebAPI
*/ */
var seconds = 10; var seconds = 5;
var gaptime = null; var gaptime = null;
const voice = new Voice({ var voice = new Voice({
// 服务接口认证信息 // 服务接口认证信息
appId: '5f4ffdeb', appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5', apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a', apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) { onWillStatusChange: function (oldStatus, newStatus) {},
console.log(oldStatus, newStatus, '交互逻辑')
},
onTextChange: function (text) { onTextChange: function (text) {
// 监听识别结果的变化 // 监听识别结果的变化
voiceTxt.innerText = text; voiceTxt.innerText = text;
marquee("marquee", "voice-txt"); marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它 // 如果已有定时器在运行,则清除它
if (gaptime) { if (gaptime) {
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null;
}; };
// 重置倒计时 // 重置倒计时
seconds = 10; seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1 console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null; gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭 // 3秒钟内没有说话就自动关闭
if (text) { if (text) {
@ -478,9 +474,16 @@
} else if (seconds == 0){ } else if (seconds == 0){
clearInterval(gaptime); clearInterval(gaptime);
closeShibie(); closeShibie();
reset();
gaptime = null; // 重置
seconds = 10; voiceTxt.innerText = '';
statusTxt.value = '';
replayVideoSegment(0, 60);
hideModal();
stopVideo();
window.onload();
return;
} }
}, 1000); }, 1000);
} }
@ -532,13 +535,8 @@
// 先静音即可处理解决(提前做交互) // 先静音即可处理解决(提前做交互)
audioElement.muted = false; audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0; audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
};
seconds = 10;
voice.start(); voice.start();
@ -553,22 +551,14 @@
voiceTxt.innerText = ''; voiceTxt.innerText = '';
statusTxt.value = ''; statusTxt.value = '';
stopRec.textContent = '暂停'; stopRec.textContent = '暂停';
voice.stop();
// 音频 // 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
}; audioElement.currentTime = 0;
// 视频 // 视频
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
isCallbackExecuted = false; isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
@ -782,7 +772,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>

View File

@ -146,10 +146,6 @@
<!-- 讯飞语音识别 --> <!-- 讯飞语音识别 -->
<script> <script>
window.onload = function () { window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo'); var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位) var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位) var endTime = 10; // 结束时间(以秒为单位)
@ -211,7 +207,6 @@
endRec.style.display = "none"; endRec.style.display = "none";
stopRec.style.display = "none"; stopRec.style.display = "none";
var token = null; var token = null;
let times = null; let times = null;
@ -260,24 +255,24 @@
/* /*
* 实例化迅飞语音听写流式版WebAPI * 实例化迅飞语音听写流式版WebAPI
*/ */
var seconds = 10; var seconds = 5;
var gaptime = null; var gaptime = null;
const voice = new Voice({ var voice = new Voice({
// 服务接口认证信息 // 服务接口认证信息
appId: '5f4ffdeb', appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5', apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a', apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) { onWillStatusChange: function (oldStatus, newStatus) {},
console.log(oldStatus, newStatus, '交互逻辑')
},
onTextChange: function (text) { onTextChange: function (text) {
// 监听识别结果的变化 // 监听识别结果的变化
voiceTxt.innerText = text; voiceTxt.innerText = text;
marquee("marquee", "voice-txt"); marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它 // 如果已有定时器在运行,则清除它
if (gaptime) { if (gaptime) {
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null;
}; };
// 重置倒计时 // 重置倒计时
seconds = 10; seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1 console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime); clearInterval(gaptime);
gaptime = null; gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭 // 3秒钟内没有说话就自动关闭
if (text) { if (text) {
@ -299,6 +295,7 @@
clearTimeout(times); clearTimeout(times);
times = setTimeout(() => { times = setTimeout(() => {
this.stop(); this.stop();
statusTxt.value = '正在说话';
const params = { msg: text }; const params = { msg: text };
@ -475,7 +472,12 @@
} }
} }
} else if (seconds == 0){ } else if (seconds == 0){
reset(); clearInterval(gaptime);
closeShibie();
// 重置
location.reload();
return;
} }
}, 1000); }, 1000);
} }
@ -527,13 +529,8 @@
// 先静音即可处理解决(提前做交互) // 先静音即可处理解决(提前做交互)
audioElement.muted = false; audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0; audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
};
seconds = 10;
voice.start(); voice.start();
@ -544,28 +541,18 @@
} }
function closeShibie() { function closeShibie() {
reset();
/**关闭识别**/ /**关闭识别**/
voiceTxt.innerText = ''; voiceTxt.innerText = '';
statusTxt.value = ''; statusTxt.value = '';
stopRec.textContent = '暂停'; stopRec.textContent = '暂停';
voice.stop();
// 音频 // 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause(); audioElement.pause();
}; audioElement.currentTime = 0;
// 视频 // 视频
replayVideoSegment(0, 60); replayVideoSegment(0, 60);
isCallbackExecuted = false; isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block'; startRec.style.display = 'block';
endRec.style.display = 'none'; endRec.style.display = 'none';
@ -779,7 +766,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>