saiCreateRecognizer

Creates a recognizer instance and allocates recognizer engine resources.

Prototype

DWORD saiCreateRecognizer ( CTAHD ctahd, SAI_RTP_ENDPOINT *rtpEndpoint, char *server, DWORD clientObjId, SAI_RECOGNIZER_HANDLE *recogHd )

Argument

Description

ctahd

Context handle associated with a call.

rtpEndpoint

Pointer to the SAI_RTP_ENDPOINT structure specifying a client RTP endpoint where the RTP stream originates:

typedef struct
{    
DWORD                   port;    
SAI_URL                 ipAddress;
}
SAI_RTP_ENDPOINT;

For more information, refer to SAI_RTP_ENDPOINT.

server

Pointer to a URL associated with a speech server. This argument is optional. If the application specifies NULL, the speech engine controller uses the default speech server name.

clientObjId

(Optional). Application clientObjId to associate with the recognizer engine resource. All events associated with the new resource are associated with this clientObjId.

recogHd

Pointer to a returned SAI service recognizer handle associated with a recognizer resource.


Return values

Return value

Description

SUCCESS

 

SAIERR_INVALID_PARAMETER

One of the specified arguments is invalid.

CTAERR_INVALID_HANDLE

Specified ctahd is invalid.


Events

Event

Description

SAIEVN_ENGINE_CREATION_DONE

Command completed. The event statusCode field in the SAI_EVENT_ENGINE_CREATION event indicates the success or failure of the operation. If the command completed successfully (the status code is SC_CSC_OK), the application can use the returned recogHd. If the operation failed, the application must call saiReleaseRecognizer to release the returned recogHd.


Details

saiCreateRecognizer allocates a recognizer resource and associates it with a recogHd. When the speech server successfully allocates the new recognizer resource, the recognizer enters a ready state and the application receives SAIEVN_ENGINE_READY. The RTP port on which the server listens is returned in the enginePort field.

Note: From the time the application creates the recognizer to the time that the server responds to the request, the recognizer remains in an in-progress state. In this state, all requests from the application to the recognizer are rejected.

For more information, refer to Creating recognizer resources.

See also

saiCreateSynthesizer

Example

//
// The ASR must be associated to a CTA context.
// The RTP endpoint defines the source where the client generates the audio stream.
// It defines the endpoint with IP address and port number.
// The port number must be even as specified by RTP protocol.
// The asrHd returned by that function is used to refer to that ASR engine for all
// recognition command.
//
// The Application waits on the event queue to receive the SAIEVN_ENGINE_CREATION_DONE.
// This event returns the server RTP endpoint. The RTP endpoint defines the destination
// where the server terminates the audio stream. It contains IP address and port number.
//       
DWORD demoAsrCreate( CTAQUEUEHD queueHd, CTAHD ctxtHd, SAI_RECOGNIZER_HANDLE *asrHd,
                     SAI_RTP_ENDPOINT EpAsr, DWORD *serverPortAsr)
{
    DWORD rc = SUCCESS;
    CTA_EVENT event;
    SAI_EVENT_ENGINE_CREATION* eventResult = NULL;
    memset( &event, 0, sizeof (CTA_EVENT) );
    if (*asrHd != 0)
    {
        printf(" A ASR already exists.\n");
return !SUCCESS;
    }
    rc = saiCreateRecognizer( ctxtHd, EpAsr, g_server, 0, asrHd );
    if ( rc == SUCCESS )
    {
        //
        // Verify each event received in queue as long as the appropriate one
        // (in this case: SAIEVN_ENGINE_CREATION_DONE) is received or before timeout
        // is over.
        //
        rc = demoWaitForEvent( queueHd, &event, SAIEVN_ENGINE_CREATION_DONE, 0);
    }
    if ( rc == SUCCESS)
    {
//
// The buffer pointer contains a speech access event. Cast buffer according to the
        // event type.
//
eventResult = (SAI_EVENT_ENGINE_CREATION*) ( event.buffer );
//
// Verify that completion cause and status code are the same as buffer memory
//
if ( (eventResult != NULL) &&
     (eventResult->statusCode == SAI_SC_SUCCESS) )
{
    *serverPortAsr = eventResult->enginePort;
}
else
{
            printf("Status Code = 0x%08x.\n", eventResult->statusCode);
    rc = !SUCCESS;
}
    }
    if (rc == SUCCESS)
    {
        printf("Engine creation succeed on serverport = %d and on serverIp = %s.\n",
              *serverPortAsr, eventResult->engineIp);
    }
    else
    {
        printf("Engine creation failed, error code: 0x%08x.\n", rc);
    }
    return rc;
}