Skip to content

Instantly share code, notes, and snippets.

@jagill
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagill/8ff45414c9ad640a409a to your computer and use it in GitHub Desktop.
Save jagill/8ff45414c9ad640a409a to your computer and use it in GitHub Desktop.
Listener tech spec
/*
* A Listener has four states: stopped, listening, continuous (listening), and stopping.
* (we'll handling pending/not-supported later).
* It starts off as stopped. It can be started normally, or in continuous mode.
*
* Listener Methods
* ================
*
* Listener.start (normal):
* listener.continous = false
* recognizer.continuous = listener.continous
* recognizer.start()
*
* Listener.start (continuous):
* listener.continous = true
* recognizer.continuous = listener.continuous
* set longListenTimeout # to handle Google's API from being unresponsive after 60 seconds.
*
* Listener.cancel:
* return if state == stopped
* listener.continuous = false
* recognizer.abort()
* clear abortTimeout
* clear finalizePendingTimeout
* clear longListenTimeout
*
* Listener.stop:
* return if state == stopped
* if state == stopping, listener.cancel() instead
* listener.continuous = false
* state = stopping
* recognizer.stop()
* if pendingResult:
* Should finalize pendingResult and emit? Would that duplicate?
* set abortTimeout # to handle chrome bug where it doesn't always end
* clear longListenTimeout
* clear finalizePendingTimeout
*
*
* Recognizer events
* =================
* onaudiostart: ignored
* onsoundstart: ignored
* onspeechstart: ignored
* onspeechend: ignored
* onsoundend: ignored
* onaudioend: ignored
* onnomatch: ignored for now
*
* onresult:
* clear finalizePendingTimeout
* if result.final:
* pendingResult = null
* emit result, naturalFinal = true
* else:
* if listener.interimResults:
* emit result
* pendingResult = result
* set finalizePendingTimeout
*
* onerror:
* "no-speech": ignore
* "aborted": ignore
* "audio-capture": emit
* "network": emit
* "not-allowed": emit
* "service-not-allowed": emit
* "bad-grammar": emit
* "language-not-supported": emit
*
* onstart:
* state = listening
* emit start
*
* onend:
* if continous == true:
* recognizer.start()
* else:
* state = stopped
* clearAbortTimeout
* emit end
*
*/
@swarajban
Copy link

#9: we'll also set the finalresult time out here

@swarajban
Copy link

#34: it should emit IMO bc the result was never finalized/emitted.

@swarajban
Copy link

#63: we fire this event currently right? It's annoying though bc we force abort a lot

@swarajban
Copy link

Can you also add descriptions/functionality for the 3 timeouts we have: longListen, onEndAbort, and setEarlyFinalResult?

@swarajban
Copy link

Thanks for putting this together. I think this gist should be our source of truth for what the listener should behave.

@swarajban
Copy link

#59: add if continuous

@swarajban
Copy link

#34: move to recognizer.onend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment