Events
All SDK events are available in two formats: via the addEventListener()
method or using the on
properties of the IaraSpeechRecognition
object. In each case, the function will receive an event as parameter whose property detail
will contain data on Iara Health.
IMPORTANTE:: data related with the Iara Health are always propertydetail
of any event, example:event.detail
.
For example, given the dummy event result
, it can be accessed through addEventListener()
:
var recognition = new IaraSpeechRecognition();
recognition.addEventListener('result', function(event) {
// Iara Health related data are available
// through the `detail` property of any event.
console.log(event.detail);
});
Or by means of the property onresult
:
recognition.onresult = function(event) {
// Iara Health related data will be available
// via the `detail` property of any event.
console.log(event.detail);
}
To facilitate event discovery (and the IDEs code autocomplete), all the events released by the IaraSpeechRecognition
class are available as static properties of the IaraEvent
class.
Tip:IaraEvent
class contains all ready-to-use events. TypeIaraEvent
in your IDE in order to list the properties of that class (which are the available events).
The following sections describe, by subject, each of the available events and the content of their property detail
. All the examples shown underneath assume that a recognizer named recognition
has been instantiated:
var recognition = new IaraSpeechRecognition();
List of available events
The table below shows all the existing events, all accessible through IaraEvent.*
.
Event | Information |
---|---|
SPEECH_RECOGNITION_RESULT | - |
SPEECH_RECOGNITION_START | - |
SPEECH_RECOGNITION_STARTING | - |
SPEECH_RECOGNITION_STOP | - |
SPEECH_RECOGNITION_READY | - |
INIT_DONE | - |
INIT_FAIL | - |
INIT_VOICE_MODEL_DOWNLOAD_STARTED | - |
INIT_VOICE_MODEL_DOWNLOAD_COMPLETED | - |
INIT_VOICE_MODEL_DOWNLOAD_PROGRESS | - |
INIT_API_AUTH | - |
INIT_API_CONFIG | - |
INIT_ALS_CHECK | - |
INIT_INSTALL_ALS | - |
INIT_PROGRESS | - |
ALS_OFFLINE | - |
ALS_ONLINE | - |
AUDIO_LEVEL_UPDATE | - |
AUDIO_DEVICE_ADD | - |
AUDIO_DEVICE_REMOVE | - |
AUDIO_DEVICE_CHANGE | - |
SHORTCUT | - |
INTERNAL | - |
ERROR | - |
ERROR_NO_INPUT_DEVICE | - |
ERROR_UNSUPPORTED_SAMPLE_RATE | - |
ERROR_RECORD_INTERRUPTION | - |
NEWER_VOICE_MODEL_AVAILABLE | - |
NEWER_ALS_AVAILABLE | - |
The following sections explain and exemplify in more details each of the events listed above.
Voice recognition
Iara Health voice recognition related events. All those events are emitted after a successful boot has taken place.
Ready - IaraEvent.SPEECH_RECOGNITION_READY
and onready
Emitted when the recognizer is ready for receive input audio to make new inferences.
recognition.addEventListener(IaraEvent.SPEECH_RECOGNITION_READY, function(event) {
console.log(event.detail);
});
recognition.onready = function(event) {
console.log(event.detail);
}
Result - IaraEvent.SPEECH_RECOGNITION_RESULT
and onresult
Emitted when the recognizer finishes an inference.
recognition.addEventListener(IaraEvent.SPEECH_RECOGNITION_RESULT, function(event) {
console.log(event.detail);
});
recognition.onresult = function(event) {
console.log(event.detail);
}
See the section Voice recognition to learn more about the voice recognition, including obtaining intermediate results.
Start - IaraEvent.SPEECH_RECOGNITION_START
and onstart
Emitted when the recognizer starts the recognition process, i.e. shortly after start()
has been called.
recognition.addEventListener(IaraEvent.SPEECH_RECOGNITION_START, function(event) {
console.log(event.detail);
});
recognition.onstart = function(event) {
console.log(event.detail);
}
IMPORTANT: there may be a few milliseconds pause (or seconds, depending on user's computer) from the moment thatstart()
is called and the moment which the recognition actually begins. It happens because the ALS is setting the system audio channels. TheIaraEvent.SPEECH_RECOGNITION_START
andonstart
events indicate when the recognition properly started.
Stop - IaraEvent.SPEECH_RECOGNITION_STOP
and onstop
Emitted when the recognizer has been instructed to stop the current recognition, i.e. shortly after stop()
has been called.
recognition.addEventListener(IaraEvent.SPEECH_RECOGNITION_STOP, function(event) {
console.log(event.detail);
});
recognition.onstop = function(event) {
console.log(event.detail);
}
VAD Voice Start - IaraEvent.SPEECH_RECOGNITION_VAD_VOICE_START
Emitted when the useVAD option is true in the initialization and the VAD (voice activity detection) starts voice detection.
recognition.addEventListener(IaraEvent.SPEECH_RECOGNITION_VAD_VOICE_START, function(event) {
console.log(event.detail);
});
VAD Voice Stop - IaraEvent.SPEECH_RECOGNITION_VAD_VOICE_STOP
Emitted when the useVAD option is true in the initialization and the VAD (voice activity detection) stops voice detection.
recognition.addEventListener(IaraEvent.SPEECH_RECOGNITION_VAD_VOICE_STOP, function(event) {
console.log(event.detail);
});
Initialization
Emitted events during the Iara's recognizer initialization process.
Init done - IaraEvent.INIT_DONE
and oninitdone
Emitted when the recognizer has finished its initialization and is ready to work.
recognition.addEventListener(IaraEvent.INIT_DONE, function(event) {
console.log(event.detail);
});
recognition.oninitdone = function(event) {
console.log(event.detail);
}
Tip: thedone()
callback chained with the recognizer methodinit()
is a shortcut toIaraEvent.INIT_DONE
andoninitdone
.
The IaraEvent.INIT_DONE
and oninitdone
events are also available through the done() callback chained with method init() from the recognizer:
var recognition = new IaraSpeechRecognition();
recognition.init({
userId: 'meu@email.com',
apiToken: '197765800edb8affcb44a7ae7b4ff0a3'
}).done(function(e) {
// Initialization completed successfully
});
Init fail - IaraEvent.INIT_FAIL
and oninitfail
Emitted when the recognizer don't complete the initialization successfully. If this event is emitted, the recognizer won't be ready to do any voice recognition.
recognition.addEventListener(IaraEvent.INIT_FAIL, function(event) {
console.log(event.detail);
});
recognition.oninitfail = function(event) {
console.log(event.detail);
}
Tip: thefail()
callback chained with the recognizer methodinit()
is a shortcut toIaraEvent.INIT_FAIL
andoninitfail
.
The IaraEvent.INIT_DONE
and oninitdone
events are also available through the done() callback chained with method init() from the recognizer:
var recognition = new IaraSpeechRecognition();
recognition.init({
userId: 'meu@email.com',
apiToken: '197765800edb8affcb44a7ae7b4ff0a3'
}).fail(function(e) {
// Initialization has failed.
});
Init progress - IaraEvent.INIT_PROGRESSS
and oninitprogress
Emitted when the recognizer is initializing. During the initialization process, the recognizer goes through several steps, as authentication with the Iara API voice template download, etc.
For each of these steps, the events IaraEvent.INIT_PROGRESSS
and oninitprogress
will be called:
recognition.addEventListener(IaraEvent.INIT_PROGRESSS, function(event) {
console.log(event.detail);
});
recognition.oninitprogress = function(event) {
console.log(event.detail);
}
Every time that IaraEvent.INIT_PROGRESSS
and oninitprogress
are emitted, you could know the initialization steps/status through the type
propriety of the object detail
of the event passed as parameter, i.e. event.detail.type
.
The possible values to event.detail.type
are:
IaraEvent.INIT_VOICE_MODEL_DOWNLOAD_STARTED
: emitted when the recognizer started the download of user voice model identified by the proprietyuserId
used during the call toinit()
.IaraEvent.INIT_VOICE_MODEL_DOWNLOAD_PROGRESS
: several times emitted while the recognizer downloads the user voice model identified by the proprietyuserId
used during the call toinit()
. You can see the download progress by the proprietydata
of the objectdetail
of the event passed as paremeter, i.e.event.detail.data
.IaraEvent.INIT_VOICE_MODEL_DOWNLOAD_COMPLETED
: emitted when the recognizer completed download of the user voice model identified by the proprietyuserId
used during theinit()
call.
Tip: theprogress()
callback chained with the recognizer methodinit()
is a shortcut toIaraEvent.INIT_PROGRESSS
andoninitdone
.
All the initialization progress events, ex: IaraEvent.INIT_*
, are avaiable through the progress() callback chained with the recognizer's init() method:
var recognition = new IaraSpeechRecognition();
recognition.init({
userId: 'meu@email.com',
apiToken: '197765800edb8affcb44a7ae7b4ff0a3'
}).progress(function(e) {
// Initialization is taking place.
console.log(e.detail.type, e.detail.data);
});
Audio
Events linked to the control of audio input and output devices. See the audio's device section to learn more about configuring and choosing audio input and output.
Audio level update - IaraEvent.AUDIO_LEVEL_UPDATE
and onaudiolevelupdate
Emitted by the recognizer when audio is detected on the input device, after start()
has been called.
recognition.addEventListener(IaraEvent.AUDIO_LEVEL_UPDATE, function(event) {
console.log(event.detail);
});
recognition.onaudiolevelupdate = function(event) {
console.log(event.detail);
}
Tip: use the `IaraEvent.AUDIO_LEVEL_UPDATE` and `onaudiolevelupdate` events to improve the UX of your application. For example, after `start()` is called, you will see small vertical (sound) bars moving to indicate that audio is being captured by mic.
Errors
In order to facilitate error handling, the SDK triggers events related to the error in question. The relevant information can be accessed in event.detail
. Each error has:
- A single
errorCode
, that's represented below by the 'code' column; - A
developerMessage
, in order to explain the error cause to developer; - A
userMessage
, that's represent a message suggestion to be shown to the user.
Errors List
The table below show all existent errors and its descriptions.
Code | Event triggered | Message to the developer | Description |
---|---|---|---|
ERROR_RECORD_INTERRUPTION | Adding or removing audio devices when recording is not allowed. | Recording problem: a mic was added or removed while the recognition was active. (Code #1) | |
ERROR | Unknown error, please contact our team. | Unknown error: please, contact support. (Code #2) | |
ERROR | Unknown error, please contact our team. | Unknown audio error: please, contact support. (Code #3) | |
ERROR_RECORD_INTERRUPTION | Something affected the recording: + reason. | Recording problem: an unknown error has interrupted the recording. Please, contact support. (Code #4) | |
ERROR_NO_INPUT_DEVICE | No input device is available. | Unavailable mic: please, check if you have a mic connected. (Code #5) | |
ERROR | ALS seems to be permanently offline. | Iara's local service problem: please, restart "ALS". If the problem persists, please contact support. (Code #6) | |
ERROR | mediaDevices not supported by browser or insecure access (HTTP instead of HTTPS). | Unavailable mic: browser doesn't have secure access to the mic or it isn't supported. Please, contact support. (Code #7) | |
ERROR | Unable to create browser stream. | Audio error: please, contact support. (Code #8) | |
ERROR | Unable to enumerate input devices. | Unavailable microphone: wasn't possible verify if it has a mic connected. Please, restart "ALS". If the problem persists, please contact support. (Code #9) | |
UNSUPPORTED_SAMPLE_RATE | Browser mic has an unsupported sample rate for recording. | Unavailable microphone: wasn't possible to start the microphone. Please, contact support. (Code #10) | |
ERROR | Unable to record. | Record problem: unable recording. Please, contact support. (Code #11) | |
ERROR | Recording is disabled: + reason. | Record problem: previous recording is being processed. Ann error occurred, please, wait a minute or two and try again. If the problem persists, please contact support. (Code #12) | |
INIT_FAIL | Unauthorized access to Iara API. | Initialization has failed: invalid password or username. Please check your credentials. (Code #13) | |
INIT_FAIL | Incompatible OS or browser version. | Initialization is failed: browser or operational system incompatible with Iara. (Code #14) | |
INIT_FAIL | Problem reading Iara API SDK version info. | Initialization is failed: don't possible verify "Javascript SDK" version. Please, contact support. (Code #15) | |
INIT_FAIL | No suitable input method is available. Check your audio input devices. | Initialization failed: Could not detect an Iara compatible mic. (Code #18) | |
INIT_FAIL | No audio input device is available. Check if you have a valid mic or SpeechMike. | Initialization failed: Could not detect one mic. (Code #19) | |
INIT_FAIL | Requested input is invalid. Valid inputs are "auto" or "speechmike", for instance. | Initialization failed: an incompatible mic was select. (Code #20) | |
INIT_FAIL | ALS not installed. | Initialization failed: Iara's local service "ALS" don't be seems installed. (Code #21) | |
ERROR | The Iara speech recognition engine is busy. Please try again in a moment. | Iara's voice recognition engine is currently busy. Please try again in a few moments. (Code #22) | |
ERROR | Error dealing with the Iara API. | Communication failed with Iara's API. Please try again in a few moments. If the problem persists, please contact support. (Code #23) | |
ERROR | Unable to initialize. | Initialization has failed: unable initialize the voice recognizer engine. Please, contact support. (Code #24) | |
ERROR | Recorder already in use. | Iara is open in one more place. At this moment has not posible use voice recognize same time on several browser tabs. (Code #25) | |
ERROR | Recorder being forcefully disconnected. | Iara is open in one more place. At this moment has not posible use voice recognize same time on several browser tabs. (Code #26) | |
ERROR | Unable to generate audio log. | There was a problem with the audio file for registration purposes. You can continue using Iara normally. If the problem persists, please contact support. (Code #27) | |
ERROR | Unable to open audio line. | Audio error: unknow error don't has allowed record beging. Please, contact support. (Code #28) | |
ERROR | Unable to open and/or start playback line. | Audio error: unknow error don't has allowed audio's play. Please, contact support. (Code #29) | |
ERROR | Unable to open and/or start capture line. | Record problem: unable started recording. Check the mic connect. If the problem persists, please contact support. (Code #30) | |
ERROR | Recorder is busy. | Record problem: ALS recording local data is busy. Please try again in a few moments. If the problem persists, please, contact support. (Code #31) | |
ERROR | Unable to generate .ogg file. | There was a problem with the audio file for registration purposes. You can continue using Iara normally. If the problem persists, please, contact support. (Code #32) | |
ERROR | Invalid command. | Communication problem with my local service "ALS": Invalid message. (Code #33) | |
ERROR | Error selecting audio line. | Mic's unavailable: please, check if selected mic are still connect. (Code #34) | |
INIT_FAIL | The Iara speech recognition engine is busy. Please try again in a moment. | Iara's voice recognition engine is currently busy. Please try again in a few moments. (Code #35) | |
INIT_FAIL | Error dealing with the Iara API. | Initialization has failed: communication failed with Iara's API. Please try again in a few moments. If the problem persists, please contact support. (Code #36) | |
INIT_FAIL | Unable to initialize. | Initialization has failed: unable initialize the voice recognizer engine. Please, contact support. (Code #37) | |
INIT_FAIL | Recorder already in use. | Initialization has failed: Iara is open in one more place. At this moment has not posible use voice recognize same time on several browser tabs. (Code #38) | |
INIT_FAIL | Recorder being forcefully disconnected. | Initialization has failed: Iara is open in one more place. At this moment has not posible use voice recognize same time on several browser tabs. (Code #39) | |
INIT_FAIL | Unable to generate audio log. | Initialization has failed: There was a problem with the audio file for registration purposes. You can continue using Iara normally. If the problem persists, please contact support. (Code #40) | |
INIT_FAIL | Unable to open audio line. | Initialization failed: Audio error: unknown error don't have allowed recording start. Please, contact support. (Code #41) | |
INIT_FAIL | Unable to open and/or start playback line. | Initialization failed: Audio error: unknown error don't have allowed audio's play. Please, contact support. (Code #42) | |
INIT_FAIL | Unable to open and/or start capture line. | Initialization failed: Record problem: unable started recording. Check the mic is connect. If the problem persists, please contact support. (Code #43) | |
INIT_FAIL | Recorder is busy. | Initialization failed: record problem: "ALS" recording local service is busy. Please try again in a few moments. If the problem persists, please, contact support. (Code #44) | |
INIT_FAIL | Unable to generate .ogg file. | Initialization has failed: There was a problem with the audio file for registration purposes. You can continue using Iara normally. If the problem persists, please, contact support. (Code #45) | |
INIT_FAIL | Invalid command. | Initialization has failed: Communication problem with my local service "ALS": Invalid message. (Code #46) | |
INIT_FAIL | Error selecting audio line. | Initialization has failed: mic's unavailable: please, check if selected mic are still connect. (Code #47) | |
INIT_FAIL | The installed ALS version is outdated and incompatible with this SDK version. | Initialization has failed: The version installed ALS local service is incompatible or is outdated. (Code #48) | |
INIT_FAIL | ALS closed all currently active connections due to forceConnect (probably multiple tabs are open). | Initialization failed: Iara's local service "ALS" seems to have closed all connections. It may be that Iara is started in more than one tab of your browser. (Code #49) | |
INIT_FAIL | Invalid response from Iara API. | Initialization has failed: communication failed with Iara's API. Please try again in a few moments. If the problem persists, please contact support. (Code #50) | |
ERROR | Failed to submit the feedback to the Iara API. Reason: + reason. | Error: failed to submit feedback. (Code #51) | |
ERROR | Unable to properly initialize ALS protocols that use the UserAgent. You can try to restart the ALS and refresh the page to fix the problem and, if that doesn't work, try reinstalling the ALS. | Local service problem: unable to initialize ALS protocols correctly disabling the functionality of shortcuts for recording, copy report and the external editor. Please, can try to restart the ALS and refresh the page to fix the problem and, if that doesn't work, try reinstalling the ALS. (Code #53) | |
ERROR | Unable to run the recognition engine for the given audio file. Please, check that the file is in proper wav 44100Hz format. | Problem running voice recognition engine with given audio file. Please, check that the file is in proper wav 44100Hz format. (Code #54) | |
ERROR | Failed to update or create a report. | Failed to update or create a report. (Code #55) | |
INIT_FAIL | User license has expired. | User license has expired. Please, check that there aren't outstanding payments. (Code #56) | |
ERROR | Failed to fetch user parser rules. | Failed to fetch user parser rules. (Code #57) | |
INIT_FAIL | User denied mic usage permission. | Initialization has failed: recognition needs permission for browser mic access. (Code #58) | |
INIT_FAIL | Failed to update the user parser rules in the speech engine. | Failed to fetch user parser rules. (Code #59) |