apphouse
Version:
Component library for React that uses observable state management and theme-able components.
83 lines (82 loc) • 2.48 kB
TypeScript
export interface IUtterance extends SpeechSynthesisUtterance {
id: string;
}
export type IUtteranceStatus = 'idle' | 'speaking' | 'ended' | 'error';
export interface IUtteranceOptions {
volume?: number;
rate?: number;
pitch?: number;
lang?: string;
voice?: SpeechSynthesisVoice;
onstart?: () => void;
onend?: () => void;
onerror?: () => void;
onpause?: () => void;
onresume?: () => void;
onmark?: () => void;
onboundary?: () => void;
}
/**
* A class that represents a speech synthesis utterance
* It is a wrapper around the SpeechSynthesisUtterance class
*/
export declare class Utterance {
id: string;
utterance?: SpeechSynthesisUtterance;
retryCount: number;
error: string | null;
status: IUtteranceStatus;
userOptions: IUtteranceOptions;
text: string;
rate: number;
volume: number;
pitch: number;
lang: string;
voice: SpeechSynthesisVoice;
mark: SpeechSynthesisEvent | null;
/**
* It marks the character position that has been read by the speech
* synthesis engine.
*/
readerIndex: number;
read: string;
unread: string;
constructor(id: string, text: string, options?: IUtteranceOptions);
restart: () => void;
setVolume: (volume: number) => void;
setRate: (rate: number) => void;
setMark: (mark: string) => void;
setVoice: (voice: SpeechSynthesisVoice) => void;
setPitch: (pitch: number) => void;
setReaderIndex: (index: number) => void;
/**
* Increments the retry count
*/
setRetry: () => void;
private setUtteranceOptions;
private isNotOfOverwrittenValues;
private setUtterance;
setRead: (read: string) => void;
setUnread: (unread: string) => void;
/**
* Sets the status of the utterance.
* Possible values: idle, active, ended, error.
* Use idle when the utterance has been created but not started.
* Use active when the utterance is being spoken.
* Use ended when the utterance has finished being spoken.
* Use error when the utterance has encountered an error.
* @param status IUtteranceStatus
*/
private setStatus;
/**
* Sets the error property in this utterance
* @param error the error
*/
private setError;
/**
* Sets the text property in this utterance.
* This is the text that will be spoken.
* @param text the text to speak
*/
setText: (text: string) => void;
}