Simple speech-to-text in the browser for choo
var choo = require('choo')
var html = require('choo/html')
var app = choo()
app.use(require('choo-stt')())
app.route('/', mainView)
app.mount('body')
function mainView (state, emit) {
return html`
<body>
<button onclick=${onclick}>Listen</button>
</body>
`
function onclick () {
emit('stt:start')
}
}
function listen (state, emitter) {
emitter.on('stt:result', function (result) {
console.log(result)
})
}
Fired whenever there is an error related to speech recognition.
Fired when the user agent has started to capture audio.
Fired when the user agent has finished capturing audio.
Fired when the speech recognition service has begun listening to incoming audio.
Fired when the speech recognition service has disconnected.
Emit this event to stops the speech recognition service from listening to incoming audio, and attempts to return a SpeechRecognitionResult using the audio captured so far.
Stops the speech recognition service from listening to incoming audio.
Fired when the speech recognition service returns a final result with no significant recognition. This may involve some degree of recognition, which doesn't meet or exceed the confidence threshold.
Fired when the speech recognition service returns a result — a word or phrase has been positively recognized and this has been communicated back to the app.
Fired when any sound — recognisable speech or not — has been detected.
Fired when any sound — recognisable speech or not — has stopped being detected.
Fired when sound that is recognised by the speech recognition service as speech has been detected.
Fired when speech recognised by the speech recognition service has stopped being detected.
Set a command. When this event is fired, it set a command so it executes a callback when the command pattern is listened.
state.stt.lang
: Returns or set the language of the current recognition. Defaults to Html lang element, or user agent lang if tag is not set.state.stt.continuos
: Controls whether continuous results are returned for each recognition, or only a single result. Defaultsfalse
.state.stt.interimResults
: Controls whether interim results should be returnedtrue
or notfalse
. Interim results are results that are not yet final. Defaultsfalse
.state.stt.maxAlternatives
: Sets the maximum number of SpeechRecognitionAlternatives provided per result. Defaults to 1.state.stt.serviceURI
: Specifies the location of the speech recognition service used by the current SpeechRecognition to handle the actual recognition. The default is the user agent's default speech service.