Appearance
useSpeechSynthesis
Reactive SpeechSynthesis
Demo
Usage
tsx
import { useSpeechSynthesis } from '@reause/core'
const {
isSupported,
isPlaying,
status,
utterance,
error,
stop,
toggle,
speak,
} = useSpeechSynthesis('Hello world')
// speak() — cancels the previous speech, then speaks with the current text/optionsOptions
The following shows the default values of the options, they will be directly passed to SpeechSynthesis API.
ts
import { useSpeechSynthesis } from '@reause/core'
useSpeechSynthesis('Hello world', {
lang: 'en-US',
pitch: 1,
rate: 1,
volume: 1,
})Type Declarations
ts
export type UseSpeechSynthesisStatus = 'init' | 'play' | 'pause' | 'end'
export interface UseSpeechSynthesisOptions extends ConfigurableWindow {
lang?: string;
pitch?: number;
rate?: number;
voice?: SpeechSynthesisVoice;
volume?: number;
onBoundary?: (event: SpeechSynthesisEvent) => void;
}
export interface UseSpeechSynthesisReturn {
isSupported: boolean;
isPlaying: boolean;
status: UseSpeechSynthesisStatus;
utterance: SpeechSynthesisUtterance | undefined;
error: SpeechSynthesisErrorEvent | undefined;
stop: () => void;
toggle: (value?: boolean) => void;
speak: () => void;
}
export function useSpeechSynthesis(text?: string, options?: UseSpeechSynthesisOptions): UseSpeechSynthesisReturn