cheatsheets/js-speech.md

24 lines
488 B
Markdown
Raw Permalink Normal View History

2016-07-06 10:43:31 +02:00
---
title: JavaScript speech synthesis
2017-08-30 00:28:48 +02:00
category: JavaScript
weight: -1
2016-07-06 10:43:31 +02:00
---
2017-08-30 00:28:48 +02:00
## SpeechSynthesisUtterance
{: .-one-column}
2016-07-06 10:43:31 +02:00
```js
function speak (message) {
var msg = new SpeechSynthesisUtterance(message)
var voices = window.speechSynthesis.getVoices()
msg.voice = voices[0]
window.speechSynthesis.speak(msg)
}
```
2017-08-30 00:28:48 +02:00
```js
speak('Hello, world')
```
2016-07-06 10:43:31 +02:00
2017-08-30 00:28:48 +02:00
See: [SpeechSynthesisUtterance](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance) _(developer.mozilla.org)_