Skip to main content

Speech Component

API Reference

Here is the full API for the <Speech> component, these properties can be set on an instance of <Speech>:

ParameterTypeRequiredDefaultDescription
textstring | JSX.ElementYes-It contains the text to be spoken by Web Speech API.
pitchnumber (0 to 2)No1The pitch at which the utterance will be spoken.
ratenumber (0.1 to 10)No1The speed at which the utterance will be spoken.
volumenumber (0 to 1)No1The volume at which the utterance will be spoken.
langstringNo-The language in which the utterance will be spoken.
voiceURIstring | string[]No-The voice using which the utterance will be spoken. If provided an array, further voices will be used as fallback if initial voices are not found. See possible values here.
highlightTextbooleanNofalseWhether the words in the text should be highlighted as they are read or not.
highlightPropsReact.DetailedHTMLPropsNo-Props to customize the highlighted word, typically applied to the <mark> tag.
preserveUtteranceQueuebooleanNofalseWhether to maintain a queue of speech utterances (true) or clear previous utterances (false).
startBtnButtonNo<HiVolumeUp />Button to start the speech instance.
pauseBtnButtonNo<HiVolumeOff />Button to pause the speech instance.
stopBtnButtonNo<HiMiniStop />Button to stop the speech instance.
useStopOverPausebooleanNofalseWhether the controls should display stopBtn instead of pauseBtn. In Android devices, SpeechSynthesis.pause() behaves like SpeechSynthesis.cancel(). See details
propsReact.DetailedHTMLPropsNo-Props to customize the <Speech> component.
childrenChildrenNo-See usage with FaC
onErrorSpeechSynthesisErrorHandlerNoconsole.errorFunction to be executed if browser doesn't support Web Speech API.
onStartSpeechSynthesisEventHandlerNo-Function to be executed when speech utterance is started.
onResumeSpeechSynthesisEventHandlerNo-Function to be executed when speech utterance is resumed.
onPauseSpeechSynthesisEventHandlerNo-Function to be executed when speech utterance is paused.
onStopSpeechSynthesisEventHandlerNo-Function to be executed when speech utterance is stopped.
onBoundarySpeechSynthesisEventHandlerNo-Function to be executed at specified boundaries during speech synthesis.
onQueueChangeQueueChangeEventHandlerNo-Function to be executed whenever queue changes.

Types

Button

type Button = JSX.Element | string | null;

Children

import { ReactNode } from "react";
type SpeechStatus = "started" | "paused" | "stopped" | "queued";
type ChildrenOptions = {
speechStatus?: SpeechStatus;
isInQueue?: boolean;
start?: Function;
pause?: Function;
stop?: Function;
};
type Children = (childrenOptions: ChildrenOptions) => ReactNode;

SpeechSynthesisErrorHandler

type SpeechSynthesisErrorHandler = (error: Error) => any;

SpeechSynthesisEventHandler

type SpeechSynthesisEventHandler = (event: SpeechSynthesisEvent) => any;

QueueChangeEventHandler

type SpeechUtterancesQueue = SpeechSynthesisUtterance[];
type QueueChangeEventHandler = (queue: SpeechUtterancesQueue) => any;