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);
}
});
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent;
}
@ -146,10 +146,6 @@
<!-- 讯飞语音识别 -->
<script>
window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音
// 获取页面元素
var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
endRec.style.display = "none";
stopRec.style.display = "none";
var token = null;
let times = null;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type]
};
// 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/*
* 实例化迅飞语音听写流式版WebAPI
*/
var seconds = 10;
var seconds = 5;
var gaptime = null;
const voice = new Voice({
var voice = new Voice({
// 服务接口认证信息
appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) {
console.log(oldStatus, newStatus, '交互逻辑')
},
onWillStatusChange: function (oldStatus, newStatus) {},
onTextChange: function (text) {
// 监听识别结果的变化
voiceTxt.innerText = text;
marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它
if (gaptime) {
clearInterval(gaptime);
};
gaptime = null;
};
// 重置倒计时
seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime);
gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭
if (text) {
@ -299,6 +295,7 @@
clearTimeout(times);
times = setTimeout(() => {
this.stop();
statusTxt.value = '正在说话';
const params = { msg: text };
@ -381,7 +378,7 @@
xhr.onerror = function () {
console.error('An error occurred during the transaction', xhr.statusText);
};
/*
* 关键字转换
*/
@ -475,7 +472,12 @@
}
}
} else if (seconds == 0){
reset();
clearInterval(gaptime);
closeShibie();
// 重置
location.reload();
return;
}
}, 1000);
}
@ -500,19 +502,19 @@
function stopPlay() {
/**暂停播放**/
if (audioElement.paused) {
audioElement.play();
videoElement.play();
isPlaying = true;
stopRec.textContent = '暂停';
statusTxt.value = '正在播放';
endRec.style.display = 'block';
audioElement.play();
videoElement.play();
isPlaying = true;
stopRec.textContent = '暂停';
statusTxt.value = '正在播放';
endRec.style.display = 'block';
} else {
audioElement.pause();
videoElement.pause();
isPlaying = false;
stopRec.textContent = '继续播放';
statusTxt.value = '已暂停';
endRec.style.display = 'none';
audioElement.pause();
videoElement.pause();
isPlaying = false;
stopRec.textContent = '继续播放';
statusTxt.value = '已暂停';
endRec.style.display = 'none';
}
};
@ -527,13 +529,8 @@
// 先静音即可处理解决(提前做交互)
audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
seconds = 10;
audioElement.currentTime = 0;
audioElement.pause();
voice.start();
@ -544,28 +541,18 @@
}
function closeShibie() {
reset();
/**关闭识别**/
voiceTxt.innerText = '';
statusTxt.value = '';
stopRec.textContent = '暂停';
voice.stop();
// 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
// 视频
audioElement.pause();
audioElement.currentTime = 0;
// 视频
replayVideoSegment(0, 60);
isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block';
endRec.style.display = 'none';
@ -577,7 +564,7 @@
function showModal() {
modal.style.display = 'block';
dialog.style.display = 'block';
}
}
// 隐藏弹窗和遮罩
function hideModal() {
@ -779,7 +766,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null;
}
}
};
</script>

View File

@ -137,7 +137,7 @@
console.error('解析 data 字段为 JSON 时出错:', error);
}
});
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent;
}
@ -146,10 +146,6 @@
<!-- 讯飞语音识别 -->
<script>
window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音
// 获取页面元素
var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
endRec.style.display = "none";
stopRec.style.display = "none";
var token = null;
let times = null;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type]
};
// 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/*
* 实例化迅飞语音听写流式版WebAPI
*/
var seconds = 10;
var seconds = 5;
var gaptime = null;
const voice = new Voice({
var voice = new Voice({
// 服务接口认证信息
appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) {
console.log(oldStatus, newStatus, '交互逻辑')
},
onWillStatusChange: function (oldStatus, newStatus) {},
onTextChange: function (text) {
// 监听识别结果的变化
voiceTxt.innerText = text;
marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它
if (gaptime) {
clearInterval(gaptime);
};
gaptime = null;
};
// 重置倒计时
seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime);
gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭
if (text) {
@ -478,9 +474,16 @@
} else if (seconds == 0){
clearInterval(gaptime);
closeShibie();
reset();
gaptime = null;
seconds = 10;
// 重置
voiceTxt.innerText = '';
statusTxt.value = '';
replayVideoSegment(0, 60);
hideModal();
stopVideo();
window.onload();
return;
}
}, 1000);
}
@ -532,13 +535,8 @@
// 先静音即可处理解决(提前做交互)
audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
seconds = 10;
audioElement.currentTime = 0;
audioElement.pause();
voice.start();
@ -553,22 +551,14 @@
voiceTxt.innerText = '';
statusTxt.value = '';
stopRec.textContent = '暂停';
voice.stop();
// 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
// 视频
audioElement.pause();
audioElement.currentTime = 0;
// 视频
replayVideoSegment(0, 60);
isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block';
endRec.style.display = 'none';
@ -580,7 +570,7 @@
function showModal() {
modal.style.display = 'block';
dialog.style.display = 'block';
}
}
// 隐藏弹窗和遮罩
function hideModal() {
@ -782,7 +772,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null;
}
}
};
</script>

View File

@ -137,7 +137,7 @@
console.error('解析 data 字段为 JSON 时出错:', error);
}
});
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent;
}
@ -146,10 +146,6 @@
<!-- 讯飞语音识别 -->
<script>
window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音
// 获取页面元素
var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
endRec.style.display = "none";
stopRec.style.display = "none";
var token = null;
let times = null;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type]
};
// 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/*
* 实例化迅飞语音听写流式版WebAPI
*/
var seconds = 10;
var seconds = 5;
var gaptime = null;
const voice = new Voice({
var voice = new Voice({
// 服务接口认证信息
appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) {
console.log(oldStatus, newStatus, '交互逻辑')
},
onWillStatusChange: function (oldStatus, newStatus) {},
onTextChange: function (text) {
// 监听识别结果的变化
voiceTxt.innerText = text;
marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它
if (gaptime) {
clearInterval(gaptime);
};
gaptime = null;
};
// 重置倒计时
seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime);
gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭
if (text) {
@ -478,9 +474,16 @@
} else if (seconds == 0){
clearInterval(gaptime);
closeShibie();
reset();
gaptime = null;
seconds = 10;
// 重置
voiceTxt.innerText = '';
statusTxt.value = '';
replayVideoSegment(0, 60);
hideModal();
stopVideo();
window.onload();
return;
}
}, 1000);
}
@ -532,13 +535,8 @@
// 先静音即可处理解决(提前做交互)
audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
seconds = 10;
audioElement.currentTime = 0;
audioElement.pause();
voice.start();
@ -553,22 +551,14 @@
voiceTxt.innerText = '';
statusTxt.value = '';
stopRec.textContent = '暂停';
voice.stop();
// 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
// 视频
audioElement.pause();
audioElement.currentTime = 0;
// 视频
replayVideoSegment(0, 60);
isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block';
endRec.style.display = 'none';
@ -580,7 +570,7 @@
function showModal() {
modal.style.display = 'block';
dialog.style.display = 'block';
}
}
// 隐藏弹窗和遮罩
function hideModal() {
@ -782,7 +772,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null;
}
}
};
</script>

View File

@ -137,7 +137,7 @@
console.error('解析 data 字段为 JSON 时出错:', error);
}
});
// 如果没有找到 finish_reason 为 "stop" 的事件,则返回 null 或其他默认值
return stopEvent;
}
@ -146,10 +146,6 @@
<!-- 讯飞语音识别 -->
<script>
window.onload = function () {
reset();
};
function reset() {
var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位)
@ -196,7 +192,7 @@
var audioElement = document.getElementById('myAudio');
var isPlaying = false; // 是否播放
audioElement.muted = true; // 先静音
// 获取页面元素
var element = document.getElementById("elementId");
@ -210,8 +206,7 @@
endRec.style.display = "none";
stopRec.style.display = "none";
var token = null;
let times = null;
@ -247,7 +242,7 @@
for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type]
};
// 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -260,25 +255,25 @@
/*
* 实例化迅飞语音听写流式版WebAPI
*/
var seconds = 10;
var seconds = 5;
var gaptime = null;
const voice = new Voice({
var voice = new Voice({
// 服务接口认证信息
appId: '5f4ffdeb',
apiSecret: 'OGIwM2RlMjBkOTI5Mzk5YTJlMzUwODI5',
apiKey: '0b17a761b6b7174b789f639119d7e29a',
onWillStatusChange: function (oldStatus, newStatus) {
console.log(oldStatus, newStatus, '交互逻辑')
},
onWillStatusChange: function (oldStatus, newStatus) {},
onTextChange: function (text) {
// 监听识别结果的变化
voiceTxt.innerText = text;
marquee("marquee", "voice-txt");
// 3秒钟内没有说话就自动关闭
// 如果已有定时器在运行,则清除它
if (gaptime) {
clearInterval(gaptime);
};
gaptime = null;
};
// 重置倒计时
seconds = 10;
@ -291,6 +286,7 @@
console.log('有 text 参数'); // 如果有 text 参数,打印 1
clearInterval(gaptime);
gaptime = null;
seconds = 10;
// 3秒钟内没有说话就自动关闭
if (text) {
@ -299,6 +295,7 @@
clearTimeout(times);
times = setTimeout(() => {
this.stop();
statusTxt.value = '正在说话';
const params = { msg: text };
@ -381,7 +378,7 @@
xhr.onerror = function () {
console.error('An error occurred during the transaction', xhr.statusText);
};
/*
* 关键字转换
*/
@ -475,7 +472,12 @@
}
}
} else if (seconds == 0){
reset();
clearInterval(gaptime);
closeShibie();
// 重置
location.reload();
return;
}
}, 1000);
}
@ -500,19 +502,19 @@
function stopPlay() {
/**暂停播放**/
if (audioElement.paused) {
audioElement.play();
videoElement.play();
isPlaying = true;
stopRec.textContent = '暂停';
statusTxt.value = '正在播放';
endRec.style.display = 'block';
audioElement.play();
videoElement.play();
isPlaying = true;
stopRec.textContent = '暂停';
statusTxt.value = '正在播放';
endRec.style.display = 'block';
} else {
audioElement.pause();
videoElement.pause();
isPlaying = false;
stopRec.textContent = '继续播放';
statusTxt.value = '已暂停';
endRec.style.display = 'none';
audioElement.pause();
videoElement.pause();
isPlaying = false;
stopRec.textContent = '继续播放';
statusTxt.value = '已暂停';
endRec.style.display = 'none';
}
};
@ -527,13 +529,8 @@
// 先静音即可处理解决(提前做交互)
audioElement.muted = false;
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
seconds = 10;
audioElement.currentTime = 0;
audioElement.pause();
voice.start();
@ -544,28 +541,18 @@
}
function closeShibie() {
reset();
/**关闭识别**/
voiceTxt.innerText = '';
statusTxt.value = '';
stopRec.textContent = '暂停';
voice.stop();
// 音频
// 检查是否可以播放,避免中断
if (!audioElement.paused) {
audioElement.currentTime = 0;
audioElement.pause();
};
// 视频
audioElement.pause();
audioElement.currentTime = 0;
// 视频
replayVideoSegment(0, 60);
isCallbackExecuted = false;
seconds = 10;
voice.stop();
console.log('关闭识别');
startRec.style.display = 'block';
endRec.style.display = 'none';
@ -577,7 +564,7 @@
function showModal() {
modal.style.display = 'block';
dialog.style.display = 'block';
}
}
// 隐藏弹窗和遮罩
function hideModal() {
@ -779,7 +766,7 @@
// 如果没有找到匹配的数据项则返回null或错误信息这里选择返回null
return null;
}
}
};
</script>