SpeechSynthesis API. Here’s an example of how you can use it to create custom voices:
const synth = window.speechSynthesis; // Get all available voices const voices = synth.getVoices(); // Set up the options for the speech synthesis const utterance = new SpeechSynthesisUtterance("Hello, World!"); utterance.pitch = 1; utterance.rate = 1; utterance.voice = voices; // Use the first available voice // Speak the text using the speech synthesis API synth.speak(utterance);
In the above example, the
SpeechSynthesis API is first accessed through the
window object. Then, the
getVoices() method is used to retrieve an array of all available voices.
SpeechSynthesisUtterance object is then created with the text to be spoken. The
voice properties are set to customize the speech synthesis. Finally, the
speak() method is used to start the speech synthesis.
Note that the
SpeechSynthesis API is not supported by all browsers, so be sure to check for compatibility before using it in your project.