1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2026-08-16 05:54:53 +02:00
Files
cheatsheets/js-speech.md
Rico Sta. Cruz f7c9650a56 Update
2017-08-30 06:28:48 +08:00

25 lines
507 B
Markdown

---
title: JavaScript speech synthesis
category: JavaScript
layout: 2017/sheet
weight: -1
---
## SpeechSynthesisUtterance
{: .-one-column}
```js
function speak (message) {
var msg = new SpeechSynthesisUtterance(message)
var voices = window.speechSynthesis.getVoices()
msg.voice = voices[0]
window.speechSynthesis.speak(msg)
}
```
```js
speak('Hello, world')
```
See: [SpeechSynthesisUtterance](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance) _(developer.mozilla.org)_