Merge pull request #128 from meetzaveri/patch-2
Create Speech_synthesis.md
This commit is contained in:
15
snippets/speech_synthesis-(experimental).md
Normal file
15
snippets/speech_synthesis-(experimental).md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
### Speech synthesis (experimental)
|
||||||
|
|
||||||
|
Use `SpeechSynthesisUtterance.voice` and `indow.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 speak = message => {
|
||||||
|
const msg = new SpeechSynthesisUtterance(message);
|
||||||
|
msg.voice = window.speechSynthesis.getVoices()[0];
|
||||||
|
window.speechSynthesis.speak(msg);
|
||||||
|
}
|
||||||
|
// speak('Hello, World') -> plays the message
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user