diff --git a/src/useSpeechSynthesis.jsx b/src/useSpeechSynthesis.jsx index fbd5960..fe1b922 100644 --- a/src/useSpeechSynthesis.jsx +++ b/src/useSpeechSynthesis.jsx @@ -5,6 +5,7 @@ const useSpeechSynthesis = (props = {}) => { const [voices, setVoices] = useState([]); const [speaking, setSpeaking] = useState(false); const [supported, setSupported] = useState(false); + const [paused, setPaused] = useState(false); const processVoices = (voiceOptions) => { setVoices(voiceOptions); @@ -27,6 +28,7 @@ const useSpeechSynthesis = (props = {}) => { const handleEnd = () => { setSpeaking(false); + setPaused(false); onEnd(); }; @@ -56,14 +58,32 @@ const useSpeechSynthesis = (props = {}) => { const cancel = () => { if (!supported) return; setSpeaking(false); + setPaused(false); window.speechSynthesis.cancel(); }; + const pause = () => { + if (!supported) return; + setSpeaking(false); + setPaused(true); + window.speechSynthesis.pause(); + }; + + const resume = () => { + if (!supported) return; + setSpeaking(true); + setPaused(false); + window.speechSynthesis.resume(); + }; + return { supported, speak, speaking, cancel, + pause, + paused, + resume, voices, }; };