feat: add rate option in useSpeech

This commit is contained in:
allen ge 2019-06-16 17:35:57 +08:00 committed by GitHub
parent 882a5f24e2
commit f52f1f7f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ 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,
});
@ -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 });