Skip to content

Instantly share code, notes, and snippets.

@Virus5600
Last active March 8, 2024 03:52
Show Gist options
  • Save Virus5600/6652e0f6d08b296f48343a135268c419 to your computer and use it in GitHub Desktop.
Save Virus5600/6652e0f6d08b296f48343a135268c419 to your computer and use it in GitHub Desktop.
Random Gists
/**
* Synthesizes speech from the provided text using the Web Speech API.
* @param {string} text - The text to be synthesized.
* @param {string} voiceName - The name of the voice to be used.
*/
function speak(text, voiceName) {
const utterance = new SpeechSynthesisUtterance(text);
const voices = window.speechSynthesis.getVoices();
// Find the voice with the specified name
const voice = voices.find(v => v.name === voiceName);
if (voice) {
utterance.voice = voice;
}
window.speechSynthesis.speak(utterance);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment