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.
Include SpeechSynth.coffee in the /modules folder of your Framer Project.
Reference the module in your Framer project.
{SpeechSynth} = require "SpeechSynth"
- .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
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
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
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.
speech._utterance.onstart = (event) - >
do whatever
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!