choo-stt

1.0.0 • Public • Published

choo-stt stability

npm version build status downloads js-standard-style

Simple speech-to-text in the browser for choo

Usage

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)
  })
}

Events

stt:error | stt.events.ERROR

Fired whenever there is an error related to speech recognition.

stt:audio-start | stt.events.AUDIO_START

Fired when the user agent has started to capture audio.

stt:audio-end | stt.events.AUDIO_END

Fired when the user agent has finished capturing audio.

stt:start | stt.events.START

Fired when the speech recognition service has begun listening to incoming audio.

stt:end | stt.events.END

Fired when the speech recognition service has disconnected.

stt:stop | stt.events.STOP

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.

stt:abort | stt.events.ABORT

Stops the speech recognition service from listening to incoming audio.

stt:no-match | stt.events.NO_MATCH

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.

stt:result | stt.events.RESULT

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.

stt:sound-start | stt.events.SOUND_START

Fired when any sound — recognisable speech or not — has been detected.

stt:sound-end | stt.events.SOUND_END

Fired when any sound — recognisable speech or not — has stopped being detected.

stt:speech-start | stt.events.SPEECH_START

Fired when sound that is recognised by the speech recognition service as speech has been detected.

stt:speech-end | stt.events.SPEECH_END

Fired when speech recognised by the speech recognition service has stopped being detected.

stt:set-command | stt.events.SET_COMMAND

Set a command. When this event is fired, it set a command so it executes a callback when the command pattern is listened.

API

stt = require('choo-stt')

  • 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. Defaults false.
  • state.stt.interimResults: Controls whether interim results should be returned true or not false. Interim results are results that are not yet final. Defaults false.
  • 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.

License

MIT

Package Sidebar

Install

npm i choo-stt

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • yerkopalma