@supunlakmal/hooks
Version:
A collection of reusable React hooks
30 lines (29 loc) • 1.16 kB
TypeScript
interface SpeechSynthesisOptions {
lang?: string;
pitch?: number;
rate?: number;
voice?: SpeechSynthesisVoice;
volume?: number;
}
interface UseSpeechSynthesisReturn {
/** Indicates if the Speech Synthesis API is supported by the browser. */
isSupported: boolean;
/** List of available voices. Might be empty initially and populate asynchronously. */
voices: SpeechSynthesisVoice[];
/** Boolean indicating if speech is currently in progress. */
speaking: boolean;
/** Function to initiate speech synthesis for the given text. */
speak: (text: string, options?: SpeechSynthesisOptions) => void;
/** Function to immediately stop any ongoing speech. */
cancel: () => void;
/** The error object if voices failed to load or speech failed. */
error: Error | null;
}
/**
* Hook to utilize the browser's Speech Synthesis API (Text-to-Speech).
* Provides controls to speak text, cancel speech, list available voices, and track status.
*
* @returns An object with speech synthesis state and control functions.
*/
export declare function useSpeechSynthesis(): UseSpeechSynthesisReturn;
export {};