Skip to content

Commit 4f10426

Browse files
authoredFeb 7, 2025··
fix(useSpeechRecognition): improve start and stop method behavior (#4565)
1 parent 636b866 commit 4f10426

File tree

1 file changed

+7
-6
lines changed
  • packages/core/useSpeechRecognition

1 file changed

+7
-6
lines changed
 

‎packages/core/useSpeechRecognition/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ export function useSpeechRecognition(options: UseSpeechRecognitionOptions = {})
6262
let recognition: SpeechRecognition | undefined
6363

6464
const start = () => {
65-
if (!isListening.value)
66-
recognition?.start()
65+
isListening.value = true
6766
}
6867

6968
const stop = () => {
70-
if (isListening.value)
71-
recognition?.stop()
69+
isListening.value = false
7270
}
7371

7472
const toggle = (value = !isListening.value) => {
@@ -119,8 +117,11 @@ export function useSpeechRecognition(options: UseSpeechRecognitionOptions = {})
119117
recognition!.lang = toValue(lang)
120118
}
121119

122-
watch(isListening, () => {
123-
if (isListening.value)
120+
watch(isListening, (newValue, oldValue) => {
121+
if (newValue === oldValue)
122+
return
123+
124+
if (newValue)
124125
recognition!.start()
125126
else
126127
recognition!.stop()

0 commit comments

Comments
 (0)
Please sign in to comment.