Skip to content

Commit 94f1e9e

Browse files
ben-lauliubaobin9romise
authored
fix(useSpeechRecognition): catch the error while calling method start (#5142)
Co-authored-by: liubaobin <[email protected]> Co-authored-by: Vida Xie <[email protected]>
1 parent 278c2d4 commit 94f1e9e

File tree

1 file changed

+12
-5
lines changed
  • packages/core/useSpeechRecognition

1 file changed

+12
-5
lines changed

packages/core/useSpeechRecognition/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function useSpeechRecognition(options: UseSpeechRecognitionOptions = {})
5656
const isListening = shallowRef(false)
5757
const isFinal = shallowRef(false)
5858
const result = shallowRef('')
59-
const error = shallowRef<SpeechRecognitionErrorEvent | undefined>(undefined)
59+
const error = shallowRef<SpeechRecognitionErrorEvent | Error | undefined>(undefined)
6060

6161
let recognition: SpeechRecognition | undefined
6262

@@ -120,10 +120,17 @@ export function useSpeechRecognition(options: UseSpeechRecognitionOptions = {})
120120
if (newValue === oldValue)
121121
return
122122

123-
if (newValue)
124-
recognition!.start()
125-
else
126-
recognition!.stop()
123+
try {
124+
if (newValue) {
125+
recognition!.start()
126+
}
127+
else {
128+
recognition!.stop()
129+
}
130+
}
131+
catch (err) {
132+
error.value = err as unknown as Error
133+
}
127134
})
128135
}
129136

0 commit comments

Comments
 (0)