Speak a Text Message
Create a SpeechSynthesisUtterance, set its text and language, and pass it to the global speechSynthesis object. Check availability first.
Complete the Example
Create a SpeechSynthesisUtterance, set its text and language, and pass it to the global speechSynthesis object. Check availability first.
if (
typeof speechSynthesis !== 'undefined' &&
typeof SpeechSynthesisUtterance !== 'undefined'
) {
const utterance = new SpeechSynthesisUtterance('Welcome to AIUI');
utterance.lang = 'zh-CN';
speechSynthesis.speak(utterance);
}
See Speech Synthesis for voices, rate, and events.