fix: interview 录音改为长按按住录音松开提交
startRecord 先同步设 isRecording=true 再异步 uni.authorize,避免 touchend 在 authorize success 回调前就触发 stopRecord 导致录音没 来得及开始就被停止。 移除冗余 doStartRecorder 函数,inline 到 authorize success 回调中。 stopRecord 不再检查 isRecording 守卫(可能已被 startRecord 设为 true), 直接 recorder.stop()。
This commit is contained in:
@@ -401,28 +401,11 @@ function startRecord() {
|
||||
if (aiLoading.value || isComplete.value) return
|
||||
// #ifdef MP-WEIXIN
|
||||
if (isRecording.value) return
|
||||
// 先确保已获得 scope.record 授权,避免没权限时产生全 0 的 corrupted 音频
|
||||
// 先标记正在录音,避免 touchend 在 authorize 回调前就触发 stopRecord
|
||||
isRecording.value = true
|
||||
uni.authorize({
|
||||
scope: 'scope.record',
|
||||
success: () => doStartRecorder(),
|
||||
fail: () => {
|
||||
uni.showModal({
|
||||
title: '需要录音权限',
|
||||
content: '请在「设置」中开启「麦克风」权限后再使用语音输入',
|
||||
confirmText: '去设置',
|
||||
success: (r) => { if (r.confirm) uni.openSetting({}) },
|
||||
})
|
||||
},
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.showToast({ title: '语音输入仅支持小程序', icon: 'none' })
|
||||
// #endif
|
||||
}
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
function doStartRecorder() {
|
||||
isRecording.value = true
|
||||
success: () => {
|
||||
if (!recorder) initRecorder()
|
||||
if (!recorder) {
|
||||
isRecording.value = false
|
||||
@@ -436,12 +419,27 @@ function doStartRecorder() {
|
||||
encodeBitRate: 128000,
|
||||
})
|
||||
uni.vibrateShort({ type: 'medium' })
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
isRecording.value = false
|
||||
uni.showModal({
|
||||
title: '需要录音权限',
|
||||
content: '请在「设置」中开启「麦克风」权限后再使用语音输入',
|
||||
confirmText: '去设置',
|
||||
success: (r) => { if (r.confirm) uni.openSetting({}) },
|
||||
})
|
||||
},
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
isRecording.value = false
|
||||
uni.showToast({ title: '语音输入仅支持小程序', icon: 'none' })
|
||||
// #endif
|
||||
}
|
||||
|
||||
function stopRecord() {
|
||||
if (!recorder || !isRecording.value) return
|
||||
isRecording.value = false
|
||||
if (!recorder) return
|
||||
recorder.stop()
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user