fix: 修复问题
This commit is contained in:
parent
eef3f742eb
commit
392157111c
|
|
@ -277,13 +277,9 @@
|
||||||
// 重置倒计时
|
// 重置倒计时
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
||||||
console.log(text)
|
|
||||||
|
|
||||||
gaptime = setInterval(() => {
|
gaptime = setInterval(() => {
|
||||||
console.log(seconds, '倒计时')
|
|
||||||
seconds--;
|
seconds--;
|
||||||
if (voiceTxt.innerText) {
|
if (voiceTxt.innerText) {
|
||||||
console.log('有 text 参数'); // 如果有 text 参数,打印 1
|
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
gaptime = null;
|
gaptime = null;
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
@ -293,7 +289,6 @@
|
||||||
if (!isCallbackExecuted) {
|
if (!isCallbackExecuted) {
|
||||||
clearTimeout(times);
|
clearTimeout(times);
|
||||||
times = setTimeout(() => {
|
times = setTimeout(() => {
|
||||||
this.stop();
|
|
||||||
statusTxt.value = '正在听…';
|
statusTxt.value = '正在听…';
|
||||||
|
|
||||||
const params = { msg: text };
|
const params = { msg: text };
|
||||||
|
|
@ -473,9 +468,6 @@
|
||||||
} else if (seconds == 0){
|
} else if (seconds == 0){
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
closeShibie();
|
closeShibie();
|
||||||
|
|
||||||
// 重置
|
|
||||||
location.reload();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
@ -528,7 +520,6 @@
|
||||||
|
|
||||||
// 先静音即可处理解决(提前做交互)
|
// 先静音即可处理解决(提前做交互)
|
||||||
audioElement.muted = false;
|
audioElement.muted = false;
|
||||||
|
|
||||||
audioElement.currentTime = 0;
|
audioElement.currentTime = 0;
|
||||||
audioElement.pause();
|
audioElement.pause();
|
||||||
|
|
||||||
|
|
@ -657,37 +648,15 @@
|
||||||
// 监听播放技术
|
// 监听播放技术
|
||||||
myAudio.addEventListener('ended', function() {
|
myAudio.addEventListener('ended', function() {
|
||||||
console.log('音频播放已结束!');
|
console.log('音频播放已结束!');
|
||||||
// 停止倒计时
|
|
||||||
startRec.style.display = 'block';
|
|
||||||
endRec.style.display = 'none';
|
|
||||||
stopRec.style.display = 'none';
|
|
||||||
statusTxt.value = '';
|
|
||||||
voiceTxt.innerText = '';
|
|
||||||
replayVideoSegment(0, 60);
|
|
||||||
hideModal()
|
|
||||||
|
|
||||||
// 播放结束重新开始监听
|
// 播放结束重新开始监听
|
||||||
|
replayVideoSegment(0, 60);
|
||||||
|
voice.stop();
|
||||||
startShibie();
|
startShibie();
|
||||||
});
|
});
|
||||||
|
|
||||||
Subtitles = "";
|
Subtitles = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防抖
|
|
||||||
function throttle(fn, wait) {
|
|
||||||
let lastTime = 0; // 上一次调用的时间
|
|
||||||
|
|
||||||
return function (...args) {
|
|
||||||
const now = Date.now(); // 当前时间
|
|
||||||
|
|
||||||
// 如果距离上次调用已经超过设定时间,则调用函数
|
|
||||||
if (now - lastTime > wait) {
|
|
||||||
lastTime = now; // 更新上一次调用的时间
|
|
||||||
fn.apply(this, args); // 以正确的`this`和参数调用函数
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拿到的数据移除*
|
// 拿到的数据移除*
|
||||||
function filterString(str, charsToRemove) {
|
function filterString(str, charsToRemove) {
|
||||||
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@
|
||||||
};
|
};
|
||||||
// 连接WebSocket
|
// 连接WebSocket
|
||||||
connectWebSocket() {
|
connectWebSocket() {
|
||||||
|
console.log('连接WebSocket')
|
||||||
return this.getWebSocketUrl().then(url => {
|
return this.getWebSocketUrl().then(url => {
|
||||||
let iatWS;
|
let iatWS;
|
||||||
if ('WebSocket' in window) {
|
if ('WebSocket' in window) {
|
||||||
|
|
@ -122,8 +123,11 @@
|
||||||
}
|
}
|
||||||
this.webSocket = iatWS;
|
this.webSocket = iatWS;
|
||||||
this.setStatus('init');
|
this.setStatus('init');
|
||||||
|
|
||||||
iatWS.onopen = e => {
|
iatWS.onopen = e => {
|
||||||
this.setStatus('ing');
|
this.setStatus('ing');
|
||||||
|
console.log('ws开启重新开始录音');
|
||||||
|
|
||||||
// 重新开始录音
|
// 重新开始录音
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.webSocketSend();
|
this.webSocketSend();
|
||||||
|
|
@ -140,6 +144,18 @@
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 防抖函数
|
||||||
|
debounce(func, wait) {
|
||||||
|
let timeout;
|
||||||
|
return function(...args) {
|
||||||
|
const context = this;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => func.apply(context, args), wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化浏览器录音
|
// 初始化浏览器录音
|
||||||
recorderInit() {
|
recorderInit() {
|
||||||
// 创建音频环境
|
// 创建音频环境
|
||||||
|
|
@ -216,9 +232,10 @@
|
||||||
};
|
};
|
||||||
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
||||||
webSocketSend() {
|
webSocketSend() {
|
||||||
|
console.log('发送数据')
|
||||||
if (this.webSocket.readyState !== 1) return false;
|
if (this.webSocket.readyState !== 1) return false;
|
||||||
// 音频数据
|
// 音频数据
|
||||||
const audioData = this.audioData.splice(0, 1280);
|
let audioData = this.audioData.splice(0, 1280);
|
||||||
const params = {
|
const params = {
|
||||||
common: {
|
common: {
|
||||||
app_id: this.appId,
|
app_id: this.appId,
|
||||||
|
|
@ -237,14 +254,17 @@
|
||||||
audio: this.toBase64(audioData)
|
audio: this.toBase64(audioData)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
console.log(params, 'socket数据');
|
||||||
|
|
||||||
// 发送数据
|
// 发送数据
|
||||||
this.webSocket.send(JSON.stringify(params));
|
this.webSocket.send(JSON.stringify(params));
|
||||||
|
|
||||||
this.handlerInterval = setInterval(() => {
|
this.handlerInterval = setInterval(() => {
|
||||||
// websocket未连接
|
// websocket未连接
|
||||||
if (this.webSocket.readyState !== 1) {
|
if (this.webSocket.readyState !== 1) {
|
||||||
this.audioData = [];
|
this.audioData = [];
|
||||||
clearInterval(this.handlerInterval);
|
clearInterval(this.handlerInterval);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if (this.audioData.length === 0) {
|
if (this.audioData.length === 0) {
|
||||||
if (this.status === 'end') {
|
if (this.status === 'end') {
|
||||||
|
|
@ -312,9 +332,10 @@
|
||||||
this.webSocket.close();
|
this.webSocket.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 启动录音
|
// 启动录音
|
||||||
recorderStart() {
|
recorderStart() {
|
||||||
if (!this.audioContext) {
|
if (!this.audioContext) {
|
||||||
this.recorderInit();
|
this.recorderInit();
|
||||||
} else {
|
} else {
|
||||||
this.audioContext.resume();
|
this.audioContext.resume();
|
||||||
|
|
@ -340,8 +361,10 @@
|
||||||
this.setResultText({ resultText: '', resultTextTemp: '' });
|
this.setResultText({ resultText: '', resultTextTemp: '' });
|
||||||
};
|
};
|
||||||
// 停止
|
// 停止
|
||||||
stop() {
|
stop() {
|
||||||
|
console.log('停了停了停了停了停了停了停了停了停了停了');
|
||||||
this.recorderStop();
|
this.recorderStop();
|
||||||
|
this.webSocket.close();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
@ -277,25 +277,19 @@
|
||||||
// 重置倒计时
|
// 重置倒计时
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
||||||
console.log(text)
|
|
||||||
|
|
||||||
gaptime = setInterval(() => {
|
gaptime = setInterval(() => {
|
||||||
console.log(seconds, '倒计时')
|
|
||||||
seconds--;
|
seconds--;
|
||||||
if (voiceTxt.innerText) {
|
if (voiceTxt.innerText) {
|
||||||
console.log('有 text 参数'); // 如果有 text 参数,打印 1
|
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
gaptime = null;
|
gaptime = null;
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
||||||
// 3秒钟内没有说话,就自动关闭
|
// 3秒钟内没有说话,就自动关闭
|
||||||
if (text) {
|
if (text) {
|
||||||
statusTxt.value = '正在听…';
|
|
||||||
if (!isCallbackExecuted) {
|
if (!isCallbackExecuted) {
|
||||||
clearTimeout(times);
|
clearTimeout(times);
|
||||||
times = setTimeout(() => {
|
times = setTimeout(() => {
|
||||||
this.stop();
|
statusTxt.value = '正在听…';
|
||||||
statusTxt.value = '正在说话';
|
|
||||||
|
|
||||||
const params = { msg: text };
|
const params = { msg: text };
|
||||||
|
|
||||||
|
|
@ -474,9 +468,6 @@
|
||||||
} else if (seconds == 0){
|
} else if (seconds == 0){
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
closeShibie();
|
closeShibie();
|
||||||
|
|
||||||
// 重置
|
|
||||||
location.reload();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
@ -521,6 +512,7 @@
|
||||||
function startShibie() {
|
function startShibie() {
|
||||||
/**开始识别**/
|
/**开始识别**/
|
||||||
|
|
||||||
|
statusTxt.value = '正在听…';
|
||||||
voiceTxt.innerText = '';
|
voiceTxt.innerText = '';
|
||||||
stopRec.textContent = '暂停';
|
stopRec.textContent = '暂停';
|
||||||
|
|
||||||
|
|
@ -528,7 +520,6 @@
|
||||||
|
|
||||||
// 先静音即可处理解决(提前做交互)
|
// 先静音即可处理解决(提前做交互)
|
||||||
audioElement.muted = false;
|
audioElement.muted = false;
|
||||||
|
|
||||||
audioElement.currentTime = 0;
|
audioElement.currentTime = 0;
|
||||||
audioElement.pause();
|
audioElement.pause();
|
||||||
|
|
||||||
|
|
@ -657,37 +648,15 @@
|
||||||
// 监听播放技术
|
// 监听播放技术
|
||||||
myAudio.addEventListener('ended', function() {
|
myAudio.addEventListener('ended', function() {
|
||||||
console.log('音频播放已结束!');
|
console.log('音频播放已结束!');
|
||||||
// 停止倒计时
|
|
||||||
startRec.style.display = 'block';
|
|
||||||
endRec.style.display = 'none';
|
|
||||||
stopRec.style.display = 'none';
|
|
||||||
statusTxt.value = '';
|
|
||||||
voiceTxt.innerText = '';
|
|
||||||
replayVideoSegment(0, 60);
|
|
||||||
hideModal()
|
|
||||||
|
|
||||||
// 播放结束重新开始监听
|
// 播放结束重新开始监听
|
||||||
|
replayVideoSegment(0, 60);
|
||||||
|
voice.stop();
|
||||||
startShibie();
|
startShibie();
|
||||||
});
|
});
|
||||||
|
|
||||||
Subtitles = "";
|
Subtitles = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防抖
|
|
||||||
function throttle(fn, wait) {
|
|
||||||
let lastTime = 0; // 上一次调用的时间
|
|
||||||
|
|
||||||
return function (...args) {
|
|
||||||
const now = Date.now(); // 当前时间
|
|
||||||
|
|
||||||
// 如果距离上次调用已经超过设定时间,则调用函数
|
|
||||||
if (now - lastTime > wait) {
|
|
||||||
lastTime = now; // 更新上一次调用的时间
|
|
||||||
fn.apply(this, args); // 以正确的`this`和参数调用函数
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拿到的数据移除*
|
// 拿到的数据移除*
|
||||||
function filterString(str, charsToRemove) {
|
function filterString(str, charsToRemove) {
|
||||||
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@
|
||||||
};
|
};
|
||||||
// 连接WebSocket
|
// 连接WebSocket
|
||||||
connectWebSocket() {
|
connectWebSocket() {
|
||||||
|
console.log('连接WebSocket')
|
||||||
return this.getWebSocketUrl().then(url => {
|
return this.getWebSocketUrl().then(url => {
|
||||||
let iatWS;
|
let iatWS;
|
||||||
if ('WebSocket' in window) {
|
if ('WebSocket' in window) {
|
||||||
|
|
@ -122,8 +123,11 @@
|
||||||
}
|
}
|
||||||
this.webSocket = iatWS;
|
this.webSocket = iatWS;
|
||||||
this.setStatus('init');
|
this.setStatus('init');
|
||||||
|
|
||||||
iatWS.onopen = e => {
|
iatWS.onopen = e => {
|
||||||
this.setStatus('ing');
|
this.setStatus('ing');
|
||||||
|
console.log('ws开启重新开始录音');
|
||||||
|
|
||||||
// 重新开始录音
|
// 重新开始录音
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.webSocketSend();
|
this.webSocketSend();
|
||||||
|
|
@ -140,6 +144,18 @@
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 防抖函数
|
||||||
|
debounce(func, wait) {
|
||||||
|
let timeout;
|
||||||
|
return function(...args) {
|
||||||
|
const context = this;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => func.apply(context, args), wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化浏览器录音
|
// 初始化浏览器录音
|
||||||
recorderInit() {
|
recorderInit() {
|
||||||
// 创建音频环境
|
// 创建音频环境
|
||||||
|
|
@ -216,9 +232,10 @@
|
||||||
};
|
};
|
||||||
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
||||||
webSocketSend() {
|
webSocketSend() {
|
||||||
|
console.log('发送数据')
|
||||||
if (this.webSocket.readyState !== 1) return false;
|
if (this.webSocket.readyState !== 1) return false;
|
||||||
// 音频数据
|
// 音频数据
|
||||||
const audioData = this.audioData.splice(0, 1280);
|
let audioData = this.audioData.splice(0, 1280);
|
||||||
const params = {
|
const params = {
|
||||||
common: {
|
common: {
|
||||||
app_id: this.appId,
|
app_id: this.appId,
|
||||||
|
|
@ -237,14 +254,17 @@
|
||||||
audio: this.toBase64(audioData)
|
audio: this.toBase64(audioData)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
console.log(params, 'socket数据');
|
||||||
|
|
||||||
// 发送数据
|
// 发送数据
|
||||||
this.webSocket.send(JSON.stringify(params));
|
this.webSocket.send(JSON.stringify(params));
|
||||||
|
|
||||||
this.handlerInterval = setInterval(() => {
|
this.handlerInterval = setInterval(() => {
|
||||||
// websocket未连接
|
// websocket未连接
|
||||||
if (this.webSocket.readyState !== 1) {
|
if (this.webSocket.readyState !== 1) {
|
||||||
this.audioData = [];
|
this.audioData = [];
|
||||||
clearInterval(this.handlerInterval);
|
clearInterval(this.handlerInterval);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if (this.audioData.length === 0) {
|
if (this.audioData.length === 0) {
|
||||||
if (this.status === 'end') {
|
if (this.status === 'end') {
|
||||||
|
|
@ -312,9 +332,10 @@
|
||||||
this.webSocket.close();
|
this.webSocket.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 启动录音
|
// 启动录音
|
||||||
recorderStart() {
|
recorderStart() {
|
||||||
if (!this.audioContext) {
|
if (!this.audioContext) {
|
||||||
this.recorderInit();
|
this.recorderInit();
|
||||||
} else {
|
} else {
|
||||||
this.audioContext.resume();
|
this.audioContext.resume();
|
||||||
|
|
@ -340,8 +361,10 @@
|
||||||
this.setResultText({ resultText: '', resultTextTemp: '' });
|
this.setResultText({ resultText: '', resultTextTemp: '' });
|
||||||
};
|
};
|
||||||
// 停止
|
// 停止
|
||||||
stop() {
|
stop() {
|
||||||
|
console.log('停了停了停了停了停了停了停了停了停了停了');
|
||||||
this.recorderStop();
|
this.recorderStop();
|
||||||
|
this.webSocket.close();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__24DA8DD","name":"中鼎云医","version":{"name":"1.2.5","code":125},"description":"中鼎云医","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"VideoPlayer":{},"Record":{},"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"autoclose":true,"delay":0,"target":"id:1","waiting":true},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"usingComponents":true,"nvueStyleCompiler":"uni-app","compilerVersion":3,"distribute":{"screenOrientation":"landscape-primary","icons":{"android":{"hdpi":"icon-android-hdpi.png","xhdpi":"icon-android-xhdpi.png","xxhdpi":"icon-android-xxhdpi.png","xxxhdpi":"icon-android-xxxhdpi.png"},"ios":{"appstore":"unpackage/res/icons/1024x1024.png","ipad":{"app":"unpackage/res/icons/76x76.png","app@2x":"unpackage/res/icons/152x152.png","notification":"unpackage/res/icons/20x20.png","notification@2x":"unpackage/res/icons/40x40.png","proapp@2x":"unpackage/res/icons/167x167.png","settings":"unpackage/res/icons/29x29.png","settings@2x":"unpackage/res/icons/58x58.png","spotlight":"unpackage/res/icons/40x40.png","spotlight@2x":"unpackage/res/icons/80x80.png"},"iphone":{"app@2x":"unpackage/res/icons/120x120.png","app@3x":"unpackage/res/icons/180x180.png","notification@2x":"unpackage/res/icons/40x40.png","notification@3x":"unpackage/res/icons/60x60.png","settings@2x":"unpackage/res/icons/58x58.png","settings@3x":"unpackage/res/icons/87x87.png","spotlight@2x":"unpackage/res/icons/80x80.png","spotlight@3x":"unpackage/res/icons/120x120.png"},"prerendered":"false"}},"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>","<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>"],"packagename":"uni.UNI24DA8DD","aliasname":"platform","password":"aB6ADjKOYCOnZRmpzM7ptg==","keystore":"google-keystore.keystore","custompermissions":true},"apple":{"dSYMs":false,"plistcmds":["Add :UIFileSharingEnabled bool true"],"devices":"universal"},"plugins":{"ad":{},"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}},"debug":true,"syncDebug":true,"orientation":"portrait-primary"},"uniStatistics":{"enable":false},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"4.15","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html","adid":"123262070412"},"screenOrientation":["portrait-primary","portrait-secondary"]}
|
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__24DA8DD","name":"中鼎云医","version":{"name":"1.2.5","code":125},"description":"中鼎云医","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"VideoPlayer":{},"Record":{},"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"autoclose":true,"delay":0,"target":"id:1","waiting":true},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"usingComponents":true,"nvueStyleCompiler":"uni-app","compilerVersion":3,"distribute":{"screenOrientation":"landscape-primary","icons":{"android":{"hdpi":"icon-android-hdpi.png","xhdpi":"icon-android-xhdpi.png","xxhdpi":"icon-android-xxhdpi.png","xxxhdpi":"icon-android-xxxhdpi.png"},"ios":{"appstore":"unpackage/res/icons/1024x1024.png","ipad":{"app":"unpackage/res/icons/76x76.png","app@2x":"unpackage/res/icons/152x152.png","notification":"unpackage/res/icons/20x20.png","notification@2x":"unpackage/res/icons/40x40.png","proapp@2x":"unpackage/res/icons/167x167.png","settings":"unpackage/res/icons/29x29.png","settings@2x":"unpackage/res/icons/58x58.png","spotlight":"unpackage/res/icons/40x40.png","spotlight@2x":"unpackage/res/icons/80x80.png"},"iphone":{"app@2x":"unpackage/res/icons/120x120.png","app@3x":"unpackage/res/icons/180x180.png","notification@2x":"unpackage/res/icons/40x40.png","notification@3x":"unpackage/res/icons/60x60.png","settings@2x":"unpackage/res/icons/58x58.png","settings@3x":"unpackage/res/icons/87x87.png","spotlight@2x":"unpackage/res/icons/80x80.png","spotlight@3x":"unpackage/res/icons/120x120.png"},"prerendered":"false"}},"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>","<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>"],"packagename":"uni.UNI24DA8DD","aliasname":"platform","password":"aB6ADjKOYCOnZRmpzM7ptg==","keystore":"google-keystore.keystore","custompermissions":true},"apple":{"dSYMs":false,"devices":"universal"},"plugins":{"ad":{},"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}},"orientation":"portrait-primary"},"uniStatistics":{"enable":false},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"4.15","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html","adid":"123262070412"},"screenOrientation":["portrait-primary","portrait-secondary"]}
|
||||||
|
|
@ -277,13 +277,9 @@
|
||||||
// 重置倒计时
|
// 重置倒计时
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
||||||
console.log(text)
|
|
||||||
|
|
||||||
gaptime = setInterval(() => {
|
gaptime = setInterval(() => {
|
||||||
console.log(seconds, '倒计时')
|
|
||||||
seconds--;
|
seconds--;
|
||||||
if (voiceTxt.innerText) {
|
if (voiceTxt.innerText) {
|
||||||
console.log('有 text 参数'); // 如果有 text 参数,打印 1
|
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
gaptime = null;
|
gaptime = null;
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
@ -293,7 +289,6 @@
|
||||||
if (!isCallbackExecuted) {
|
if (!isCallbackExecuted) {
|
||||||
clearTimeout(times);
|
clearTimeout(times);
|
||||||
times = setTimeout(() => {
|
times = setTimeout(() => {
|
||||||
this.stop();
|
|
||||||
statusTxt.value = '正在听…';
|
statusTxt.value = '正在听…';
|
||||||
|
|
||||||
const params = { msg: text };
|
const params = { msg: text };
|
||||||
|
|
@ -473,9 +468,6 @@
|
||||||
} else if (seconds == 0){
|
} else if (seconds == 0){
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
closeShibie();
|
closeShibie();
|
||||||
|
|
||||||
// 重置
|
|
||||||
location.reload();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
@ -528,7 +520,6 @@
|
||||||
|
|
||||||
// 先静音即可处理解决(提前做交互)
|
// 先静音即可处理解决(提前做交互)
|
||||||
audioElement.muted = false;
|
audioElement.muted = false;
|
||||||
|
|
||||||
audioElement.currentTime = 0;
|
audioElement.currentTime = 0;
|
||||||
audioElement.pause();
|
audioElement.pause();
|
||||||
|
|
||||||
|
|
@ -657,37 +648,15 @@
|
||||||
// 监听播放技术
|
// 监听播放技术
|
||||||
myAudio.addEventListener('ended', function() {
|
myAudio.addEventListener('ended', function() {
|
||||||
console.log('音频播放已结束!');
|
console.log('音频播放已结束!');
|
||||||
// 停止倒计时
|
|
||||||
startRec.style.display = 'block';
|
|
||||||
endRec.style.display = 'none';
|
|
||||||
stopRec.style.display = 'none';
|
|
||||||
statusTxt.value = '';
|
|
||||||
voiceTxt.innerText = '';
|
|
||||||
replayVideoSegment(0, 60);
|
|
||||||
hideModal()
|
|
||||||
|
|
||||||
// 播放结束重新开始监听
|
// 播放结束重新开始监听
|
||||||
|
replayVideoSegment(0, 60);
|
||||||
|
voice.stop();
|
||||||
startShibie();
|
startShibie();
|
||||||
});
|
});
|
||||||
|
|
||||||
Subtitles = "";
|
Subtitles = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防抖
|
|
||||||
function throttle(fn, wait) {
|
|
||||||
let lastTime = 0; // 上一次调用的时间
|
|
||||||
|
|
||||||
return function (...args) {
|
|
||||||
const now = Date.now(); // 当前时间
|
|
||||||
|
|
||||||
// 如果距离上次调用已经超过设定时间,则调用函数
|
|
||||||
if (now - lastTime > wait) {
|
|
||||||
lastTime = now; // 更新上一次调用的时间
|
|
||||||
fn.apply(this, args); // 以正确的`this`和参数调用函数
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拿到的数据移除*
|
// 拿到的数据移除*
|
||||||
function filterString(str, charsToRemove) {
|
function filterString(str, charsToRemove) {
|
||||||
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@
|
||||||
};
|
};
|
||||||
// 连接WebSocket
|
// 连接WebSocket
|
||||||
connectWebSocket() {
|
connectWebSocket() {
|
||||||
|
console.log('连接WebSocket')
|
||||||
return this.getWebSocketUrl().then(url => {
|
return this.getWebSocketUrl().then(url => {
|
||||||
let iatWS;
|
let iatWS;
|
||||||
if ('WebSocket' in window) {
|
if ('WebSocket' in window) {
|
||||||
|
|
@ -122,8 +123,11 @@
|
||||||
}
|
}
|
||||||
this.webSocket = iatWS;
|
this.webSocket = iatWS;
|
||||||
this.setStatus('init');
|
this.setStatus('init');
|
||||||
|
|
||||||
iatWS.onopen = e => {
|
iatWS.onopen = e => {
|
||||||
this.setStatus('ing');
|
this.setStatus('ing');
|
||||||
|
console.log('ws开启重新开始录音');
|
||||||
|
|
||||||
// 重新开始录音
|
// 重新开始录音
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.webSocketSend();
|
this.webSocketSend();
|
||||||
|
|
@ -140,6 +144,18 @@
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 防抖函数
|
||||||
|
debounce(func, wait) {
|
||||||
|
let timeout;
|
||||||
|
return function(...args) {
|
||||||
|
const context = this;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => func.apply(context, args), wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化浏览器录音
|
// 初始化浏览器录音
|
||||||
recorderInit() {
|
recorderInit() {
|
||||||
// 创建音频环境
|
// 创建音频环境
|
||||||
|
|
@ -216,9 +232,10 @@
|
||||||
};
|
};
|
||||||
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
||||||
webSocketSend() {
|
webSocketSend() {
|
||||||
|
console.log('发送数据')
|
||||||
if (this.webSocket.readyState !== 1) return false;
|
if (this.webSocket.readyState !== 1) return false;
|
||||||
// 音频数据
|
// 音频数据
|
||||||
const audioData = this.audioData.splice(0, 1280);
|
let audioData = this.audioData.splice(0, 1280);
|
||||||
const params = {
|
const params = {
|
||||||
common: {
|
common: {
|
||||||
app_id: this.appId,
|
app_id: this.appId,
|
||||||
|
|
@ -237,14 +254,17 @@
|
||||||
audio: this.toBase64(audioData)
|
audio: this.toBase64(audioData)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
console.log(params, 'socket数据');
|
||||||
|
|
||||||
// 发送数据
|
// 发送数据
|
||||||
this.webSocket.send(JSON.stringify(params));
|
this.webSocket.send(JSON.stringify(params));
|
||||||
|
|
||||||
this.handlerInterval = setInterval(() => {
|
this.handlerInterval = setInterval(() => {
|
||||||
// websocket未连接
|
// websocket未连接
|
||||||
if (this.webSocket.readyState !== 1) {
|
if (this.webSocket.readyState !== 1) {
|
||||||
this.audioData = [];
|
this.audioData = [];
|
||||||
clearInterval(this.handlerInterval);
|
clearInterval(this.handlerInterval);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if (this.audioData.length === 0) {
|
if (this.audioData.length === 0) {
|
||||||
if (this.status === 'end') {
|
if (this.status === 'end') {
|
||||||
|
|
@ -312,9 +332,10 @@
|
||||||
this.webSocket.close();
|
this.webSocket.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 启动录音
|
// 启动录音
|
||||||
recorderStart() {
|
recorderStart() {
|
||||||
if (!this.audioContext) {
|
if (!this.audioContext) {
|
||||||
this.recorderInit();
|
this.recorderInit();
|
||||||
} else {
|
} else {
|
||||||
this.audioContext.resume();
|
this.audioContext.resume();
|
||||||
|
|
@ -340,8 +361,10 @@
|
||||||
this.setResultText({ resultText: '', resultTextTemp: '' });
|
this.setResultText({ resultText: '', resultTextTemp: '' });
|
||||||
};
|
};
|
||||||
// 停止
|
// 停止
|
||||||
stop() {
|
stop() {
|
||||||
|
console.log('停了停了停了停了停了停了停了停了停了停了');
|
||||||
this.recorderStop();
|
this.recorderStop();
|
||||||
|
this.webSocket.close();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
@ -277,13 +277,9 @@
|
||||||
// 重置倒计时
|
// 重置倒计时
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
||||||
console.log(text)
|
|
||||||
|
|
||||||
gaptime = setInterval(() => {
|
gaptime = setInterval(() => {
|
||||||
console.log(seconds, '倒计时')
|
|
||||||
seconds--;
|
seconds--;
|
||||||
if (voiceTxt.innerText) {
|
if (voiceTxt.innerText) {
|
||||||
console.log('有 text 参数'); // 如果有 text 参数,打印 1
|
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
gaptime = null;
|
gaptime = null;
|
||||||
seconds = 10;
|
seconds = 10;
|
||||||
|
|
@ -293,7 +289,6 @@
|
||||||
if (!isCallbackExecuted) {
|
if (!isCallbackExecuted) {
|
||||||
clearTimeout(times);
|
clearTimeout(times);
|
||||||
times = setTimeout(() => {
|
times = setTimeout(() => {
|
||||||
this.stop();
|
|
||||||
statusTxt.value = '正在听…';
|
statusTxt.value = '正在听…';
|
||||||
|
|
||||||
const params = { msg: text };
|
const params = { msg: text };
|
||||||
|
|
@ -473,9 +468,6 @@
|
||||||
} else if (seconds == 0){
|
} else if (seconds == 0){
|
||||||
clearInterval(gaptime);
|
clearInterval(gaptime);
|
||||||
closeShibie();
|
closeShibie();
|
||||||
|
|
||||||
// 重置
|
|
||||||
location.reload();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
@ -528,7 +520,6 @@
|
||||||
|
|
||||||
// 先静音即可处理解决(提前做交互)
|
// 先静音即可处理解决(提前做交互)
|
||||||
audioElement.muted = false;
|
audioElement.muted = false;
|
||||||
|
|
||||||
audioElement.currentTime = 0;
|
audioElement.currentTime = 0;
|
||||||
audioElement.pause();
|
audioElement.pause();
|
||||||
|
|
||||||
|
|
@ -657,37 +648,15 @@
|
||||||
// 监听播放技术
|
// 监听播放技术
|
||||||
myAudio.addEventListener('ended', function() {
|
myAudio.addEventListener('ended', function() {
|
||||||
console.log('音频播放已结束!');
|
console.log('音频播放已结束!');
|
||||||
// 停止倒计时
|
|
||||||
startRec.style.display = 'block';
|
|
||||||
endRec.style.display = 'none';
|
|
||||||
stopRec.style.display = 'none';
|
|
||||||
statusTxt.value = '';
|
|
||||||
voiceTxt.innerText = '';
|
|
||||||
replayVideoSegment(0, 60);
|
|
||||||
hideModal()
|
|
||||||
|
|
||||||
// 播放结束重新开始监听
|
// 播放结束重新开始监听
|
||||||
|
replayVideoSegment(0, 60);
|
||||||
|
voice.stop();
|
||||||
startShibie();
|
startShibie();
|
||||||
});
|
});
|
||||||
|
|
||||||
Subtitles = "";
|
Subtitles = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防抖
|
|
||||||
function throttle(fn, wait) {
|
|
||||||
let lastTime = 0; // 上一次调用的时间
|
|
||||||
|
|
||||||
return function (...args) {
|
|
||||||
const now = Date.now(); // 当前时间
|
|
||||||
|
|
||||||
// 如果距离上次调用已经超过设定时间,则调用函数
|
|
||||||
if (now - lastTime > wait) {
|
|
||||||
lastTime = now; // 更新上一次调用的时间
|
|
||||||
fn.apply(this, args); // 以正确的`this`和参数调用函数
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拿到的数据移除*
|
// 拿到的数据移除*
|
||||||
function filterString(str, charsToRemove) {
|
function filterString(str, charsToRemove) {
|
||||||
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类(character class)来构建的
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@
|
||||||
};
|
};
|
||||||
// 连接WebSocket
|
// 连接WebSocket
|
||||||
connectWebSocket() {
|
connectWebSocket() {
|
||||||
|
console.log('连接WebSocket')
|
||||||
return this.getWebSocketUrl().then(url => {
|
return this.getWebSocketUrl().then(url => {
|
||||||
let iatWS;
|
let iatWS;
|
||||||
if ('WebSocket' in window) {
|
if ('WebSocket' in window) {
|
||||||
|
|
@ -122,8 +123,11 @@
|
||||||
}
|
}
|
||||||
this.webSocket = iatWS;
|
this.webSocket = iatWS;
|
||||||
this.setStatus('init');
|
this.setStatus('init');
|
||||||
|
|
||||||
iatWS.onopen = e => {
|
iatWS.onopen = e => {
|
||||||
this.setStatus('ing');
|
this.setStatus('ing');
|
||||||
|
console.log('ws开启重新开始录音');
|
||||||
|
|
||||||
// 重新开始录音
|
// 重新开始录音
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.webSocketSend();
|
this.webSocketSend();
|
||||||
|
|
@ -140,6 +144,18 @@
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 防抖函数
|
||||||
|
debounce(func, wait) {
|
||||||
|
let timeout;
|
||||||
|
return function(...args) {
|
||||||
|
const context = this;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => func.apply(context, args), wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化浏览器录音
|
// 初始化浏览器录音
|
||||||
recorderInit() {
|
recorderInit() {
|
||||||
// 创建音频环境
|
// 创建音频环境
|
||||||
|
|
@ -216,9 +232,10 @@
|
||||||
};
|
};
|
||||||
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
// 向webSocket发送数据(音频二进制数据经过Base64处理)
|
||||||
webSocketSend() {
|
webSocketSend() {
|
||||||
|
console.log('发送数据')
|
||||||
if (this.webSocket.readyState !== 1) return false;
|
if (this.webSocket.readyState !== 1) return false;
|
||||||
// 音频数据
|
// 音频数据
|
||||||
const audioData = this.audioData.splice(0, 1280);
|
let audioData = this.audioData.splice(0, 1280);
|
||||||
const params = {
|
const params = {
|
||||||
common: {
|
common: {
|
||||||
app_id: this.appId,
|
app_id: this.appId,
|
||||||
|
|
@ -237,14 +254,17 @@
|
||||||
audio: this.toBase64(audioData)
|
audio: this.toBase64(audioData)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
console.log(params, 'socket数据');
|
||||||
|
|
||||||
// 发送数据
|
// 发送数据
|
||||||
this.webSocket.send(JSON.stringify(params));
|
this.webSocket.send(JSON.stringify(params));
|
||||||
|
|
||||||
this.handlerInterval = setInterval(() => {
|
this.handlerInterval = setInterval(() => {
|
||||||
// websocket未连接
|
// websocket未连接
|
||||||
if (this.webSocket.readyState !== 1) {
|
if (this.webSocket.readyState !== 1) {
|
||||||
this.audioData = [];
|
this.audioData = [];
|
||||||
clearInterval(this.handlerInterval);
|
clearInterval(this.handlerInterval);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if (this.audioData.length === 0) {
|
if (this.audioData.length === 0) {
|
||||||
if (this.status === 'end') {
|
if (this.status === 'end') {
|
||||||
|
|
@ -312,9 +332,10 @@
|
||||||
this.webSocket.close();
|
this.webSocket.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 启动录音
|
// 启动录音
|
||||||
recorderStart() {
|
recorderStart() {
|
||||||
if (!this.audioContext) {
|
if (!this.audioContext) {
|
||||||
this.recorderInit();
|
this.recorderInit();
|
||||||
} else {
|
} else {
|
||||||
this.audioContext.resume();
|
this.audioContext.resume();
|
||||||
|
|
@ -340,8 +361,10 @@
|
||||||
this.setResultText({ resultText: '', resultTextTemp: '' });
|
this.setResultText({ resultText: '', resultTextTemp: '' });
|
||||||
};
|
};
|
||||||
// 停止
|
// 停止
|
||||||
stop() {
|
stop() {
|
||||||
|
console.log('停了停了停了停了停了停了停了停了停了停了');
|
||||||
this.recorderStop();
|
this.recorderStop();
|
||||||
|
this.webSocket.close();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue