Skip to content

Commit

Permalink
fix(useSpeechRecognition): improve start and stop method behavior (#4565
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ilyaliao authored Feb 7, 2025
1 parent 636b866 commit 4f10426
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/core/useSpeechRecognition/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ export function useSpeechRecognition(options: UseSpeechRecognitionOptions = {})
let recognition: SpeechRecognition | undefined

const start = () => {
if (!isListening.value)
recognition?.start()
isListening.value = true
}

const stop = () => {
if (isListening.value)
recognition?.stop()
isListening.value = false
}

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

watch(isListening, () => {
if (isListening.value)
watch(isListening, (newValue, oldValue) => {
if (newValue === oldValue)
return

if (newValue)
recognition!.start()
else
recognition!.stop()
Expand Down

0 comments on commit 4f10426

Please sign in to comment.