Merge branch 'dev-recording' of http://25.13.9.101:9000/K17_AITS/tra-app into dev-recording
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.8: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 });
|
||||
// 是否录音中
|
||||
@@ -260,7 +261,7 @@
|
||||
const state = await permissionApi.judgeIosPermission('record');
|
||||
if (state === 'not determined') {
|
||||
// 苹果专用
|
||||
preRequestRecordPermission(() => {});
|
||||
preRequestRecordPermission();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -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;
|
||||
|
||||
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,17 +292,108 @@
|
||||
// 记录开始时间戳(毫秒)
|
||||
recordStartTime.value = Date.now();
|
||||
// 弹出录音界面
|
||||
startRecordingTimer(true) // 启动超长定时器
|
||||
startRecordingTimer(true); // 启动超长定时器
|
||||
startAudioRecord({
|
||||
onFrame: (pcmData: any) => {
|
||||
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('关闭');
|
||||
@@ -379,7 +410,7 @@
|
||||
|
||||
// 结束录音
|
||||
const closePopup = () => {
|
||||
startRecordingTimer(false)
|
||||
startRecordingTimer(false);
|
||||
isRecording.value = false;
|
||||
popupRef.value.close();
|
||||
};
|
||||
@@ -392,6 +423,7 @@
|
||||
complete: () => {
|
||||
console.log('挂断Ws');
|
||||
wsStatus.value = false;
|
||||
ws.value = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -405,7 +437,7 @@
|
||||
pressTimer = null;
|
||||
isRecording.value = false;
|
||||
setTimeout(() => {
|
||||
status.value = 'default'
|
||||
status.value = 'default';
|
||||
}, 50);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// components/touch-btn/touch-btn.images.ts
|
||||
// 统一导出所有需要的图片资源
|
||||
export { default as cancelBtn } from '@/static/images/course/cancel.png';
|
||||
export { default as cancelActiveBtn } from '@/static/images/course/cancel-active.png';
|
||||
export { default as translateBtn } from '@/static/images/course/translate.png';
|
||||
export { default as translateActiveBtn } from '@/static/images/course/translate-active.png';
|
||||
@@ -1,15 +0,0 @@
|
||||
import { get_base_url } from '@/api/request.js';
|
||||
// const url = '/trapractice/voiceCallSocket/voiceCall'
|
||||
// const url = '/traapp/voiceTransSocket/open';
|
||||
const url = '/traapp/voiceAiModelSocket/open';
|
||||
const _baseUrl = get_base_url(url).split('http').join('ws');
|
||||
export const wsUrl = _baseUrl + url;
|
||||
const windowInfo = uni.getWindowInfo();
|
||||
// 安全区域信息
|
||||
const safeArea = windowInfo.safeArea;
|
||||
// 按钮高度
|
||||
const btnHeight = (windowInfo.screenWidth / 750) * 234;
|
||||
// 按钮的顶部边界
|
||||
export const bottomAreaTopBoundary = safeArea.bottom - btnHeight;
|
||||
// 屏幕横向分割线
|
||||
export const horizontalSplitX = safeArea.right / 2;
|
||||
@@ -1 +0,0 @@
|
||||
export type StatusType = 'voice' | 'input' | 'text';
|
||||
@@ -1,541 +0,0 @@
|
||||
<template>
|
||||
<view class="talk-btns">
|
||||
<view class="touch-btn" @click="disabled_click">
|
||||
<!-- @touchend="stopRecord(false)" -->
|
||||
<uv-button
|
||||
class="touch-btn"
|
||||
@touchstart="startRecord"
|
||||
@touchmove="handleMove"
|
||||
@touchend="loosenButton"
|
||||
v-if="!keyboardIsShow"
|
||||
:throttleTime="0"
|
||||
:hoverStartTime="0"
|
||||
:hoverStayTime="100"
|
||||
:customStyle="{ height: '92rpx' }"
|
||||
>
|
||||
{{buttonText}}
|
||||
</uv-button>
|
||||
<uv-input
|
||||
v-if="keyboardIsShow"
|
||||
class="input-box"
|
||||
ref="inputRef"
|
||||
v-model="inputText"
|
||||
:maxlength="props.textValueLength"
|
||||
:adjustPosition="true"
|
||||
placeholderStyle="color:#999999;font-size:26rpx"
|
||||
placeholder="请输入文字"
|
||||
:disabled="props.isDisabled"
|
||||
></uv-input>
|
||||
</view>
|
||||
|
||||
<view class="talk-btn-box">
|
||||
<image
|
||||
class="talk-btn-icon"
|
||||
v-show="!keyboardIsShow"
|
||||
src="@/static/images/course/jianpan.png"
|
||||
mode=""
|
||||
@click="changeBtn"
|
||||
></image>
|
||||
<image
|
||||
class="talk-btn-icon"
|
||||
v-show="keyboardIsShow && !inputText"
|
||||
src="@/static/images/course/record.png"
|
||||
mode=""
|
||||
@click="changeBtn"
|
||||
></image>
|
||||
<image
|
||||
class="talk-btn-icon"
|
||||
v-show="keyboardIsShow && !!inputText"
|
||||
src="@/static/images/course/send.png"
|
||||
mode=""
|
||||
@click.stop="showKeyboard"
|
||||
></image>
|
||||
</view>
|
||||
<uv-overlay ref="popupRef" class="popup" :show="show" :duration="400" >
|
||||
<view class="overlay-box">
|
||||
<view class="circle-bg-box">
|
||||
<view class="tips-box">松开发送</view>
|
||||
</view>
|
||||
<!-- 取消按钮 -->
|
||||
<view class="btns-box">
|
||||
<image
|
||||
class="btn-box btn-box-1"
|
||||
:src="isOutStatus == '02' ? cancelActiveBtn : cancelBtn"
|
||||
mode="heightFix"
|
||||
@click="closePopup()"
|
||||
></image>
|
||||
<image
|
||||
class="btn-box btn-box-2"
|
||||
:src="isOutStatus == '03' ? translateActiveBtn : translateBtn"
|
||||
mode="heightFix"
|
||||
></image>
|
||||
</view>
|
||||
<view class="talk-dialog" :class="{ 'is-out': isOutStatus === '02', 'is-translate': isOutStatus === '03' }">
|
||||
<image src="@/static/images/course/voice-white.gif" mode="" class="gif-box"></image>
|
||||
<uv-textarea
|
||||
ref="inputRef"
|
||||
v-model="allText"
|
||||
:maxlength="255"
|
||||
@click.stop
|
||||
customStyle="background: #ffffff00; padding-bottom: 50rpx; color: #fff; caret-color: #fff"
|
||||
text-style="color: #fff"
|
||||
border="none"
|
||||
placeholderStyle="color:#999999;font-size:26rpx;"
|
||||
placeholder=""
|
||||
></uv-textarea>
|
||||
<!-- <view class="text-div" v-if="isOutStatus === '03'">
|
||||
{{ allText }}{{ tempText }}
|
||||
</view> -->
|
||||
</view>
|
||||
<view class="fl1"></view>
|
||||
</view>
|
||||
</uv-overlay>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 导出图片
|
||||
import { cancelBtn, cancelActiveBtn, translateBtn, translateActiveBtn } from './touch-btn.images';
|
||||
import { StatusType } from './touch-btn.types';
|
||||
import { wsUrl, bottomAreaTopBoundary, horizontalSplitX } from './touch-btn';
|
||||
import { ref, computed, onMounted, nextTick, watch, reactive } from 'vue';
|
||||
import common from '@/common/common';
|
||||
import { onHide, onLaunch } from '@dcloudio/uni-app';
|
||||
import { getPhoneEnvBool, getToken } from '@/common/common.js';
|
||||
import { startAudioRecord, stopAudioRecord,preRequestRecordPermission } from '@/uni_modules/ty-recording';
|
||||
import { ProtocolCodec, MessageType, ControlCommand, ControlCode } from '@/pages/sparring/js/ProtocolCodec';
|
||||
import permissionApi from '@/common/permission';
|
||||
const buttonText = computed(() => show.value?'松手发送':'按住说话');
|
||||
const show = ref(false)
|
||||
const emit = defineEmits(['submit']);
|
||||
const ws = ref(null);
|
||||
const status = ref<StatusType>('voice');
|
||||
const props = defineProps({
|
||||
isDisabled: {
|
||||
default: false,
|
||||
type: Boolean
|
||||
},
|
||||
isLoading: {
|
||||
default: false,
|
||||
type: Boolean
|
||||
},
|
||||
loadingText: {
|
||||
default: '发送回答中,请稍后再试!',
|
||||
type: String
|
||||
},
|
||||
disabledText: {
|
||||
default: '请稍后再试!',
|
||||
type: String
|
||||
},
|
||||
canAnswer: {
|
||||
default: true,
|
||||
type: Boolean
|
||||
},
|
||||
canAnswerText: {
|
||||
default: '当前状态不能发送内容!',
|
||||
type: String
|
||||
},
|
||||
textValueLength: {
|
||||
type: Number,
|
||||
default: 500
|
||||
},
|
||||
minRecordDuration: {
|
||||
// 最小录音间隔
|
||||
type: Number,
|
||||
default: 1000
|
||||
}
|
||||
});
|
||||
// 记录 按下移动位置
|
||||
const touchPos = reactive({ x: 0, y: 0 });
|
||||
|
||||
// 计算是否超出按下盒子位置01代表下方盒子,02代表左上03代表右上
|
||||
const isOutStatus = computed(() => {
|
||||
const { y: touchY, x: touchX } = touchPos;
|
||||
if (touchY >= bottomAreaTopBoundary) return '01';
|
||||
return touchX < horizontalSplitX ? '02' : '03';
|
||||
});
|
||||
// 监听按下移动
|
||||
const handleMove = (obj) => {
|
||||
const { pageX, pageY } = obj.changedTouches[0];
|
||||
touchPos.x = pageX;
|
||||
touchPos.y = pageY;
|
||||
};
|
||||
const allText = ref('');
|
||||
const tempText = ref('');
|
||||
|
||||
// 键盘还是语音
|
||||
const keyboardIsShow = ref(false);
|
||||
const popupRef = ref(null);
|
||||
const inputText = ref('');
|
||||
let startTime = 0;
|
||||
// 开启语音
|
||||
const startRecord = async (obj: { touches: any[]; }) => {
|
||||
|
||||
// popupRef.value.open();
|
||||
console.log('打开');
|
||||
show.value = true
|
||||
return
|
||||
try {
|
||||
const state = await permissionApi.judgeIosPermission('record');
|
||||
if(state === 'not determined') { // 苹果专用
|
||||
preRequestRecordPermission(() => {})
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('麦克风权限申请失败:', e);
|
||||
return;
|
||||
}
|
||||
const changedTouche = obj.touches[0];
|
||||
touchPos.x = changedTouche.clientX;
|
||||
touchPos.y = changedTouche.clientY;
|
||||
popupRef.value.open();
|
||||
startAudioRecord({
|
||||
onFrame: (pcmData: any) => {
|
||||
// console.log('pcmData', pcmData.length);
|
||||
// ws.value.send({
|
||||
// data: ProtocolCodec.pack(MessageType.AUDIO_DATA, pcmData)
|
||||
// });
|
||||
},
|
||||
onStart: (res: any) => {
|
||||
console.log('启动', res);
|
||||
|
||||
},
|
||||
onStop: () => {
|
||||
console.log('关闭');
|
||||
},
|
||||
onError: ({ errCode, errMsg }) => {
|
||||
console.log('onError',errMsg);
|
||||
if (errCode === 9010001) {
|
||||
console.log(errMsg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// ws.value = uni.connectSocket({
|
||||
// url: wsUrl + '?summary=' + getToken(),
|
||||
// fail: () => {},
|
||||
// success: () => {}
|
||||
// });
|
||||
// ws.value.onOpen((res) => {
|
||||
// console.log('ws已连接');
|
||||
// popupRef.value.open();
|
||||
|
||||
// });
|
||||
// ws.value.onError((err) => {
|
||||
// console.log('err', err);
|
||||
// });
|
||||
// ws.value.onClose((err) => {
|
||||
// console.log('onClose', err);
|
||||
// });
|
||||
// ws.value.onMessage((res) => {
|
||||
// try {
|
||||
// const { msgType, body } = ProtocolCodec.unpack(res.data);
|
||||
// console.log('来消息了', msgType, body);
|
||||
// if (msgType === MessageType.TEXT_MESSAGE) {
|
||||
// tempText.value = '';
|
||||
// allText.value = allText.value + body;
|
||||
// } else if (msgType === MessageType.TIP_MESSAGE) {
|
||||
// // tempText.value = body;
|
||||
// }
|
||||
// } catch (e) {
|
||||
// console.log('后端发来的信息有问题');
|
||||
// }
|
||||
// });
|
||||
};
|
||||
// 关掉遮罩层
|
||||
const closePopup = () => {
|
||||
show.value = false
|
||||
return
|
||||
nextTick(() => {
|
||||
allText.value = '';
|
||||
tempText.value = '';
|
||||
popupRef.value.close();
|
||||
});
|
||||
ws.value &&
|
||||
ws.value.close({
|
||||
code: 1000,
|
||||
reason: '挂断',
|
||||
success: () => {
|
||||
console.log('挂断success');
|
||||
},
|
||||
fail: () => {
|
||||
console.log('挂断fail');
|
||||
},
|
||||
complete: () => {
|
||||
console.log('挂断complete');
|
||||
}
|
||||
});
|
||||
};
|
||||
// 松开按钮
|
||||
const loosenButton = () => {
|
||||
// popupRef.value.close();
|
||||
show.value = false
|
||||
return
|
||||
// 判断一下位置,03的时候是转文字不能关闭
|
||||
if (isOutStatus.value === '03') {
|
||||
// 03转文字
|
||||
console.log('已发送', '03转文字');
|
||||
ws.value.send({
|
||||
data: ProtocolCodec.pack(MessageType.CONTROL_CMD, { type: ControlCode.FRNOT_TO_SERVER_OVER })
|
||||
});
|
||||
} else {
|
||||
closePopup();
|
||||
}
|
||||
stopRecord();
|
||||
};
|
||||
// 结束录音
|
||||
const stopRecord = (status = false) => {
|
||||
console.log('结束录音stopRecord', status);
|
||||
// 判断一下位置
|
||||
if (isOutStatus.value === '01') {
|
||||
// 01发送
|
||||
} else if (isOutStatus.value === '02') {
|
||||
// 02取消
|
||||
} else if (isOutStatus.value === '03') {
|
||||
// 03转文字
|
||||
}
|
||||
|
||||
stopAudioRecord();
|
||||
};
|
||||
|
||||
onMounted(async () => {});
|
||||
onHide(() => {
|
||||
// closePopup();
|
||||
console.log('onHide');
|
||||
});
|
||||
const activeNum = ref(1);
|
||||
|
||||
const clearinputText = (text = '') => {
|
||||
const old_text = inputText.value;
|
||||
inputText.value = text;
|
||||
return old_text;
|
||||
};
|
||||
|
||||
// 发送文本
|
||||
const showKeyboard = () => {
|
||||
if (keyboardIsShow.value) {
|
||||
const inputTextTram = inputText.value.trim();
|
||||
if (inputTextTram) {
|
||||
emit('submit', 'text', inputTextTram);
|
||||
} else {
|
||||
common.msg('不能发送空白消息!');
|
||||
}
|
||||
} else {
|
||||
keyboardIsShow.value = !keyboardIsShow.value;
|
||||
}
|
||||
};
|
||||
// 切换键盘语音
|
||||
const changeBtn = () => {
|
||||
if (props.isDisabled) return;
|
||||
keyboardIsShow.value = !keyboardIsShow.value;
|
||||
inputText.value = '';
|
||||
};
|
||||
// 禁用时点击给的提示
|
||||
const disabled_click = () => {
|
||||
console.log('禁用时点击给的提示');
|
||||
if (props.isDisabled) common.msg(props.disabledText);
|
||||
};
|
||||
|
||||
// 外面调用放弃这次
|
||||
const give_up = () => {
|
||||
console.log('调用结束语音回答');
|
||||
stopRecord(false);
|
||||
};
|
||||
defineExpose({ clearinputText, give_up });
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.talk-btns {
|
||||
height: 150rpx;
|
||||
background-color: #fff;
|
||||
padding: 25rpx 30rpx 0;
|
||||
position: relative;
|
||||
|
||||
.touch-btn {
|
||||
height: 92rpx;
|
||||
box-shadow: 0 8rpx 20rpx 0 rgba(0, 0, 0, 0.06);
|
||||
text-align: center;
|
||||
line-height: 92rpx;
|
||||
color: #000;
|
||||
font-weight: 400;
|
||||
position: relative;
|
||||
|
||||
.input-box {
|
||||
width: 100%;
|
||||
height: 92rpx;
|
||||
line-height: 92rpx;
|
||||
text-align: left;
|
||||
box-sizing: border-box;
|
||||
padding: 0 40rpx 0 40rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.talk-btn-box {
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
width: 120rpx;
|
||||
right: 0;
|
||||
top: 0;
|
||||
|
||||
.talk-btn-icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
position: absolute;
|
||||
right: 60rpx;
|
||||
top: 50%;
|
||||
margin-top: -20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.overlay-box {
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background-color: rgba(0, 0, 0, 0.9);
|
||||
|
||||
.circle-bg-box {
|
||||
height: 234rpx;
|
||||
background: url(@/static/images/course/talking.png) no-repeat;
|
||||
background-size: cover;
|
||||
position: relative;
|
||||
|
||||
.icon-box {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
margin-left: -17rpx;
|
||||
margin-top: -24rpx;
|
||||
width: 34rpx;
|
||||
height: 48rpx;
|
||||
|
||||
image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tips-box {
|
||||
height: 40rpx;
|
||||
line-height: 40rpx;
|
||||
color: #c0c0c0;
|
||||
text-align: center;
|
||||
margin: 36rpx 0 12rpx 0;
|
||||
font-weight: 600;
|
||||
font-size: 34rpx;
|
||||
color: #000000;
|
||||
line-height: 46px;
|
||||
}
|
||||
|
||||
.btns-box {
|
||||
height: 240rpx;
|
||||
width: 100%;
|
||||
font-size: 28rpx;
|
||||
display: flex;
|
||||
z-index: 1200;
|
||||
justify-content: space-around;
|
||||
position: relative;
|
||||
.btn-box {
|
||||
position: absolute;
|
||||
height: 164rpx;
|
||||
transform: scale(1.2);
|
||||
bottom: -10rpx;
|
||||
}
|
||||
.btn-box-1 {
|
||||
left: -40rpx;
|
||||
}
|
||||
.btn-box-2 {
|
||||
right: -40rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.talk-dialog {
|
||||
width: 506rpx;
|
||||
min-height: 234rpx;
|
||||
margin: 0 auto;
|
||||
background-color: #06f;
|
||||
border-radius: 32rpx;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: width 0.3s ease;
|
||||
.text-div {
|
||||
overflow-y: scroll;
|
||||
max-height: 434rpx;
|
||||
padding: 20rpx;
|
||||
font-size: 32rpx;
|
||||
color: #fff;
|
||||
line-height: 40rpx;
|
||||
}
|
||||
&.is-translate {
|
||||
width: 706rpx;
|
||||
.gif-box {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.is-out {
|
||||
background-color: #ff3e49;
|
||||
|
||||
&::after {
|
||||
background-color: #ff3e49;
|
||||
}
|
||||
}
|
||||
|
||||
.gif-box {
|
||||
position: absolute;
|
||||
width: 200rpx;
|
||||
height: 80rpx;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
width: 44rpx;
|
||||
height: 44rpx;
|
||||
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
|
||||
background-color: #06f;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
bottom: -22rpx;
|
||||
left: 50%;
|
||||
margin-left: -22rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.white-bg-box {
|
||||
height: 365rpx;
|
||||
background-color: #fff;
|
||||
overflow: hidden;
|
||||
border-radius: 32rpx 32rpx 0 0;
|
||||
padding: 58rpx 36rpx;
|
||||
|
||||
.box-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
line-height: 46rpx;
|
||||
margin-bottom: 46rpx;
|
||||
}
|
||||
|
||||
.box-btns {
|
||||
height: 46rpx;
|
||||
line-height: 46rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
color: #999;
|
||||
|
||||
.is-active {
|
||||
color: #06f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep .uv-input__content__field-wrapper__field {
|
||||
padding-right: 60rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "35"
|
||||
"minSdkVersion": "22"
|
||||
}
|
||||
@@ -105,8 +105,9 @@ export function stopAudioRecord() : void {
|
||||
}
|
||||
}
|
||||
}
|
||||
export function preRequestRecordPermission(callback ?: (granted : boolean) => void) { callback?.(true); }
|
||||
|
||||
// 预申请麦克风权限(ios需要,安卓只定义)
|
||||
export function preRequestRecordPermission():void {}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "13"
|
||||
"deploymentTarget": "35"
|
||||
}
|
||||
|
||||
@@ -14,9 +14,10 @@ export const UniErrorSubject = 'ty-recording';
|
||||
* 分段规则:9010001-9010009(权限)、9010010-9010019(初始化)、9010020-9010029(采集)、9010030-9010039(线程)、9010040-9010049(资源)、9010050-9010059(参数)、9010060-9010069(系统/硬件)、9010070+(预留)
|
||||
* @UniError
|
||||
*/
|
||||
|
||||
export const AudioErrors = new Map<AudioErrorCode, string>([
|
||||
// 权限相关(9010001-9010009)
|
||||
[9010001, '麦克风权限未授予,请前往设置开启'],
|
||||
[9010001, '麦克风权限未授予,请前往设置开启1'],
|
||||
[9010002, '麦克风权限被永久拒绝,请前往设置开启'],
|
||||
[9010003, '获取麦克风权限状态失败'],
|
||||
|
||||
@@ -69,15 +70,13 @@ export const AudioErrors = new Map<AudioErrorCode, string>([
|
||||
* 错误对象实现
|
||||
*/
|
||||
export class StartAudioRecordFailImpl extends UniError implements AudioErrorRes {
|
||||
override errCode: AudioErrorCode
|
||||
/**
|
||||
* 错误对象构造函数
|
||||
*/
|
||||
constructor(errCode : AudioErrorCode) {
|
||||
constructor(errCode : number) {
|
||||
super();
|
||||
|
||||
this.errSubject = UniErrorSubject;
|
||||
this.errCode = errCode;
|
||||
this.errMsg = AudioErrors.get(errCode) ?? "";
|
||||
this.errMsg = AudioErrors.get(errCode as AudioErrorCode) ?? "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"id": "ty-test",
|
||||
"displayName": "ty-test",
|
||||
"version": "1.0.0",
|
||||
"description": "ty-test",
|
||||
"keywords": [
|
||||
"ty-test"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.6.8"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "uts",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "",
|
||||
"data": "",
|
||||
"permissions": ""
|
||||
},
|
||||
"npmurl": ""
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "u",
|
||||
"aliyun": "u",
|
||||
"alipay": "u"
|
||||
},
|
||||
"client": {
|
||||
"Vue": {
|
||||
"vue2": "u",
|
||||
"vue3": "u"
|
||||
},
|
||||
"App": {
|
||||
"app-android": "u",
|
||||
"app-ios": "u",
|
||||
"app-harmony": "u"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "u",
|
||||
"Android Browser": "u",
|
||||
"微信浏览器(Android)": "u",
|
||||
"QQ浏览器(Android)": "u"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "u",
|
||||
"IE": "u",
|
||||
"Edge": "u",
|
||||
"Firefox": "u",
|
||||
"Safari": "u"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "u",
|
||||
"阿里": "u",
|
||||
"百度": "u",
|
||||
"字节跳动": "u",
|
||||
"QQ": "u",
|
||||
"钉钉": "u",
|
||||
"快手": "u",
|
||||
"飞书": "u",
|
||||
"京东": "u"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "u",
|
||||
"联盟": "u"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# ty-test
|
||||
### 开发文档
|
||||
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
|
||||
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
|
||||
[UTS uni-app兼容模式组件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
|
||||
[UTS 标准模式组件](https://doc.dcloud.net.cn/uni-app-x/plugin/uts-vue-component.html)
|
||||
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "21"
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 引用 Android 系统库,示例如下:
|
||||
* import { Context } from "android.content.Context";
|
||||
* [可选实现,按需引入]
|
||||
*/
|
||||
|
||||
/* 引入 interface.uts 文件中定义的变量 */
|
||||
import { MyApiOptions, MyApiResult, MyApi, MyApiSync } from '../interface.uts';
|
||||
|
||||
/* 引入 unierror.uts 文件中定义的变量 */
|
||||
import { MyApiFailImpl } from '../unierror';
|
||||
|
||||
/**
|
||||
* 引入三方库
|
||||
* [可选实现,按需引入]
|
||||
*
|
||||
* 在 Android 平台引入三方库有以下两种方式:
|
||||
* 1、[推荐] 通过 仓储 方式引入,将 三方库的依赖信息 配置到 config.json 文件下的 dependencies 字段下。详细配置方式[详见](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#dependencies)
|
||||
* 2、直接引入,将 三方库的aar或jar文件 放到libs目录下。更多信息[详见](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#android%E5%B9%B3%E5%8F%B0%E5%8E%9F%E7%94%9F%E9%85%8D%E7%BD%AE)
|
||||
*
|
||||
* 在通过上述任意方式依赖三方库后,使用时需要在文件中 import,如下示例:
|
||||
* import { LottieAnimationView } from 'com.airbnb.lottie.LottieAnimationView'
|
||||
*/
|
||||
|
||||
/**
|
||||
* UTSAndroid 为平台内置对象,不需要 import 可直接调用其API,[详见](https://uniapp.dcloud.net.cn/uts/utsandroid.html#utsandroid)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 异步方法
|
||||
*
|
||||
* uni-app项目中(vue/nvue)调用示例:
|
||||
* 1、引入方法声明 import { myApi } from "@/uni_modules/uts-api"
|
||||
* 2、方法调用
|
||||
* myApi({
|
||||
* paramA: false,
|
||||
* complete: (res) => {
|
||||
* console.log(res)
|
||||
* }
|
||||
* });
|
||||
* uni-app x项目(uvue)中调用示例:
|
||||
* 1、引入方法及参数声明 import { myApi, MyApiOptions } from "@/uni_modules/uts-api";
|
||||
* 2、方法调用
|
||||
* let options = {
|
||||
* paramA: false,
|
||||
* complete: (res : any) => {
|
||||
* console.log(res)
|
||||
* }
|
||||
* } as MyApiOptions;
|
||||
* myApi(options);
|
||||
*
|
||||
*/
|
||||
export const myApi : MyApi = function (options : MyApiOptions) {
|
||||
if (options.paramA == true) {
|
||||
// 返回数据
|
||||
const res : MyApiResult = {
|
||||
fieldA: 85,
|
||||
fieldB: true,
|
||||
fieldC: 'some message'
|
||||
};
|
||||
options.success?.(res);
|
||||
options.complete?.(res);
|
||||
} else {
|
||||
// 返回错误
|
||||
const err = new MyApiFailImpl(9010001);
|
||||
options.fail?.(err)
|
||||
options.complete?.(err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步方法
|
||||
*
|
||||
* uni-app项目中(vue/nvue)调用示例:
|
||||
* 1、引入方法声明 import { myApiSync } from "@/uni_modules/uts-api"
|
||||
* 2、方法调用 myApiSync(true)
|
||||
*
|
||||
* uni-app x项目(uvue)中调用示例:
|
||||
* 1、引入方法及参数声明 import { myApiSync } from "@/uni_modules/uts-api";
|
||||
* 2、方法调用 myApiSync(true)
|
||||
*/
|
||||
export const myApiSync : MyApiSync = function (paramA : boolean) : MyApiResult {
|
||||
// 返回数据,根据插件功能获取实际的返回值
|
||||
const res : MyApiResult = {
|
||||
fieldA: 85,
|
||||
fieldB: paramA,
|
||||
fieldC: 'some message'
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更多插件开发的信息详见:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
|
||||
*/
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "12"
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 引用 iOS 系统库,示例如下:
|
||||
* import { UIDevice } from "UIKit";
|
||||
* [可选实现,按需引入]
|
||||
*/
|
||||
|
||||
/* 引入 interface.uts 文件中定义的变量 */
|
||||
import { MyApiOptions, MyApiResult, MyApi, MyApiSync } from '../interface.uts';
|
||||
|
||||
/* 引入 unierror.uts 文件中定义的变量 */
|
||||
import { MyApiFailImpl } from '../unierror';
|
||||
|
||||
/**
|
||||
* 引入三方库
|
||||
* [可选实现,按需引入]
|
||||
*
|
||||
* 在 iOS 平台引入三方库有以下两种方式:
|
||||
* 1、通过引入三方库framework 或者.a 等方式,需要将 .framework 放到 ./Frameworks 目录下,将.a 放到 ./Libs 目录下。更多信息[详见](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#ios-平台原生配置)
|
||||
* 2、通过 cocoaPods 方式引入,将要引入的 pod 信息配置到 config.json 文件下的 dependencies-pods 字段下。详细配置方式[详见](https://uniapp.dcloud.net.cn/plugin/uts-ios-cocoapods.html)
|
||||
*
|
||||
* 在通过上述任意方式依赖三方库后,使用时需要在文件中 import:
|
||||
* 示例:import { LottieLoopMode } from 'Lottie'
|
||||
*/
|
||||
|
||||
/**
|
||||
* UTSiOS 为平台内置对象,不需要 import 可直接调用其API,[详见](https://uniapp.dcloud.net.cn/uts/utsios.html)
|
||||
*/
|
||||
|
||||
/**
|
||||
* 异步方法
|
||||
*
|
||||
* uni-app项目中(vue/nvue)调用示例:
|
||||
* 1、引入方法声明 import { myApi } from "@/uni_modules/uts-api"
|
||||
* 2、方法调用
|
||||
* myApi({
|
||||
* paramA: false,
|
||||
* complete: (res) => {
|
||||
* console.log(res)
|
||||
* }
|
||||
* });
|
||||
*
|
||||
*/
|
||||
export const myApi : MyApi = function (options : MyApiOptions) {
|
||||
|
||||
if (options.paramA == true) {
|
||||
// 返回数据
|
||||
const res : MyApiResult = {
|
||||
fieldA: 85,
|
||||
fieldB: true,
|
||||
fieldC: 'some message'
|
||||
};
|
||||
options.success?.(res);
|
||||
options.complete?.(res);
|
||||
|
||||
} else {
|
||||
// 返回错误
|
||||
let failResult = new MyApiFailImpl(9010001);
|
||||
options.fail?.(failResult)
|
||||
options.complete?.(failResult)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步方法
|
||||
*
|
||||
* uni-app项目中(vue/nvue)调用示例:
|
||||
* 1、引入方法声明 import { myApiSync } from "@/uni_modules/uts-api"
|
||||
* 2、方法调用
|
||||
* myApiSync(true);
|
||||
*
|
||||
*/
|
||||
export const myApiSync : MyApiSync = function (paramA : boolean) : MyApiResult {
|
||||
// 返回数据,根据插件功能获取实际的返回值
|
||||
const res : MyApiResult = {
|
||||
fieldA: 85,
|
||||
fieldB: paramA,
|
||||
fieldC: 'some message'
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更多插件开发的信息详见:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
|
||||
*/
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* interface.uts
|
||||
* uts插件接口定义文件,按规范定义接口文件可以在HBuilderX中更好的做到语法提示
|
||||
*/
|
||||
|
||||
/**
|
||||
* myApi 异步函数的参数,在type里定义函数需要的参数以及api成功、失败的相关回调函数。
|
||||
*/
|
||||
export type MyApiOptions = {
|
||||
paramA : boolean
|
||||
success ?: (res : MyApiResult) => void
|
||||
fail ?: (res : MyApiFail) => void
|
||||
complete ?: (res : any) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数返回结果
|
||||
* 可以是void, 基本数据类型,自定义type, 或者其他类型。
|
||||
* [可选实现]
|
||||
*/
|
||||
export type MyApiResult = {
|
||||
fieldA : number,
|
||||
fieldB : boolean,
|
||||
fieldC : string
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
* 根据uni错误码规范要求,建议错误码以90开头,以下是错误码示例:
|
||||
* - 9010001 错误信息1
|
||||
* - 9010002 错误信息2
|
||||
*/
|
||||
export type MyApiErrorCode = 9010001 | 9010002;
|
||||
/**
|
||||
* myApi 的错误回调参数
|
||||
*/
|
||||
export interface MyApiFail extends IUniError {
|
||||
errCode : MyApiErrorCode
|
||||
};
|
||||
|
||||
/* 异步函数定义 */
|
||||
export type MyApi = (options : MyApiOptions) => void
|
||||
|
||||
/* 同步函数定义 */
|
||||
export type MyApiSync = (paramA : boolean) => MyApiResult
|
||||
@@ -0,0 +1,39 @@
|
||||
/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
|
||||
import { MyApiErrorCode, MyApiFail } from "./interface.uts"
|
||||
/**
|
||||
* 错误主题
|
||||
* 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
|
||||
* [可选实现]
|
||||
*/
|
||||
export const UniErrorSubject = 'uts-api';
|
||||
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
* @UniError
|
||||
* [可选实现]
|
||||
*/
|
||||
export const MyAPIErrors : Map<MyApiErrorCode, string> = new Map([
|
||||
/**
|
||||
* 错误码及对应的错误信息
|
||||
*/
|
||||
[9010001, 'custom error mseeage1'],
|
||||
[9010002, 'custom error mseeage2'],
|
||||
]);
|
||||
|
||||
|
||||
/**
|
||||
* 错误对象实现
|
||||
*/
|
||||
export class MyApiFailImpl extends UniError implements MyApiFail {
|
||||
|
||||
/**
|
||||
* 错误对象构造函数
|
||||
*/
|
||||
constructor(errCode : MyApiErrorCode) {
|
||||
super();
|
||||
this.errSubject = UniErrorSubject;
|
||||
this.errCode = errCode;
|
||||
this.errMsg = MyAPIErrors.get(errCode) ?? "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user