The SpeechSynthesis interface of the Web Speech API is the controller interface for the speech service; this can be used to retrieve information about the synthesis voices available on the device, start and pause speech, and other commands besides.
Instance properties
SpeechSynthesis also inherits properties from its parent interface, EventTarget.
let utterance =newSpeechSynthesisUtterance("Hello world!");
speechSynthesis.speak(utterance);
Now we'll look at a more fully-fledged example. In our Speech synthesizer demo, we first grab a reference to the SpeechSynthesis controller using window.speechSynthesis. After defining some necessary variables, we retrieve a list of the voices available using SpeechSynthesis.getVoices() and populate a select menu with them so the user can choose what voice they want.
Inside the inputForm.onsubmit handler, we stop the form submitting with preventDefault(), create a new SpeechSynthesisUtterance instance containing the text from the text <input>, set the utterance's voice to the voice selected in the <select> element, and start the utterance speaking via the SpeechSynthesis.speak() method.