diff --git a/hybrid/html/ai.html b/hybrid/html/ai.html index 31d7cb1..d1b65a2 100755 --- a/hybrid/html/ai.html +++ b/hybrid/html/ai.html @@ -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(); diff --git a/unpackage/cache/wgt/__UNI__24DA8DD/hybrid/html/ai.html b/unpackage/cache/wgt/__UNI__24DA8DD/hybrid/html/ai.html index 93ecc80..31d7cb1 100644 --- a/unpackage/cache/wgt/__UNI__24DA8DD/hybrid/html/ai.html +++ b/unpackage/cache/wgt/__UNI__24DA8DD/hybrid/html/ai.html @@ -46,8 +46,11 @@
点击说话
+ +
中止
+ -
停止
+
暂停
@@ -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 => { diff --git a/unpackage/dist/build/app-plus/hybrid/html/ai.html b/unpackage/dist/build/app-plus/hybrid/html/ai.html index 93ecc80..31d7cb1 100644 --- a/unpackage/dist/build/app-plus/hybrid/html/ai.html +++ b/unpackage/dist/build/app-plus/hybrid/html/ai.html @@ -46,8 +46,11 @@
点击说话
+ +
中止
+ -
停止
+
暂停
@@ -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 => { diff --git a/unpackage/dist/dev/app-plus/hybrid/html/ai.html b/unpackage/dist/dev/app-plus/hybrid/html/ai.html index 31d7cb1..d1b65a2 100644 --- a/unpackage/dist/dev/app-plus/hybrid/html/ai.html +++ b/unpackage/dist/dev/app-plus/hybrid/html/ai.html @@ -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(); diff --git a/unpackage/release/.DS_Store b/unpackage/release/.DS_Store index 84517b9..23521e6 100644 Binary files a/unpackage/release/.DS_Store and b/unpackage/release/.DS_Store differ diff --git a/unpackage/release/apk/__UNI__24DA8DD__20241014113508.apk b/unpackage/release/apk/__UNI__24DA8DD__20241014113508.apk deleted file mode 100644 index bfa6066..0000000 Binary files a/unpackage/release/apk/__UNI__24DA8DD__20241014113508.apk and /dev/null differ diff --git a/unpackage/release/apk/__UNI__24DA8DD__20241015182814.apk b/unpackage/release/apk/__UNI__24DA8DD__20241015182814.apk deleted file mode 100644 index 7a78d93..0000000 Binary files a/unpackage/release/apk/__UNI__24DA8DD__20241015182814.apk and /dev/null differ