From 820e28ec8272af1f083132805b5f51de8d406e9e Mon Sep 17 00:00:00 2001 From: zwkkwz1 <494913198@qq.com> Date: Sat, 18 Feb 2023 00:15:47 +0800 Subject: [PATCH] feat(useSpeechSynthesis): add `stop` function (#2774) --- packages/core/useSpeechSynthesis/demo.vue | 2 +- packages/core/useSpeechSynthesis/index.md | 1 + packages/core/useSpeechSynthesis/index.ts | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/useSpeechSynthesis/demo.vue b/packages/core/useSpeechSynthesis/demo.vue index 923b841f265..3738ac39d41 100644 --- a/packages/core/useSpeechSynthesis/demo.vue +++ b/packages/core/useSpeechSynthesis/demo.vue @@ -39,7 +39,7 @@ const pause = () => { } const stop = () => { - window.speechSynthesis.cancel() + speech.stop() } diff --git a/packages/core/useSpeechSynthesis/index.md b/packages/core/useSpeechSynthesis/index.md index d0a3bfa209c..c724c99a548 100644 --- a/packages/core/useSpeechSynthesis/index.md +++ b/packages/core/useSpeechSynthesis/index.md @@ -20,6 +20,7 @@ const { voiceInfo, utterance, error, + stop, toggle, speak, diff --git a/packages/core/useSpeechSynthesis/index.ts b/packages/core/useSpeechSynthesis/index.ts index 6ff3a12f2bd..25513003d3a 100644 --- a/packages/core/useSpeechSynthesis/index.ts +++ b/packages/core/useSpeechSynthesis/index.ts @@ -113,6 +113,11 @@ export function useSpeechSynthesis(text: MaybeComputedRef, options: UseS utterance && synth!.speak(utterance.value) } + const stop = () => { + synth!.cancel() + isPlaying.value = false + } + if (isSupported.value) { bindEventsForUtterance(utterance.value) @@ -146,6 +151,7 @@ export function useSpeechSynthesis(text: MaybeComputedRef, options: UseS utterance, error, + stop, toggle, speak, }