fix: 按钮状态
This commit is contained in:
parent
1674bbee2e
commit
dc7b8bf343
|
|
@ -113,7 +113,7 @@
|
|||
|
||||
// 遍历每一行来找到 data 字段
|
||||
lines.forEach(line => {
|
||||
if (line.trim().startsWith('data:')) {
|
||||
if (line.trim().startsWith('data:')) {
|
||||
isDataLine = true;
|
||||
dataLines.push(line.trim().slice(5)); // 移除 'data:' 前缀
|
||||
} else if (isDataLine && !line.trim()) {
|
||||
|
|
@ -254,6 +254,8 @@
|
|||
/*
|
||||
* 实例化迅飞语音听写(流式版)WebAPI
|
||||
*/
|
||||
|
||||
let seconds = 10;
|
||||
const voice = new Voice({
|
||||
// 服务接口认证信息
|
||||
appId: '5f4ffdeb',
|
||||
|
|
@ -266,6 +268,21 @@
|
|||
voiceTxt.innerText = text;
|
||||
marquee("marquee", "voice-txt");
|
||||
|
||||
let timer = setInterval(() => {
|
||||
seconds--;
|
||||
|
||||
if (seconds <= 0) {
|
||||
clearInterval(timer);
|
||||
if (text) {
|
||||
console.log(1); // 如果有 text 参数,打印 1
|
||||
} else {
|
||||
console.log("没有传入 text 参数"); // 如果没有 text 参数,执行其他逻辑
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
|
||||
|
||||
// 3秒钟内没有说话,就自动关闭
|
||||
if (text) {
|
||||
statusTxt.value = '正在听…';
|
||||
|
|
@ -463,7 +480,7 @@
|
|||
closeShibie();
|
||||
});
|
||||
|
||||
// 关闭识别
|
||||
// 暂停识别
|
||||
stopRec.addEventListener("click", function() {
|
||||
stopPlay();
|
||||
});
|
||||
|
|
@ -475,11 +492,15 @@
|
|||
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';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -602,6 +623,8 @@
|
|||
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
|
||||
statusTxt.value = '正在说话';
|
||||
|
||||
// 字幕文字
|
||||
voiceTxt.innerText = str;
|
||||
marquee("marquee", "voice-txt");
|
||||
|
|
@ -621,6 +644,7 @@
|
|||
// 停止倒计时
|
||||
startRec.style.display = 'block';
|
||||
endRec.style.display = 'none';
|
||||
stopRec.style.display = 'none';
|
||||
statusTxt.value = '';
|
||||
voiceTxt.innerText = '';
|
||||
voice.stop();
|
||||
|
|
|
|||
|
|
@ -46,8 +46,11 @@
|
|||
<!-- 录制 -->
|
||||
<div class="buttons startRec">点击说话</div>
|
||||
|
||||
<!-- 暂停 -->
|
||||
<div class="buttons endRec">中止</div>
|
||||
|
||||
<!-- 停止 -->
|
||||
<div class="buttons endRec">停止</div>
|
||||
<div class="buttons stopRec">暂停</div>
|
||||
</div>
|
||||
|
||||
<!-- 讯飞测试 -->
|
||||
|
|
@ -185,6 +188,7 @@
|
|||
|
||||
// 获取 audio 元素的引用
|
||||
var audioElement = document.getElementById('myAudio');
|
||||
var isPlaying = false; // 是否播放
|
||||
audioElement.muted = true; // 先静音
|
||||
|
||||
// 获取页面元素
|
||||
|
|
@ -196,7 +200,11 @@
|
|||
// 点击事件
|
||||
var startRec = document.getElementsByClassName('startRec')[0];
|
||||
var endRec = document.getElementsByClassName('endRec')[0];
|
||||
var stopRec = document.getElementsByClassName('stopRec')[0];
|
||||
|
||||
endRec.style.display = "none";
|
||||
stopRec.style.display = "none";
|
||||
|
||||
|
||||
var token = null;
|
||||
let times = null;
|
||||
|
|
@ -450,15 +458,35 @@
|
|||
startShibie();
|
||||
});
|
||||
|
||||
|
||||
// 关闭识别
|
||||
endRec.addEventListener("click", function() {
|
||||
closeShibie();
|
||||
});
|
||||
|
||||
// 关闭识别
|
||||
stopRec.addEventListener("click", function() {
|
||||
stopPlay();
|
||||
});
|
||||
|
||||
function stopPlay() {
|
||||
/**暂停播放**/
|
||||
if (audioElement.paused) {
|
||||
audioElement.play();
|
||||
videoElement.play();
|
||||
isPlaying = true;
|
||||
stopRec.textContent = '暂停';
|
||||
} else {
|
||||
audioElement.pause();
|
||||
videoElement.pause();
|
||||
isPlaying = false;
|
||||
stopRec.textContent = '继续播放';
|
||||
}
|
||||
};
|
||||
|
||||
function startShibie() {
|
||||
/**开始识别**/
|
||||
voiceTxt.innerText = '';
|
||||
stopRec.textContent = '暂停';
|
||||
voice.start();
|
||||
isCallbackExecuted = false;
|
||||
|
||||
|
|
@ -469,6 +497,7 @@
|
|||
|
||||
startRec.style.display = 'none';
|
||||
endRec.style.display = 'none';
|
||||
stopRec.style.display = 'none';
|
||||
showModal();
|
||||
}
|
||||
|
||||
|
|
@ -476,6 +505,7 @@
|
|||
/**关闭识别**/
|
||||
voiceTxt.innerText = '';
|
||||
statusTxt.value = '';
|
||||
stopRec.textContent = '暂停';
|
||||
|
||||
voice.stop();
|
||||
|
||||
|
|
@ -489,10 +519,10 @@
|
|||
|
||||
startRec.style.display = 'block';
|
||||
endRec.style.display = 'none';
|
||||
stopRec.style.display = 'none';
|
||||
hideModal()
|
||||
}
|
||||
|
||||
|
||||
// 显示弹窗和遮罩
|
||||
function showModal() {
|
||||
modal.style.display = 'block';
|
||||
|
|
@ -557,6 +587,7 @@
|
|||
}).then(async(response) => {
|
||||
startRec.style.display = "none";
|
||||
endRec.style.display = "block";
|
||||
stopRec.style.display = "block";
|
||||
|
||||
NextPlayVideo(response, filterString(Subtitles, ['*', ' ']));
|
||||
}).catch(e => {
|
||||
|
|
|
|||
|
|
@ -46,8 +46,11 @@
|
|||
<!-- 录制 -->
|
||||
<div class="buttons startRec">点击说话</div>
|
||||
|
||||
<!-- 暂停 -->
|
||||
<div class="buttons endRec">中止</div>
|
||||
|
||||
<!-- 停止 -->
|
||||
<div class="buttons endRec">停止</div>
|
||||
<div class="buttons stopRec">暂停</div>
|
||||
</div>
|
||||
|
||||
<!-- 讯飞测试 -->
|
||||
|
|
@ -185,6 +188,7 @@
|
|||
|
||||
// 获取 audio 元素的引用
|
||||
var audioElement = document.getElementById('myAudio');
|
||||
var isPlaying = false; // 是否播放
|
||||
audioElement.muted = true; // 先静音
|
||||
|
||||
// 获取页面元素
|
||||
|
|
@ -196,7 +200,11 @@
|
|||
// 点击事件
|
||||
var startRec = document.getElementsByClassName('startRec')[0];
|
||||
var endRec = document.getElementsByClassName('endRec')[0];
|
||||
var stopRec = document.getElementsByClassName('stopRec')[0];
|
||||
|
||||
endRec.style.display = "none";
|
||||
stopRec.style.display = "none";
|
||||
|
||||
|
||||
var token = null;
|
||||
let times = null;
|
||||
|
|
@ -450,15 +458,35 @@
|
|||
startShibie();
|
||||
});
|
||||
|
||||
|
||||
// 关闭识别
|
||||
endRec.addEventListener("click", function() {
|
||||
closeShibie();
|
||||
});
|
||||
|
||||
// 关闭识别
|
||||
stopRec.addEventListener("click", function() {
|
||||
stopPlay();
|
||||
});
|
||||
|
||||
function stopPlay() {
|
||||
/**暂停播放**/
|
||||
if (audioElement.paused) {
|
||||
audioElement.play();
|
||||
videoElement.play();
|
||||
isPlaying = true;
|
||||
stopRec.textContent = '暂停';
|
||||
} else {
|
||||
audioElement.pause();
|
||||
videoElement.pause();
|
||||
isPlaying = false;
|
||||
stopRec.textContent = '继续播放';
|
||||
}
|
||||
};
|
||||
|
||||
function startShibie() {
|
||||
/**开始识别**/
|
||||
voiceTxt.innerText = '';
|
||||
stopRec.textContent = '暂停';
|
||||
voice.start();
|
||||
isCallbackExecuted = false;
|
||||
|
||||
|
|
@ -469,6 +497,7 @@
|
|||
|
||||
startRec.style.display = 'none';
|
||||
endRec.style.display = 'none';
|
||||
stopRec.style.display = 'none';
|
||||
showModal();
|
||||
}
|
||||
|
||||
|
|
@ -476,6 +505,7 @@
|
|||
/**关闭识别**/
|
||||
voiceTxt.innerText = '';
|
||||
statusTxt.value = '';
|
||||
stopRec.textContent = '暂停';
|
||||
|
||||
voice.stop();
|
||||
|
||||
|
|
@ -489,10 +519,10 @@
|
|||
|
||||
startRec.style.display = 'block';
|
||||
endRec.style.display = 'none';
|
||||
stopRec.style.display = 'none';
|
||||
hideModal()
|
||||
}
|
||||
|
||||
|
||||
// 显示弹窗和遮罩
|
||||
function showModal() {
|
||||
modal.style.display = 'block';
|
||||
|
|
@ -557,6 +587,7 @@
|
|||
}).then(async(response) => {
|
||||
startRec.style.display = "none";
|
||||
endRec.style.display = "block";
|
||||
stopRec.style.display = "block";
|
||||
|
||||
NextPlayVideo(response, filterString(Subtitles, ['*', ' ']));
|
||||
}).catch(e => {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@
|
|||
|
||||
// 遍历每一行来找到 data 字段
|
||||
lines.forEach(line => {
|
||||
if (line.trim().startsWith('data:')) {
|
||||
if (line.trim().startsWith('data:')) {
|
||||
isDataLine = true;
|
||||
dataLines.push(line.trim().slice(5)); // 移除 'data:' 前缀
|
||||
} else if (isDataLine && !line.trim()) {
|
||||
|
|
@ -254,6 +254,8 @@
|
|||
/*
|
||||
* 实例化迅飞语音听写(流式版)WebAPI
|
||||
*/
|
||||
|
||||
let seconds = 10;
|
||||
const voice = new Voice({
|
||||
// 服务接口认证信息
|
||||
appId: '5f4ffdeb',
|
||||
|
|
@ -266,6 +268,21 @@
|
|||
voiceTxt.innerText = text;
|
||||
marquee("marquee", "voice-txt");
|
||||
|
||||
let timer = setInterval(() => {
|
||||
seconds--;
|
||||
|
||||
if (seconds <= 0) {
|
||||
clearInterval(timer);
|
||||
if (text) {
|
||||
console.log(1); // 如果有 text 参数,打印 1
|
||||
} else {
|
||||
console.log("没有传入 text 参数"); // 如果没有 text 参数,执行其他逻辑
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
|
||||
|
||||
// 3秒钟内没有说话,就自动关闭
|
||||
if (text) {
|
||||
statusTxt.value = '正在听…';
|
||||
|
|
@ -463,7 +480,7 @@
|
|||
closeShibie();
|
||||
});
|
||||
|
||||
// 关闭识别
|
||||
// 暂停识别
|
||||
stopRec.addEventListener("click", function() {
|
||||
stopPlay();
|
||||
});
|
||||
|
|
@ -475,11 +492,15 @@
|
|||
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';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -602,6 +623,8 @@
|
|||
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
|
||||
statusTxt.value = '正在说话';
|
||||
|
||||
// 字幕文字
|
||||
voiceTxt.innerText = str;
|
||||
marquee("marquee", "voice-txt");
|
||||
|
|
@ -621,6 +644,7 @@
|
|||
// 停止倒计时
|
||||
startRec.style.display = 'block';
|
||||
endRec.style.display = 'none';
|
||||
stopRec.style.display = 'none';
|
||||
statusTxt.value = '';
|
||||
voiceTxt.innerText = '';
|
||||
voice.stop();
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue