mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
feat: add rate option in useSpeech
This commit is contained in:
parent
882a5f24e2
commit
f52f1f7f0f
@ -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 });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user