Files
30-seconds-of-code/snippets_archive/speechSynthesis.md
Angelos Chalaris 0425ebefe7 Archive, multitagging, cleanup
Cleaned up the current snippets for consistency and minor problems, added multiple tags to most of them, archived a few.
2018-01-05 16:33:54 +02:00

21 lines
651 B
Markdown

### speechSynthesis
Performs speech synthesis (experimental).
Use `SpeechSynthesisUtterance.voice` and `window.speechSynthesis.getVoices()` to convert a message to speech.
Use `window.speechSynthesis.speak()` to play the message.
Learn more about the [SpeechSynthesisUtterance interface of the Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance).
```js
const speechSynthesis = message => {
const msg = new SpeechSynthesisUtterance(message);
msg.voice = window.speechSynthesis.getVoices()[0];
window.speechSynthesis.speak(msg);
};
```
```js
speechSynthesis('Hello, World'); // // plays the message
```