From f52f1f7f0f034694a4411479e16b6cfdbd1e684a Mon Sep 17 00:00:00 2001 From: allen ge Date: Sun, 16 Jun 2019 17:35:57 +0800 Subject: [PATCH] feat: add rate option in useSpeech --- src/useSpeech.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/useSpeech.ts b/src/useSpeech.ts index 4b0066c2e3..67e2ab166c 100644 --- a/src/useSpeech.ts +++ b/src/useSpeech.ts @@ -18,6 +18,7 @@ export interface SpeechOptions { const useSpeech = (text: string, opts: SpeechOptions = {}): SpeechState => { const [state, setState] = useSetState({ isPlaying: false, + rate: opts.rate || 1, volume: opts.volume || 1, }); @@ -25,6 +26,7 @@ const useSpeech = (text: string, opts: SpeechOptions = {}): SpeechState => { useMount(() => { const utterance = new SpeechSynthesisUtterance(text); + utterance.rate = opts.rate || 1; utterance.volume = opts.volume || 1; utterance.onstart = () => setState({ isPlaying: true }); utterance.onresume = () => setState({ isPlaying: true });