speech-to-text
Advanced tools
Comparing version 0.4.4 to 0.4.7
@@ -28,8 +28,8 @@ 'use strict'; | ||
// Check to see if this browser supports speech recognition | ||
if (!('webkitSpeechRecognition' in window)) { | ||
throw new Error("This browser doesn't support speech recognition. Try Google Chrome."); | ||
if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) { | ||
throw new Error("This browser doesn't support speech recognition. Try Google Chrome or Firefox."); | ||
} | ||
var WebkitSpeechRecognition = window.webkitSpeechRecognition; | ||
this.recognition = new WebkitSpeechRecognition(); | ||
var SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition; | ||
this.recognition = new SpeechRecognition(); | ||
@@ -67,9 +67,14 @@ // Keep listening even if the speaker pauses, and return interim results. | ||
/* | ||
Explicitly start listening. | ||
Listening will need to be started again after a finalised result is returned. | ||
*/ | ||
_createClass(SpeechToText, [{ | ||
key: 'stopListening', | ||
value: function stopListening() { | ||
this.recognition.stop(); | ||
} | ||
/* | ||
Explicitly start listening. | ||
Listening will need to be started again after a finalised result is returned. | ||
*/ | ||
_createClass(SpeechToText, [{ | ||
}, { | ||
key: 'startListening', | ||
@@ -76,0 +81,0 @@ value: function startListening() { |
{ | ||
"name": "speech-to-text", | ||
"version": "0.4.4", | ||
"version": "0.4.7", | ||
"description": "A speech to text module.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -5,11 +5,12 @@ # Speech To Text | ||
It's designed to listen continuously to a user (i.e. pauses are ok), and then converting that speech to text. | ||
It's designed to listen continuously to a user (i.e. pauses are ok), and then | ||
converts that speech to text. | ||
## Install | ||
`npm install --save speech-to-text` | ||
`npm install speech-to-text` | ||
## Usage | ||
```` | ||
``` | ||
import SpeechToText from 'speech-to-text'; | ||
@@ -19,5 +20,6 @@ | ||
const onFinalised = text => console.log(`Finalised text: ${text}`); | ||
const onFinishedListening = () => console.log('Done listening.'); | ||
try { | ||
const listener = new SpeechToText(onAnythingSaid, onFinalised); | ||
const listener = new SpeechToText(onAnythingSaid, onFinalised, onFinishedListening); | ||
listener.startListening(); | ||
@@ -27,3 +29,3 @@ } catch (error) { | ||
} | ||
```` | ||
``` | ||
@@ -36,21 +38,35 @@ Demo [here](http://apps.golightlyplus.com/speech-to-text-demo/). | ||
- onAnythingSaid: this is a callback function that is called with text as it's being said | ||
- onFinalised: this is a callback function that is called with the full text as it has been resolved in the cloud. | ||
- onFinishedListening: this is a callback function that is called when the speech recognitions stops listening. | ||
- language: This is an optional string that specifies the language to be interpreted as. Default is United States English. 'en-US' | ||
- onAnythingSaid: this is a callback function that is called with text as it's | ||
being said. | ||
- onFinalised: this is a callback function that is called with the full text as | ||
it has been resolved in the cloud. | ||
- onFinishedListening: this is a callback function that is called when the | ||
speech recognitions stops listening. | ||
- language: This is an optional string that specifies the language to be | ||
interpreted as. Default is United States English. 'en-US' | ||
The constructor will throw an error if speech recognition is not supported by the browser. | ||
```` | ||
// Check to see if this browser supports speech recognition | ||
if (!('webkitSpeechRecognition' in window)) { | ||
throw new Error("This browser doesn't support speech recognition. Try Google Chrome."); | ||
The constructor will throw an error if speech recognition is not supported by | ||
the browser. | ||
``` | ||
if ( | ||
!('webkitSpeechRecognition' in window) && | ||
!('SpeechRecognition' in window) | ||
) { | ||
throw new Error("This browser doesn't support speech recognition. Try Google Chrome or Firefox."); | ||
} | ||
```` | ||
``` | ||
### startListening | ||
Initiates listening to speech input and will continue to call the callback functions provided until the speech recognition stops listening. After which you'll need to call this function again. | ||
Initiates listening to speech input and will continue to call the callback | ||
functions provided until the speech recognition stops listening. After which | ||
you'll need to call this function again. | ||
### stopListening | ||
Does just that. Stops listening. | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7366
82
69
5