Last active
March 8, 2024 03:52
-
-
Save Virus5600/6652e0f6d08b296f48343a135268c419 to your computer and use it in GitHub Desktop.
Random Gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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