chore:语音输入正常
This commit is contained in:
@@ -4077,6 +4077,7 @@ _handleStreamError(msg) {
|
||||
if (this._voiceRecorder) return
|
||||
this.voiceHolding = true
|
||||
this.voiceHoldCancelling = false
|
||||
this._voiceHoldStartTime = Date.now()
|
||||
try {
|
||||
const touch = (e && e.touches && e.touches[0]) || null
|
||||
this._voiceHoldStartY = touch ? touch.clientY : 0
|
||||
@@ -4143,12 +4144,20 @@ _handleStreamError(msg) {
|
||||
}
|
||||
try {
|
||||
const result = await this._voiceRecorder.stop()
|
||||
console.log('[ai-chat] voice hold stop result:', JSON.stringify(result))
|
||||
const pressDuration = this._voiceHoldStartTime ? Date.now() - this._voiceHoldStartTime : 0
|
||||
console.log('[ai-chat] voice hold stop result:', JSON.stringify(result), 'pressDuration=', pressDuration)
|
||||
this._teardownVoiceRecorder()
|
||||
if (!result || !result.filePath) {
|
||||
uni.showToast({ title: this.$lang('ai-chat.index.voiceStopFailed'), icon: 'none' })
|
||||
return
|
||||
}
|
||||
// PR-FRONTEND-VOICE-MIN-DURATION (2026-09-29): 过滤过短录音, 像微信一样提示"说话时间太短",
|
||||
// 避免发出去 100ms 的空语音导致播放失败/后端无法识别。
|
||||
if (result.duration < 500) {
|
||||
console.log('[ai-chat] voice too short, discarded:', result.duration, 'ms')
|
||||
uni.showToast({ title: this.$lang('ai-chat.index.voiceTooShort'), icon: 'none' })
|
||||
return
|
||||
}
|
||||
await this._handleRecordedAudio(result)
|
||||
// PR-FRONTEND-VOICE-AUTO-SEND (2026-09-29): 按住说话像微信一样, 松手后自动发送,
|
||||
// 不需要用户再点一次发送按钮。
|
||||
@@ -4301,6 +4310,11 @@ _handleStreamError(msg) {
|
||||
// voice-recorder.js 自身不带 Vue 上下文, 通过 err.code 映射到 $lang() key
|
||||
_voiceErrMsg(err) {
|
||||
if (!err) return ''
|
||||
const msg = (err && (err.errMsg || err.message || err.errMsg)) || ''
|
||||
// 微信录音单例仍被占用 (通常因上一次 onStop 尚未触发就被下一次 start 抢占)
|
||||
if (msg && (msg.includes("is recording") || msg.includes("operateRecorder:fail:audio"))) {
|
||||
return this.$lang('ai-chat.index.voiceRecorderBusy')
|
||||
}
|
||||
switch (err.code) {
|
||||
case 'NOT_SUPPORTED':
|
||||
case 'NO_RECORDER_MANAGER':
|
||||
@@ -4311,9 +4325,9 @@ _handleStreamError(msg) {
|
||||
return this.$lang('ai-chat.index.voiceStartFailed')
|
||||
case 'UNI_RECORD_ERROR':
|
||||
// 诊断期: 直接透出微信原始错误 (errMsg/message), 便于截图定位根因
|
||||
return (err && (err.errMsg || err.message)) || this.$lang('ai-chat.index.voiceStopFailed')
|
||||
return msg || this.$lang('ai-chat.index.voiceStopFailed')
|
||||
default:
|
||||
return err.message || ''
|
||||
return msg || ''
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user