|
@@ -53,14 +53,26 @@ const isRecording = ref(false) // 录音状态
|
|
|
const recognition = ref(null) // 语音识别实例
|
|
const recognition = ref(null) // 语音识别实例
|
|
|
const countdown = ref(0) // 倒计时剩余秒数
|
|
const countdown = ref(0) // 倒计时剩余秒数
|
|
|
const countdownTimer = ref(null) // 倒计时定时器
|
|
const countdownTimer = ref(null) // 倒计时定时器
|
|
|
|
|
+const isBrowserSupported = ref(true) // 浏览器是否支持语音识别
|
|
|
|
|
|
|
|
-// 初始化语音识别
|
|
|
|
|
-const initSpeechRecognition = () => {
|
|
|
|
|
|
|
+// 检测浏览器是否支持语音识别
|
|
|
|
|
+const checkBrowserSupport = () => {
|
|
|
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
|
|
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
|
|
|
if (!SpeechRecognition) {
|
|
if (!SpeechRecognition) {
|
|
|
ElMessage.warning('当前浏览器不支持语音输入功能')
|
|
ElMessage.warning('当前浏览器不支持语音输入功能')
|
|
|
|
|
+ isBrowserSupported.value = false
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ return true
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 初始化语音识别
|
|
|
|
|
+const initSpeechRecognition = () => {
|
|
|
|
|
+ if (!checkBrowserSupport()) {
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
|
|
|
|
|
|
|
|
const instance = new SpeechRecognition()
|
|
const instance = new SpeechRecognition()
|
|
|
instance.lang = props.lang
|
|
instance.lang = props.lang
|
|
@@ -144,6 +156,11 @@ const toggleSpeechInput = () => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 组件挂载时检测浏览器支持
|
|
|
|
|
+onMounted(() => {
|
|
|
|
|
+ checkBrowserSupport()
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
// 组件卸载时清理资源
|
|
// 组件卸载时清理资源
|
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
|
clearInterval(countdownTimer.value)
|
|
clearInterval(countdownTimer.value)
|