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

@ -137,7 +137,7 @@
console.error('解析 data 字段为 JSON 时出错:', error); console.error('解析 data 字段为 JSON 时出错:', error);
} }
}); });
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值 // 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent; return stopEvent;
} }
@ -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; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio'); var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放 var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音 audioElement.muted = true; // 先静音
// 获取页面元素 // 获取页面元素
var element = document.getElementById("elementId"); var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
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;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) { for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type] exampleData[i].name = demoData[exampleData[i].type]
}; };
// 过滤掉非对象类型的值 // 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object'); const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/* /*
* 实例化迅飞语音听写流式版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 };
@ -381,7 +378,7 @@
xhr.onerror = function () { xhr.onerror = function () {
console.error('An error occurred during the transaction', xhr.statusText); console.error('An error occurred during the transaction', xhr.statusText);
}; };
/* /*
* 关键字转换 * 关键字转换
*/ */
@ -475,7 +472,12 @@
} }
} }
} else if (seconds == 0){ } else if (seconds == 0){
reset(); clearInterval(gaptime);
closeShibie();
// 重置
location.reload();
return;
} }
}, 1000); }, 1000);
} }
@ -500,19 +502,19 @@
function stopPlay() { function stopPlay() {
/**暂停播放**/ /**暂停播放**/
if (audioElement.paused) { if (audioElement.paused) {
audioElement.play(); audioElement.play();
videoElement.play(); videoElement.play();
isPlaying = true; isPlaying = true;
stopRec.textContent = '暂停'; stopRec.textContent = '暂停';
statusTxt.value = '正在播放'; statusTxt.value = '正在播放';
endRec.style.display = 'block'; endRec.style.display = 'block';
} else { } else {
audioElement.pause(); audioElement.pause();
videoElement.pause(); videoElement.pause();
isPlaying = false; isPlaying = false;
stopRec.textContent = '继续播放'; stopRec.textContent = '继续播放';
statusTxt.value = '已暂停'; statusTxt.value = '已暂停';
endRec.style.display = 'none'; endRec.style.display = 'none';
} }
}; };
@ -527,13 +529,8 @@
// 先静音即可处理解决(提前做交互) // 先静音即可处理解决(提前做交互)
audioElement.muted = false; audioElement.muted = false;
// 检查是否可以播放,避免中断 audioElement.currentTime = 0;
if (!audioElement.paused) { audioElement.pause();
audioElement.currentTime = 0;
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();
// 音频 // 音频
// 检查是否可以播放,避免中断 audioElement.pause();
if (!audioElement.paused) { audioElement.currentTime = 0;
audioElement.currentTime = 0; // 视频
audioElement.pause();
};
// 视频
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';
@ -577,7 +564,7 @@
function showModal() { function showModal() {
modal.style.display = 'block'; modal.style.display = 'block';
dialog.style.display = 'block'; dialog.style.display = 'block';
} }
// 隐藏弹窗和遮罩 // 隐藏弹窗和遮罩
function hideModal() { function hideModal() {
@ -779,7 +766,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>

View File

@ -137,7 +137,7 @@
console.error('解析 data 字段为 JSON 时出错:', error); console.error('解析 data 字段为 JSON 时出错:', error);
} }
}); });
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值 // 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent; return stopEvent;
} }
@ -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; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio'); var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放 var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音 audioElement.muted = true; // 先静音
// 获取页面元素 // 获取页面元素
var element = document.getElementById("elementId"); var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
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;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) { for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type] exampleData[i].name = demoData[exampleData[i].type]
}; };
// 过滤掉非对象类型的值 // 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object'); const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/* /*
* 实例化迅飞语音听写流式版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;
// 检查是否可以播放,避免中断 audioElement.currentTime = 0;
if (!audioElement.paused) { audioElement.pause();
audioElement.currentTime = 0;
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();
// 音频 // 音频
// 检查是否可以播放,避免中断 audioElement.pause();
if (!audioElement.paused) { audioElement.currentTime = 0;
audioElement.currentTime = 0; // 视频
audioElement.pause();
};
// 视频
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';
@ -580,7 +570,7 @@
function showModal() { function showModal() {
modal.style.display = 'block'; modal.style.display = 'block';
dialog.style.display = 'block'; dialog.style.display = 'block';
} }
// 隐藏弹窗和遮罩 // 隐藏弹窗和遮罩
function hideModal() { function hideModal() {
@ -782,7 +772,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>

View File

@ -137,7 +137,7 @@
console.error('解析 data 字段为 JSON 时出错:', error); console.error('解析 data 字段为 JSON 时出错:', error);
} }
}); });
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值 // 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent; return stopEvent;
} }
@ -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; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio'); var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放 var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音 audioElement.muted = true; // 先静音
// 获取页面元素 // 获取页面元素
var element = document.getElementById("elementId"); var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
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;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) { for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type] exampleData[i].name = demoData[exampleData[i].type]
}; };
// 过滤掉非对象类型的值 // 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object'); const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/* /*
* 实例化迅飞语音听写流式版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;
// 检查是否可以播放,避免中断 audioElement.currentTime = 0;
if (!audioElement.paused) { audioElement.pause();
audioElement.currentTime = 0;
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();
// 音频 // 音频
// 检查是否可以播放,避免中断 audioElement.pause();
if (!audioElement.paused) { audioElement.currentTime = 0;
audioElement.currentTime = 0; // 视频
audioElement.pause();
};
// 视频
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';
@ -580,7 +570,7 @@
function showModal() { function showModal() {
modal.style.display = 'block'; modal.style.display = 'block';
dialog.style.display = 'block'; dialog.style.display = 'block';
} }
// 隐藏弹窗和遮罩 // 隐藏弹窗和遮罩
function hideModal() { function hideModal() {
@ -782,7 +772,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>

View File

@ -137,7 +137,7 @@
console.error('解析 data 字段为 JSON 时出错:', error); console.error('解析 data 字段为 JSON 时出错:', error);
} }
}); });
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值 // 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent; return stopEvent;
} }
@ -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; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio'); var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放 var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音 audioElement.muted = true; // 先静音
// 获取页面元素 // 获取页面元素
var element = document.getElementById("elementId"); var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
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;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) { for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type] exampleData[i].name = demoData[exampleData[i].type]
}; };
// 过滤掉非对象类型的值 // 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object'); const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/* /*
* 实例化迅飞语音听写流式版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 };
@ -381,7 +378,7 @@
xhr.onerror = function () { xhr.onerror = function () {
console.error('An error occurred during the transaction', xhr.statusText); console.error('An error occurred during the transaction', xhr.statusText);
}; };
/* /*
* 关键字转换 * 关键字转换
*/ */
@ -475,7 +472,12 @@
} }
} }
} else if (seconds == 0){ } else if (seconds == 0){
reset(); clearInterval(gaptime);
closeShibie();
// 重置
location.reload();
return;
} }
}, 1000); }, 1000);
} }
@ -500,19 +502,19 @@
function stopPlay() { function stopPlay() {
/**暂停播放**/ /**暂停播放**/
if (audioElement.paused) { if (audioElement.paused) {
audioElement.play(); audioElement.play();
videoElement.play(); videoElement.play();
isPlaying = true; isPlaying = true;
stopRec.textContent = '暂停'; stopRec.textContent = '暂停';
statusTxt.value = '正在播放'; statusTxt.value = '正在播放';
endRec.style.display = 'block'; endRec.style.display = 'block';
} else { } else {
audioElement.pause(); audioElement.pause();
videoElement.pause(); videoElement.pause();
isPlaying = false; isPlaying = false;
stopRec.textContent = '继续播放'; stopRec.textContent = '继续播放';
statusTxt.value = '已暂停'; statusTxt.value = '已暂停';
endRec.style.display = 'none'; endRec.style.display = 'none';
} }
}; };
@ -527,13 +529,8 @@
// 先静音即可处理解决(提前做交互) // 先静音即可处理解决(提前做交互)
audioElement.muted = false; audioElement.muted = false;
// 检查是否可以播放,避免中断 audioElement.currentTime = 0;
if (!audioElement.paused) { audioElement.pause();
audioElement.currentTime = 0;
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();
// 音频 // 音频
// 检查是否可以播放,避免中断 audioElement.pause();
if (!audioElement.paused) { audioElement.currentTime = 0;
audioElement.currentTime = 0; // 视频
audioElement.pause();
};
// 视频
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';
@ -577,7 +564,7 @@
function showModal() { function showModal() {
modal.style.display = 'block'; modal.style.display = 'block';
dialog.style.display = 'block'; dialog.style.display = 'block';
} }
// 隐藏弹窗和遮罩 // 隐藏弹窗和遮罩
function hideModal() { function hideModal() {
@ -779,7 +766,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null // 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null; return null;
} }
} };
</script> </script>