Last reviewed: 3/23/2024 9:34:16 AM
Event Handling
To track the progress of backup and restore operations, applications receive event notifications. Event availability varies among Speech APIs.
Event | Event Arguments | Description |
---|---|---|
ApiError | ChantAPIErrorEventArgs | Notifies the application of an API error |
AudioSourceStart | AudioEventArgs | Notifies the application the speech recognizer has started processing audio |
AudioSourceStop | AudioEventArgs | Notifies the application the speech recognizer has stopped processing audio |
FalseRecognition | SREventArgs | Notifies the application the speech recognizer was unable to recognize speech from the utterance |
Interference | InterferenceEventArgs | Notifies the application the speech recognizer detected interference |
Recognition | RecognitionEventArgs | Notifies the application the speech recognizer recognized speech |
Sound | SREventArgs | Notifies the application the speech recognizer detected sound |
UtteranceBegin | SREventArgs | Notifies the application the speech recognizer detected the beginning of an utterance |
UtteranceEnd | SREventArgs | Notifies the application the speech recognizer detected the end of an utterance |
Some events provide data values that are returned in argument objects. Argument data availability varies among Speech APIs.
-
AudioEventArgs
- File - File name
- AudioStreamOffset - Audio stream offset
- AudioTimeOffset - Audio time offset
-
ChantAPIErrorEventArgs
- Function - API funtion name
- Message - API error message
- RC - API error return code
-
InterferenceEventArgs
- Interference - The type of interference detected by the recognizer
- AudioStreamOffset - Audio stream offset
- AudioTimeOffset - Audio time offset
-
RecognitionEventArgs
- Text - Recognized speech
- Property - Recognized speech property value
- AudioStreamOffset - Audio stream offset
- AudioTimeOffset - Audio time offset
-
SREventArgs
- AudioStreamOffset - Audio stream offset
- AudioTimeOffset - Audio time offset
Event notifications are recieved in callback routines as follows:
if (_Recognizer != null)
{
_Recognizer.APIError += this.Recognizer_APIError;
}
// Static event handler declaration
void CALLBACK APIError(void* Sender, CChantAPIErrorEventArgs* Args);
...
if (_Recognizer != NULL)
{
// Optionally, register Event Handler
_Recognizer->SetAPIError(APIError);
}
// Static event handler declaration
void CALLBACK APIError(void* Sender, CChantAPIErrorEventArgs* Args);
...
if (_Recognizer != NULL)
{
// Optionally, register Event Handler
_Recognizer->SetAPIError(APIError);
}
if (_Recognizer <> nil) then
begin
// Register Event Handler
_Recognizer.APIError := APIError;
end;
_Recognizer = _ProfileKit.createSAPI5Recognizer();
if (_Recognizer != null)
{
// Optionally, set the callback object
_Recognizer.setChantProfileKitEvents(this);
// Optionally, register for callback
_Recognizer.registerCallback(ChantProfileKitCallback.CCAPIError);
}
_Recognizer = _ProfileKit.CreateSAPI5Recognizer()
// Declaring the event handlers routines with Handles clause in VB automatically registers for the event notifications
Private Sub Recognizer_APIError(ByVal sender As System.Object, ByVal e As ChantAPIErrorEventArgs) Handles _Synthesizer.APIError
The recognizer object send all notifications to the event handlers. All event data is contained in a arguments object.
private void Recognizer_APIError(object sender, ChantAPIErrorEventArgs e)
{
// Format transcript message
string errorMsg = "";
errorMsg = "(" + e.RC.ToString() + ") ";
errorMsg += " " + e.Function.ToString() + " ";
errorMsg += e.Message;
...
}
void CALLBACK APIError(void* Sender, CChantAPIErrorEventArgs* Args)
{
// Format transcript message
CString strErrorMsg;
strErrorMsg.Format(L"(%d) %s %s\r\n", Args->GetRC(), Args->GetFunction(), Args->GetMessage());
...
}
void CALLBACK APIError(void* Sender, CChantAPIErrorEventArgs* Args)
{
// Format transcript message
String strErrorMsg = "(" + IntToStr(Args->GetRC()) + ") ";
strErrorMsg = strErrorMsg + " " + Args->GetFunction() + " " + Args->GetMessage() + "\r\n";
...
}
procedure TForm1.APIError(Sender: TObject; Args: TChantAPIErrorEventArgs);
var
strErrorMsg: string;
begin
strErrorMsg := '';
strErrorMsg := '(' + IntToStr(Args.RC) + ') ';
strErrorMsg := strErrorMsg + ' ' + IntToStr(Args.Function) + ' ' + Args.Message + #13 + #10;
...
end;
public void apiError(Object sender, ChantAPIErrorEventArgs args)
{
System.out.println(
String.format("(%d) %s %s", args->getRC(), args->getFunction(), args->getMessage())
);
}
Private Sub Recognizer_APIError(ByVal sender As System.Object, ByVal e As ChantAPIErrorEventArgs) Handles _Synthesizer.APIError
Dim errorMsg As String
' Format transcript message
errorMsg = "(" + e.RC.ToString() + ") "
errorMsg += " " + e.Function.ToString() + " "
errorMsg += e.Message
...
End Sub