Skip to content

Instantly share code, notes, and snippets.

@usmaanalii
Created August 23, 2017 07:39
Show Gist options
  • Save usmaanalii/c82e8b5c6d720ffa7d058869b894bb81 to your computer and use it in GitHub Desktop.
Save usmaanalii/c82e8b5c6d720ffa7d058869b894bb81 to your computer and use it in GitHub Desktop.

What I learned on this mini-project.

speechSynthesisUtterance

This is an interface for the Web Speech API. It contains the content that the speech service will read, as well as options that can be configured, such as language and pitch.

https://gist.github.com/42f72f3c149a214878b25254e2d6af1f

  • voiceschanged - This event listener can be used to attach an event to add voices to use.
  • getVoices() - Will extract the voices on the device being used as an array

SpeechSynthesis

This is the controller interface for the speech service, which can be used to get information about the voices available, on your particular device.

It can also be used to start and pause the speech.

https://gist.github.com/0f561e3b28f6ba5167cf56d2ec97fbca

Above, are example properties and methods that can be used to alter the state of the speech device.

Anonymous function

At times you may want to provide a parameter to a function to be used in an event listener. Unfortunately, doing this within a traditional function call will result in it being run on page load.

Using an anonymous function, you can avoid this problem

https://gist.github.com/195136e3b3c9df3351aa9fd7b5d669db

One caveat to this is that a new function will be created. Relying on this approach can cause unnecessary overhead to your code, which could have negative implications on your websites speed and efficiency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment