Skip to content

Commit

Permalink
Web speech API - minor fixes (#10706)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee authored Nov 23, 2021
1 parent 258d2b8 commit e6242a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion files/en-us/web/api/web_speech_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ For more details on using these features, see [Using the Web Speech API](/en-US/
- : The controller interface for the recognition service; this also handles the {{domxref("SpeechRecognitionEvent")}} sent from the recognition service.
- {{domxref("SpeechRecognitionAlternative")}}
- : Represents a single word that has been recognized by the speech recognition service.
- {{domxref("SpeechRecognitionError")}}
- {{domxref("SpeechRecognitionError")}} {{deprecated_inline}}
- : Represents error messages from the recognition service.
- {{domxref("SpeechRecognitionEvent")}}
- : The event object for the {{event("result")}} and {{event("nomatch")}} events, and contains all the data associated with an interim or final speech recognition result.
Expand Down
14 changes: 4 additions & 10 deletions files/en-us/web/api/window/speechsynthesis/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,24 @@ title: Window.speechSynthesis
slug: Web/API/Window/speechSynthesis
tags:
- API
- Experimental
- Property
- Reference
- SpeechSynthesis
- Window
browser-compat: api.Window.speechSynthesis
---
{{APIRef()}}{{SeeCompatTable}}
{{APIRef()}}

The `speechSynthesis` read-only property of the Window object returns a {{domxref("SpeechSynthesis")}} object, which is the entry point into using [Web Speech API](/en-US/docs/Web/API/Web_Speech_API) speech synthesis functionality.

## Syntax

```js
var synth = window.speechSynthesis;
```

### Value
## Value

A {{domxref("SpeechSynthesis")}} object.

## Examples

In our basic [Speech synthesiser demo](https://github.com/mdn/web-speech-api/tree/master/speak-easy-synthesis), we first grab a reference to the SpeechSynthesis controller using `window.speechSynthesis`. After defining some necessary variables, we retrieve a list of the voices available using {{domxref("SpeechSynthesis.getVoices()")}} and populate a select menu with them so the user can choose what voice they want.
In our basic [Speech synthesiser demo](https://github.com/mdn/web-speech-api/tree/master/speak-easy-synthesis), we first grab a reference to the SpeechSynthesis controller using `window.speechSynthesis`.
After defining some necessary variables, we retrieve a list of the voices available using {{domxref("SpeechSynthesis.getVoices()")}} and populate a select menu with them so the user can choose what voice they want.

Inside the `inputForm.onsubmit` handler, we stop the form submitting with [preventDefault()](/en-US/docs/Web/API/Event/preventDefault),  create a new {{domxref("SpeechSynthesisUtterance")}} instance containing the text from the text {{htmlelement("input")}}, set the utterance's voice to the voice selected in the {{htmlelement("select")}} element, and start the utterance speaking via the {{domxref("SpeechSynthesis.speak()")}} method.

Expand Down

0 comments on commit e6242a4

Please sign in to comment.