chore:语音输入有返回

This commit is contained in:
2026-09-29 16:46:59 +08:00
parent bf5e32df2b
commit 10e6402ad6
4 changed files with 106 additions and 22 deletions

View File

@@ -4073,6 +4073,7 @@ _handleStreamError(msg) {
// - touchend 提交产物 (取消则丢弃)
// - H5 鼠标不会触发 touch, click 也走 onVoiceHoldEnd 兜底 (无录音产物就当没按住)
onVoiceHoldStart(e) {
console.log('[ai-chat] onVoiceHoldStart fired', this._voiceRecorder ? 'recorder already exists' : 'creating recorder')
if (this._voiceRecorder) return
this.voiceHolding = true
this.voiceHoldCancelling = false
@@ -4090,6 +4091,7 @@ _handleStreamError(msg) {
}
this._onHoldError = (err) => {
console.warn('[ai-chat] voice hold error:', err)
console.error('[ai-chat] voice hold error raw:', JSON.stringify(err), 'errMsg=', err && err.errMsg, 'message=', err && err.message)
uni.showToast({ title: this._voiceErrMsg(err) || this.$lang('ai-chat.index.voiceInputFailed'), icon: 'none' })
this._discardVoiceRecorder()
}
@@ -4119,6 +4121,7 @@ _handleStreamError(msg) {
},
async onVoiceHoldEnd() {
console.log('[ai-chat] onVoiceHoldEnd fired, voiceHolding=', this.voiceHolding, 'recorder=', !!this._voiceRecorder)
if (!this.voiceHolding) {
// 非按住触发的 click (H5 鼠标等), 不做任何事, 避免双触发
return
@@ -4129,6 +4132,7 @@ _handleStreamError(msg) {
if (!this._voiceRecorder) {
// 启动录音器失败 (无 touch 触发的 click) → 退回弹窗路径, 保留功能不丢
console.log('[ai-chat] onVoiceHoldEnd: no recorder, fallback to voice panel')
this.showVoicePanel()
return
}
@@ -4139,13 +4143,19 @@ _handleStreamError(msg) {
}
try {
const result = await this._voiceRecorder.stop()
console.log('[ai-chat] voice hold stop result:', JSON.stringify(result))
this._teardownVoiceRecorder()
if (!result || !result.filePath) {
uni.showToast({ title: this.$lang('ai-chat.index.voiceStopFailed'), icon: 'none' })
return
}
await this._handleRecordedAudio(result)
// PR-FRONTEND-VOICE-AUTO-SEND (2026-09-29): 按住说话像微信一样, 松手后自动发送,
// 不需要用户再点一次发送按钮。
console.log('[ai-chat] voice hold auto-send triggered')
this.sendMessage()
} catch (e) {
console.error('[ai-chat] voice hold end error:', e && e.errMsg, e && e.message, JSON.stringify(e))
this._teardownVoiceRecorder()
uni.showToast({ title: this._voiceErrMsg(e) || this.$lang('ai-chat.index.voiceInputFailed'), icon: 'none' })
}
@@ -4153,6 +4163,7 @@ _handleStreamError(msg) {
// 按住说话: 手势被系统打断 (来电/滑动取消)
onVoiceHoldCancel() {
console.log('[ai-chat] onVoiceHoldCancel fired')
if (!this.voiceHolding) return
this.voiceHolding = false
this.voiceHoldCancelling = false
@@ -4267,12 +4278,14 @@ _handleStreamError(msg) {
},
_discardVoiceRecorder() {
console.log('[ai-chat] _discardVoiceRecorder called')
if (!this._voiceRecorder) return
try { this._voiceRecorder.cancel() } catch (e) { /* noop */ }
this._teardownVoiceRecorder()
},
_teardownVoiceRecorder() {
console.log('[ai-chat] _teardownVoiceRecorder called')
if (this._voiceRecorder) {
if (this._onHoldProgress) this._voiceRecorder.off('progress', this._onHoldProgress)
if (this._onHoldError) this._voiceRecorder.off('error', this._onHoldError)
@@ -4297,7 +4310,8 @@ _handleStreamError(msg) {
case 'ALREADY_STARTED':
return this.$lang('ai-chat.index.voiceStartFailed')
case 'UNI_RECORD_ERROR':
return this.$lang('ai-chat.index.voiceStopFailed')
// 诊断期: 直接透出微信原始错误 (errMsg/message), 便于截图定位根因
return (err && (err.errMsg || err.message)) || this.$lang('ai-chat.index.voiceStopFailed')
default:
return err.message || ''
}

View File

@@ -147,6 +147,7 @@ export default {
}
this._onError = (err) => {
console.warn('[voice-panel] recorder error:', err)
console.error('[voice-panel] recorder error raw:', JSON.stringify(err), 'errMsg=', err && err.errMsg, 'message=', err && err.message)
uni.showToast({ title: this._voiceErrMsg(err) || this.$lang('ai-chat.index.voiceInputFailed'), icon: 'none' })
this._discardRecorderIfAny()
}
@@ -227,7 +228,7 @@ export default {
case 'ALREADY_STARTED':
return this.$lang('ai-chat.index.voiceStartFailed')
case 'UNI_RECORD_ERROR':
return this.$lang('ai-chat.index.voiceStopFailed')
return (err && (err.errMsg || err.message)) || this.$lang('ai-chat.index.voiceStopFailed')
default:
return err.message || ''
}