An awesome wrapper for the Chrome Speech(Synthesis) API
Use Chrome to speak text and or listen to voice input with ease (demo).
Just include blabla.js
into your project.
TODO: Add to bower / npm (for browserify)?
Blabla.speak('Hello!');
Blabla.setVoice('Monica');
Blabla.speak('Hola!');
Blabla.speaker.on('start', function () {
// Started speaking
});
Blabla.speaker.on('end', function () {
// Done speaking
});
var listener = Blabla.listen();
listener.start();
// Listen for 3 seconds
setTimeout(function () { listener.stop(); }, 3000);
Blabla.listener.on('result', function (data) {
var result = data.results[0][0];
console.log(result);
});
Blabla.listener.on('error', function (error) {
// Something went wrong (ie: timeout, no mic access)
});
Type: boolean
Check if the user's browser supports speaking and listening.
Example:
if (!Blabla.isSupported) alert('Please use Google Chrome');
Type: string
The text that will be spoken
Type: string
The voice to use for speaking (see Blabla.voices).
This is Blabla's public speaker, no need to assign it to a variable.
Type: string
Speaking has started
Type: string
Speaking has stopped
Type: string
There was an error while speaking
Type: Function
Function to run when event occurs, only has a parameter error
on the error event.
Type: Function
Returns: Object
Returns an object with a stop()
method to stop the listening.
Type: boolean
Default: false
When true, live listening will be enabled and `Blabla.listener.on('result', fn); will be called every time a new word is spoken.
This is Blabla's public listener, no need to assign it to a variable.
Type: string
Listening has started
Type: string
Listening has stopped
Type: string
There was an error while listening (ie: no acccess to microphone)
Type: string
Event for when we receive results from the SpeechSynthesisAPI
Type: Function
Has a parameter result
for the event result.
You will need to result.results which is another object
The result.results
object will have the following properties:
- [0-9999] (
number
) - Key, the result be will 0 with normal listening andresult.results.length - 1
for live listening. - isFinal (
boolean
) - Shows if it's the final result (used for live listening) - length (
number
) - Amount of results
[0-9999]: The result, another object
containing the following properties
- confidence (
float
) - 0-1, how sure Google is that the result is correct - transcript (
stirng
) - The spoken text by the user
To get the result you'll need to do something like result.results[0][0].transcript
.
Type: string
When Blabla.voices[] becomes available, this gets loaded. You can't access Blabla.voices onLoad because Chome loads the voices asynchronous. You generally only need this method if you want to list the voices.
Type: function
Function to execute after the voices are loaded.
Type: array
An array of objects containing voice objects.
MIT © Jilles Soeters