UNPKG

discussion

Version:

Basic implementating to help altering between ongoing SpeechRecognition and intermittant SpeechSynthesis

59 lines (58 loc) 2.49 kB
/// <reference types="dom-speech-recognition" /> export declare class Discussion { private factory; recognitionLanguageCode: string; synthesisLanguageCode: string; recognitionMaxAlternatives: number; /** * Results of the SpeechRecognition will arrive here */ onRecognitionResult: (ev: SpeechRecognitionEvent) => any; private recognition; private utterance; private preferedVoice; private isSynthesizing; private isRecognitionEnabled; private isGoodVoice; private voices; /** * Constructs the class. Make sure to call initialize() as well afterwards when your page is ready to go. * @param recognitionLanguageCode * @param synthesisLanguageCode * @param recognitionMaxAlternatives how many guesses for the recognition should be returned? (See https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/maxAlternatives) */ constructor(factory: () => SpeechRecognition, recognitionLanguageCode?: string, synthesisLanguageCode?: string, recognitionMaxAlternatives?: number); /** * Lists all available synthesis voices. This list will only be filled after initialize() was called * */ getSynthesisVoices(): SpeechSynthesisVoice[]; /** * Indicates whether the current synthesis language is installed locally (and thus faster in ending) * */ hasGoodVoice(): boolean; /** * Disable the recognition * */ disableRecognition(): void; /** * Re-enable the recognition * */ enableRecognition(): void; private toggleRecognition; /** * Setup the recognition and synthesis * */ initialize(): void; private initializeSynthesis; private initializeRecognition; /** * Synthesize something to the user * @param text what to say * @param pitch at which pitch to say it (from 0 to 2) * @param rate how fast to say it (from 0.1 to 10) * @param volume how loud to say it (from 0 to 1) * @recognitionWaitPeriod While synthesizing, the recognition has to be stopped. Set this parameter to start listening again after N milliseconds. Set this parameter to 0 to wait until the synthesis is completely over (may take +- 1 second AFTER the voice is finished). */ synthesize(text: string, pitch?: number, rate?: number, volume?: number, recognitionWaitPeriod?: number): void; private keepSpeechRecognitionAlive; }