Przeglądaj źródła

语音输入强制校验只有edge浏览器支持,其他提示

liyanbo 3 miesięcy temu
rodzic
commit
0542e8e97d
1 zmienionych plików z 25 dodań i 0 usunięć
  1. 25 0
      src/components/ai/voice/VoiceInput.vue

+ 25 - 0
src/components/ai/voice/VoiceInput.vue

@@ -110,8 +110,33 @@ const initSpeechRecognition = () => {
   return instance
 }
 
+// 获取浏览器信息
+const getBrowserInfo = () => {
+  const userAgent = window.navigator.userAgent.toLowerCase()
+  if (userAgent.includes('edg')) {
+    return { name: 'Edge', version: (userAgent.match(/edg\/([\d.]+)/) || [])[1] }
+  }
+  if (userAgent.includes('chrome')) {
+    return { name: 'Chrome', version: (userAgent.match(/chrome\/([\d.]+)/) || [])[1] }
+  }
+  if (userAgent.includes('firefox')) {
+    return { name: 'Firefox', version: (userAgent.match(/firefox\/([\d.]+)/) || [])[1] }
+  }
+  if (userAgent.includes('safari')) {
+    return { name: 'Safari', version: (userAgent.match(/version\/([\d.]+)/) || [])[1] }
+  }
+  return { name: 'Unknown', version: 'Unknown' }
+}
+
 // 切换录音状态
 const toggleSpeechInput = () => {
+  const browser = getBrowserInfo()
+  // 已知Edge支持,Chrome不支持
+  if (browser.name !== 'Edge') {
+    ElMessage.error('当前浏览器暂不支持语音输入功能,请使用Edge浏览器')
+    isBrowserSupported.value = false
+    return false
+  }
   // 无论当前状态如何,先清除可能存在的旧定时器
   clearInterval(countdownTimer.value)
   countdownTimer.value = null