fix: 语音录音时长获取方式调整

This commit is contained in:
杨航
2025-12-05 11:04:20 +08:00
parent 616efc63c9
commit 1deecae63f
9 changed files with 55 additions and 16 deletions
+2 -2
View File
@@ -4,8 +4,8 @@ ENV = 'development.yh'
# VITE_APP_BASE_H5_API_Url = 'http://25.18.122.65:7001'
VITE_APP_BASE_H5_API_Url = 'http://25.18.122.91:9786'
# VITE_APP_BASE_H5_API_Url = 'http://25.18.122.78:9786'
# VITE_APP_BASE_H5_API_Url = 'http://25.18.122.91:9786'
VITE_APP_BASE_H5_API_Url = 'http://25.18.122.78:9786'
# VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002'
# VITE_APP_BASE_H5_API_Url_TRAEXAM = 'http://25.64.32.154:9604'
# VITE_APP_BASE_H5_API_Url_TRAPRACTICE = 'http://25.64.32.156:9603'
+1 -1
View File
@@ -694,7 +694,7 @@
voiceTime.value = (Math.ceil(talkVoiceObj.value.duration) || 0) + 's';
} else {
if (sum === 100) {
voiceTime.value = 0 + 's';
voiceTime.value = (unref(dataInfo).voiceTime || 0) + 's';
return;
}
setTimeout(() => {
+19 -1
View File
@@ -174,6 +174,7 @@
const initRecord = () => {
recordObjCom.value = uni.getRecorderManager();
unref(recordObjCom)?.onStop((res, duration) => {
isRecording.value = false
if(isGettingPermission.value){
isGettingPermission.value = false
return
@@ -196,13 +197,20 @@
});
} else {
closeModel();
emit('uploadVoice', audioPath.value);
emit('uploadVoice', audioPath.value, recordTime.value);
}
} else {
closeModel();
}
});
unref(recordObjCom).onStart(() => {
isRecording.value = true
recordTime.value = 0
setRecordTime()
if(isGettingPermission.value){
isGettingPermission.value = false
return
}
startFlag.value = 1;
setTimeout(() => {
startFlag.value = 2;
@@ -219,6 +227,16 @@
}
});
};
const setRecordTime = () => {
setTimeout(()=>{
if(isRecording.value){
recordTime.value += 1
setRecordTime()
}
},1000)
}
const isRecording = ref(false)
const recordTime = ref(0)
const startFlag = ref(1);
// const canStart = ref(true)
const startRecord = () => {
+3 -2
View File
@@ -839,7 +839,7 @@ const testAnswer = computed(() => {
let _num = _arr.map(t => [1, 2, 6].indexOf(Number(t.type)) >= 0).filter(t => !!t)
return _num.length < 5
})
const uploadRecordNow = voicePath => {
const uploadRecordNow = (voicePath, voiceTime) => {
if (!testAnswer.value) {
common.msg('每个问题最多连续发送五次答案!')
return
@@ -911,7 +911,8 @@ const uploadRecordNow = voicePath => {
userInfo: {
...choiceTeacherInfo.value
},
id: _id
id: _id,
voiceTime: voiceTime
}
} else {
return t
+1 -1
View File
@@ -131,7 +131,7 @@ import { onUnload } from '@dcloudio/uni-app';
voiceTime.value = (Math.ceil(talkVoiceObj.value.duration) || 1 ) + 's'
}else{
if(sum === 20) {
voiceTime.value = 0 + 's'
voiceTime.value = (unref(dataInfo).voiceTime || 0) + 's';
return
}
setTimeout(()=>{
+3 -2
View File
@@ -662,7 +662,7 @@
submitAnswerNow(item);
};
// 发送语音
const uploadRecordNow = (voicePath) => {
const uploadRecordNow = (voicePath, voiceTime) => {
// /traask/traAskchat/voiceTrans
//#ifndef APP-PLUS
// h5 假数据
@@ -683,7 +683,8 @@
intrctContent: _res.body.transContent,
bucketKey: _res.body.fileId,
ossFileAddr: _res.body.ossFileAddr,
talkingVoice: voicePath
talkingVoice: voicePath,
voiceTime: voiceTime
};
sendMessage({
commond: 'ASK',
+8 -4
View File
@@ -130,8 +130,12 @@
talkUserVoiceObj.value.onError(() => {
talkUserVoiceObj.value.src = ''
})
talkUserVoiceObj.value.onCanplay(() => {
setVoiceTime(0)
})
itemVoice.value = unref(dataInfo).talkingVoice
talkUserVoiceObj.value.src = itemVoice.value
talkUserVoiceObj.value.sessionCategory = 'soloAmbient'
//#ifdef APP-PLUS
// 安卓端 须播放一次,不然再次播放会没有声音
if (IsAndEnv) {
@@ -141,9 +145,9 @@
// talkUserVoiceObj.value.pause()
}
// #endif
setTimeout(() => {
setVoiceTime(0)
}, 100)
// setTimeout(() => {
// setVoiceTime(0)
// }, 100)
}
const isTesting = ref(false)
const setVoiceTime = (sum) => {
@@ -152,7 +156,7 @@
voiceTime.value = (Math.ceil(talkUserVoiceObj.value.duration) || 1) + 's'
} else {
if (sum === 20) {
voiceTime.value = 0 + 's'
voiceTime.value = (props.dataInfo.voiceTime|| 0) + 's'
return
}
setTimeout(() => {
+15 -1
View File
@@ -127,6 +127,7 @@
const initRecord = () => {
recordObjCom.value = uni.getRecorderManager();
unref(recordObjCom)?.onStop((res, duration) => {
isRecording.value = false
if(isGettingPermission.value){
isGettingPermission.value = false
return
@@ -141,13 +142,16 @@
});
} else {
closeModel();
emit('uploadVoice', audioPath.value);
emit('uploadVoice', audioPath.value, recordTime.value);
}
} else {
closeModel();
}
});
unref(recordObjCom).onStart(() => {
isRecording.value = true
recordTime.value = 0
setRecordTime()
if(isGettingPermission.value){
stopRecord();
return
@@ -167,6 +171,16 @@
}
});
};
const setRecordTime = () => {
setTimeout(()=>{
if(isRecording.value){
recordTime.value += 1
setRecordTime()
}
},1000)
}
const isRecording = ref(false)
const recordTime = ref(0)
const startFlag = ref(1);
const startRecord = () => {
isStartNum.value += 1;
+3 -2
View File
@@ -189,7 +189,7 @@
}, time);
});
};
const uploadRecordNow = (voicePath) => {
const uploadRecordNow = (voicePath, voiceTime) => {
//#ifndef APP-PLUS
// h5 假数据
// #endif
@@ -211,7 +211,8 @@
intrctContent: _res.body.transContent,
fileId: _res.body.fileId,
ossFileAddr: _res.body.ossFileAddr,
talkingVoice: voicePath
talkingVoice: voicePath,
voiceTime: voiceTime
};
sendMessage({
commond: 'ASK',