|
@@ -398,15 +398,37 @@ watch(streamConversationId, (newId) => {
|
|
|
// 监听 showChat 变化,开始对话时自动启动语音识别
|
|
// 监听 showChat 变化,开始对话时自动启动语音识别
|
|
|
watch(showChat, async (newVal) => {
|
|
watch(showChat, async (newVal) => {
|
|
|
if (newVal && !isRecording.value) {
|
|
if (newVal && !isRecording.value) {
|
|
|
- try {
|
|
|
|
|
- await startRecording()
|
|
|
|
|
- ElMessage.success('语音识别已启动')
|
|
|
|
|
|
|
+ // 尝试启动语音识别,最多重试 3 次
|
|
|
|
|
+ let retryCount = 0
|
|
|
|
|
+ const maxRetries = 3
|
|
|
|
|
|
|
|
- // 启动波形动画
|
|
|
|
|
- waveformInterval = setInterval(updateWaveform, 100)
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- ElMessage.error('启动语音识别失败: ' + error.message)
|
|
|
|
|
|
|
+ const tryStartRecording = async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await startRecording()
|
|
|
|
|
+ ElMessage.success('语音识别已启动')
|
|
|
|
|
+
|
|
|
|
|
+ // 启动波形动画
|
|
|
|
|
+ waveformInterval = setInterval(updateWaveform, 100)
|
|
|
|
|
+ return true
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ retryCount++
|
|
|
|
|
+ console.error(`语音识别启动失败 (尝试 ${retryCount}/${maxRetries}):`, error)
|
|
|
|
|
+
|
|
|
|
|
+ if (retryCount < maxRetries) {
|
|
|
|
|
+ ElMessage.warning(`语音识别启动失败,正在重试 (${retryCount}/${maxRetries})...`)
|
|
|
|
|
+ // 等待 1 秒后重试
|
|
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 1000))
|
|
|
|
|
+ return tryStartRecording()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ElMessage.error('语音识别启动失败,已切换到文字输入模式')
|
|
|
|
|
+ // 多次重试都失败,切换到文字输入模式
|
|
|
|
|
+ isTextInput.value = true
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ await tryStartRecording()
|
|
|
} else if (!newVal) {
|
|
} else if (!newVal) {
|
|
|
// 对话结束时,无论什么状态都执行清理操作
|
|
// 对话结束时,无论什么状态都执行清理操作
|
|
|
if (isRecording.value) {
|
|
if (isRecording.value) {
|
|
@@ -451,6 +473,11 @@ watch(showChat, async (newVal) => {
|
|
|
// 清空 conversationId,确保下次开始对话时是新的会话
|
|
// 清空 conversationId,确保下次开始对话时是新的会话
|
|
|
currentConversationId.value = null
|
|
currentConversationId.value = null
|
|
|
resetConversation()
|
|
resetConversation()
|
|
|
|
|
+
|
|
|
|
|
+ // 重置输入模式为语音输入
|
|
|
|
|
+ isTextInput.value = false
|
|
|
|
|
+ // 重置麦克风静音状态
|
|
|
|
|
+ isMicMuted.value = false
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|