Skip to content

Commit

Permalink
feat: add rate option in useSpeech
Browse files Browse the repository at this point in the history
  • Loading branch information
gelove authored Jun 16, 2019
1 parent 882a5f2 commit f52f1f7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/useSpeech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export interface SpeechOptions {
const useSpeech = (text: string, opts: SpeechOptions = {}): SpeechState => {
const [state, setState] = useSetState<SpeechState>({
isPlaying: false,
rate: opts.rate || 1,
volume: opts.volume || 1,
});

const uterranceRef = useRef<SpeechSynthesisUtterance | null>(null);

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 });
Expand Down

0 comments on commit f52f1f7

Please sign in to comment.