JLBA202505130001_关于吉林银行新建AI智能培训系统的需求_修复安卓按钮bug1
This commit is contained in:
@@ -3,13 +3,10 @@ import { get_base_url } from '@/api/request.js';
|
||||
import { getPhoneEnvBool } from '@/common/common.js';
|
||||
const IsAndEnv = getPhoneEnvBool('AND')
|
||||
|
||||
// const url = '/trapractice/voiceCallSocket/voiceCall'
|
||||
// const url = '/traapp/voiceTransSocket/open';
|
||||
// const url = '/traapp/asrAiModelSocket/open';
|
||||
const url = '/traapp/asrAiModelSocket/open';
|
||||
const _baseUrl = get_base_url(url).split('http').join('ws');
|
||||
// export const wsUrl = _baseUrl + url ;
|
||||
export const wsUrl = 'ws://10.10.10.4:8000/ws/asr';
|
||||
export const wsUrl = _baseUrl + url;
|
||||
// export const wsUrl = 'ws://10.10.10.4:8000/ws/asr';
|
||||
const windowInfo = uni.getWindowInfo();
|
||||
// 安全区域信息
|
||||
const safeArea = windowInfo.safeArea;
|
||||
@@ -44,7 +41,7 @@ export const initWebSocket = (wsUrl : string) : Promise<UniApp.SocketTask> => {
|
||||
const onOpenHandler = (res) => {
|
||||
resolve(ws);
|
||||
};
|
||||
|
||||
|
||||
// 4. 监听连接错误(出错时reject)
|
||||
const onErrorHandler = (err) => {
|
||||
console.log('WS连接错误', err, wsUrl);
|
||||
|
||||
@@ -214,6 +214,7 @@
|
||||
const tempText = ref('');
|
||||
const inputText = ref('');
|
||||
const ossKey = ref('');
|
||||
let voiceQueue = [];
|
||||
// 记录 按下移动位置
|
||||
const touchPos = reactive({ x: 0, y: 0 });
|
||||
// 是否录音中
|
||||
@@ -274,68 +275,7 @@
|
||||
tempText.value = '';
|
||||
allText.value = '';
|
||||
ossKey.value = '';
|
||||
console.log('开启语音');
|
||||
initWebSocket(wsUrl + '?summary=' + getToken())
|
||||
.then((socketTask) => {
|
||||
if (!isRecording.value) {
|
||||
ws.value = null;
|
||||
wsStatus.value = false;
|
||||
return;
|
||||
}
|
||||
ws.value = socketTask;
|
||||
wsStatus.value = true;
|
||||
console.log('WS连接成功', isRecording.value, );
|
||||
ws.value.onMessage((res: { data: Uint8Array | ArrayBuffer }) => {
|
||||
try {
|
||||
const { msgType, body } = ProtocolCodec.unpack(res.data);
|
||||
console.log('msgType', msgType, body);
|
||||
if (msgType === MessageType.TEXT_MESSAGE) {
|
||||
tempText.value = '';
|
||||
allText.value = allText.value + body;
|
||||
} else if (msgType === MessageType.TIP_MESSAGE) {
|
||||
tempText.value += body as string;
|
||||
} else if (msgType === MessageType.CONTROL_CMD) {
|
||||
// 返回结束消息
|
||||
const controlBody = body as ControlBody;
|
||||
if (controlBody.type === ControlCode.SERVER_TO_FRONT_OVER) {
|
||||
console.log('识别结束', controlBody, voice_to_text_status.value);
|
||||
// 如果不等于init说明已经超时,被超时函数处理完了,这里即使返回也不做处理
|
||||
if (status.value === 'voice_to_text' && voice_to_text_status.value !== 'init') return;
|
||||
if (status.value === 'send_over') return;
|
||||
// 时间太短,关掉的时候就处理了,这里不处理
|
||||
const recordDurationMs = Date.now() - recordStartTime.value;
|
||||
if (recordDurationMs <= props.minRecordDuration) return;
|
||||
closeWS()
|
||||
status.value = 'send_over'; // 设置成发送完成
|
||||
if (voiceTimer) clearTimeout(voiceTimer);
|
||||
// 设置识别结果
|
||||
voice_to_text_status.value = controlBody?.txt === '' ? 'failed' : 'success';
|
||||
// 取值出来
|
||||
ossKey.value = controlBody?.ossKey || '';
|
||||
if (typeof controlBody?.txt === 'string') {
|
||||
allText.value = controlBody.txt.trim();
|
||||
}
|
||||
const _isOutStatus =
|
||||
workMode.value === 'text-only' && isOutStatus.value === '01' ? '03' : isOutStatus.value;
|
||||
// 只有模式为01的时候才发送出去
|
||||
if (_isOutStatus === '01') {
|
||||
emit('submitVoice', {
|
||||
ossKey: ossKey.value,
|
||||
text: allText.value,
|
||||
recordId: recordId.value
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('后端发来的信息有问题', e, res.data);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
stopRecord('networkError');
|
||||
console.log('网络出现问题');
|
||||
});
|
||||
|
||||
pressTimer = setTimeout(() => {
|
||||
if (!isRecording.value) {
|
||||
console.log('定时器被取消还是进入了');
|
||||
@@ -352,18 +292,108 @@
|
||||
// 记录开始时间戳(毫秒)
|
||||
recordStartTime.value = Date.now();
|
||||
// 弹出录音界面
|
||||
startRecordingTimer(true) // 启动超长定时器
|
||||
startRecordingTimer(true); // 启动超长定时器
|
||||
startAudioRecord({
|
||||
onFrame: (pcmData: any) => {
|
||||
console.log('msgType', pcmData.length, !!(wsStatus.value && ws.value));
|
||||
if (wsStatus.value && ws.value) {
|
||||
ws.value.send({ data: ProtocolCodec.pack(MessageType.AUDIO_DATA, pcmData) });
|
||||
if (voiceQueue.length > 0) {
|
||||
voiceQueue.forEach((cachedData) => {
|
||||
ws.value.send({
|
||||
data: ProtocolCodec.pack(MessageType.AUDIO_DATA, cachedData)
|
||||
});
|
||||
});
|
||||
// 发送完成后清空队列
|
||||
voiceQueue = [];
|
||||
}
|
||||
// 再发送当前帧的音频数据
|
||||
ws.value.send({
|
||||
data: ProtocolCodec.pack(MessageType.AUDIO_DATA, pcmData)
|
||||
});
|
||||
} else {
|
||||
voiceQueue.push(pcmData)
|
||||
}
|
||||
},
|
||||
onStart: (res: any) => {
|
||||
console.log('启动', res);
|
||||
recordId.value = res.recordId ?? '';
|
||||
popupRef.value.open();
|
||||
console.log('开启语音');
|
||||
setTimeout(() => {
|
||||
initWebSocket(wsUrl + '?summary=' + getToken())
|
||||
.then((socketTask) => {
|
||||
if (!isRecording.value) {
|
||||
ws.value = null;
|
||||
wsStatus.value = false;
|
||||
return;
|
||||
}
|
||||
ws.value = socketTask;
|
||||
wsStatus.value = true;
|
||||
console.log('WS连接成功', isRecording.value);
|
||||
ws.value.onMessage((res: { data: Uint8Array | ArrayBuffer }) => {
|
||||
try {
|
||||
const { msgType, body } = ProtocolCodec.unpack(res.data);
|
||||
console.log('msgType', msgType, body);
|
||||
if (msgType === MessageType.TEXT_MESSAGE) {
|
||||
tempText.value = '';
|
||||
allText.value = allText.value + body;
|
||||
} else if (msgType === MessageType.TIP_MESSAGE) {
|
||||
tempText.value += body as string;
|
||||
} else if (msgType === MessageType.CONTROL_CMD) {
|
||||
// 返回结束消息
|
||||
const controlBody = body as ControlBody;
|
||||
if (controlBody.type === ControlCode.SERVER_TO_FRONT_OVER) {
|
||||
console.log(
|
||||
'识别结束',
|
||||
controlBody,
|
||||
voice_to_text_status.value,
|
||||
status.value,
|
||||
voice_to_text_status.value
|
||||
);
|
||||
// 如果不等于init说明已经超时,被超时函数处理完了,这里即使返回也不做处理
|
||||
if (
|
||||
status.value === 'voice_to_text' &&
|
||||
voice_to_text_status.value !== 'init'
|
||||
)
|
||||
return;
|
||||
if (status.value === 'send_over') return;
|
||||
// 时间太短,关掉的时候就处理了,这里不处理
|
||||
const recordDurationMs = Date.now() - recordStartTime.value;
|
||||
if (recordDurationMs <= props.minRecordDuration) return;
|
||||
closeWS();
|
||||
status.value = 'send_over'; // 设置成发送完成
|
||||
if (voiceTimer) clearTimeout(voiceTimer);
|
||||
// 设置识别结果
|
||||
voice_to_text_status.value = controlBody?.txt === '' ? 'failed' : 'success';
|
||||
// 取值出来
|
||||
ossKey.value = controlBody?.ossKey || '';
|
||||
if (typeof controlBody?.txt === 'string') {
|
||||
allText.value = controlBody.txt.trim();
|
||||
}
|
||||
const _isOutStatus =
|
||||
workMode.value === 'text-only' && isOutStatus.value === '01'
|
||||
? '03'
|
||||
: isOutStatus.value;
|
||||
// 只有模式为01的时候才发送出去
|
||||
console.log('只有模式为01的时候才发送出去', controlBody);
|
||||
if (_isOutStatus === '01') {
|
||||
emit('submitVoice', {
|
||||
ossKey: ossKey.value,
|
||||
text: allText.value,
|
||||
recordId: recordId.value
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('后端发来的信息有问题', e, res.data);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
stopRecord('networkError');
|
||||
console.log('网络出现问题');
|
||||
});
|
||||
}, 200);
|
||||
},
|
||||
onStop: () => {
|
||||
console.log('关闭');
|
||||
@@ -380,7 +410,7 @@
|
||||
|
||||
// 结束录音
|
||||
const closePopup = () => {
|
||||
startRecordingTimer(false)
|
||||
startRecordingTimer(false);
|
||||
isRecording.value = false;
|
||||
popupRef.value.close();
|
||||
};
|
||||
@@ -393,6 +423,7 @@
|
||||
complete: () => {
|
||||
console.log('挂断Ws');
|
||||
wsStatus.value = false;
|
||||
ws.value = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -406,7 +437,7 @@
|
||||
pressTimer = null;
|
||||
isRecording.value = false;
|
||||
setTimeout(() => {
|
||||
status.value = 'default'
|
||||
status.value = 'default';
|
||||
}, 50);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user