fix: voice input recording format + ASR logging

- Change recorder format from mp3 (8kHz) to aac (22kHz) for better
  whisper ASR accuracy
- Move recorder.onStop binding before recorder.stop() to prevent
  race condition (onStop may fire before handler is registered)
- Backend: add Logger, log ASR errors instead of silent catch {}
- Backend: change default extension from .mp3 to .aac
This commit is contained in:
yuzhiran
2026-06-25 08:49:55 +08:00
parent 9b1c92464e
commit b8aaa51eb1
2 changed files with 21 additions and 16 deletions
+13 -13
View File
@@ -351,19 +351,7 @@ function startRecord() {
isRecording.value = true
recorder = uni.getRecorderManager()
recorder.onStart(() => {})
recorder.onError(() => { isRecording.value = false })
recorder.start({ format: 'mp3' })
uni.vibrateShort({ type: 'medium' })
// #endif
// #ifndef MP-WEIXIN
uni.showToast({ title: '语音输入仅支持小程序', icon: 'none' })
// #endif
}
function stopRecord() {
if (!recorder || !isRecording.value) return
isRecording.value = false
recorder.stop()
recorder.onError(() => { isRecording.value = false; uni.showToast({ title: '录音失败', icon: 'none' }) })
recorder.onStop(async (res) => {
if (!res.tempFilePath) return
const audioPath = res.tempFilePath
@@ -387,6 +375,18 @@ function stopRecord() {
}
uni.showToast({ title: '语音识别失败,请手动输入', icon: 'none' })
})
recorder.start({ format: 'aac', sampleRate: 22050, numberOfChannels: 1, encodeBitRate: 16000 })
uni.vibrateShort({ type: 'medium' })
// #endif
// #ifndef MP-WEIXIN
uni.showToast({ title: '语音输入仅支持小程序', icon: 'none' })
// #endif
}
function stopRecord() {
if (!recorder || !isRecording.value) return
isRecording.value = false
recorder.stop()
}
</script>