Last reviewed: 3/23/2024 9:14:27 AM

Event Handling

To receive error message, applications request event notifications. Event availability varies among Speech APIs.

EventEvent ArgumentsDescription
ApiErrorChantAPIErrorEventArgsNotifies the application of an API error

Some events provide data values that are returned in argument objects. Argument data availability varies among Speech APIs.

  • ChantAPIErrorEventArgs
    • Function - API funtion name
    • Message - API error message
    • RC - API error return code

Event notifications are recieved in callback routines as follows:


_Synthesizer = _LexiconKit.CreateSAPI5Synthesizer();
if (_Synthesizer != null)
{
    _Synthesizer.APIError += this.Syntheszier_APIError;
}

_Synthesizer = _LexiconKit->CreateSAPI5Synthesizer();
if (_Synthesizer != NULL)
{
    // Optionally, register Event Handler
    _Synthesizer->SetAPIError(APIError);
}
    

_Synthesizer = _LexiconKit->CreateSAPI5Synthesizer();
if (_Synthesizer != NULL)
{
    // Optionally, register Event Handler
    _Synthesizer->SetAPIError(APIError);
}
    

if (_Synthesizer <> nil) then
begin
    // Register Event Handler
    _Synthesizer.APIError := APIError;
end;
    

if (_Synthesizer != null)
{
    // Optionally, set the callback object
    _Synthesizer.setChantLexiconKitEvents(this);
    // Optionally, register for callback
    _Synthesizer.registerCallback(ChantLexiconKitCallback.CCAPIError);
}
    

_Synthesizer = _LexiconKit.CreateSAPI5Synthesizer()
// Declaring the event handlers routines with Handles clause in VB automatically registers for the event notifications
Private Sub Synthesizer_APIError(ByVal sender As System.Object, ByVal e As ChantAPIErrorEventArgs) Handles _Synthesizer.APIError
    

The recognizer and synthesizer objects send all notifications to the event handlers. All event data is contained in a arguments object.


private void Synthesizer_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 Synthesizer_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