Skip to content

joshmtucker/SpeechSynth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

SpeechSynth

Framer module for Web SpeechSynthesis. As documented in Web Speech API Specification.

Check out AfricanAnimals.framer to see SpeechSynth in action.

A great getting started guide on understanding how Web SpeechSynthesis works is available from Treehouse.

How to use

Include SpeechSynth.coffee in the /modules folder of your Framer Project.

Reference the module in your Framer project.

{SpeechSynth} = require "SpeechSynth"

Properties

  • .voices array Names of all supported voices
  • .text – string Text speechSynthesis reads
  • .voice – string Name of voice
  • .lang – string Language code for voice
  • .volume – number Between 0 and 1
  • .rate – number Speed of spoken text (between 1 and 10)
  • .pitch – number Between 0 and 2

NOTES:

Not all voices support each language, rate, or pitch value.

If you wish to grab the raw voice objects from speechSynthesis, you can access them through the SpeechSynth variable.

speech._voices

Example

Add properties at creation.

speech = new SpeechSynth 
	text: "Hello world" 
	voice: "Samantha"
	volume: 1
	rate: 1.25

OR

Add properties individually.

speech = new SpeechSynth
speech.text = "Hello world"
speech.volume = .5

Methods

Start speaking.

speech.speak()

Remove all utterances from queue. Whenever you call .speak(), said utterance is queued. The speechSynthesis will continue to speak as long as there are utterances in queue.

speech.cancel()

Pause speaking.

speech.pause()

Resume if paused.

# Returns true or false
speech.resume()

Check if speechSynthesis has any pending utterances. (queued)?

# Returns true or false
speech.isPending

Check if speechSynthesis is currently speaking.

# Returns true or false
speech.isSpeaking

Check if speechSynthesis is currently paused.

# Returns true or false
speech.isPaused

Advanced

The SpeechSynthesisUtterance object (the object that handles all the properties listed above) has support for events. You can listen for events like:

  • start
  • end
  • pause
  • resume

Full list available in Web Speech API Specification.

To listen to such events, reference the root SpeechSynthesisUtterance variable.

Example

speech._utterance.onstart = (event) - >
	do whatever

API Status

Web Speech Synthesis API is a little janky as is – in both Chrome and Safari. You may run into some problems with certain events and methods not firing. Bear with me – some of it is out my control, however I am open to any suggestions on improving the framework of the module.

Cheers!

About

Framer module for Web SpeechSynthesis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages