# Creating recognizer resources

After initializing the Universal Speech Access API, applications use USAI functions to request automatic speech recognition (ASR) resources from a speech server. Each recognizer resource is associated with a specific NaturalAccess context.

Applications invoke saiCreateRecognizer to allocate recognizer resources. When using saiCreateRecognizer, the application must specify the following:

- NaturalAccess context handle.

- Incoming Fusion RTP endpoint information, including the IP address and the port number to transmit over.

- (Optional) Name of a speech server where recognizer requests are directed. If no speech server is specified, USAI defaults to the first server defined in the saiconfig.xml file.

- (Optional) Client object identifier that USAI associates with any events returned for the recognizer resource.

- Pointer to a recognizer handle container to receive the created recognizer handle.

saiCreateRecognizer is an asynchronous function. When saiCreateRecognizer completes successfully (indicating that all specified parameters are valid), USAI sends a setup command to the speech server requesting a new recognizer resource according to the specified parameters. USAI returns a recognizer handle (recog Hd) that the application references in subsequent requests to the resource. However, the application must wait for USAI to return SAIEVN_ENGINE_READY for the specified recognizer before making any requests with the returned recog Hd.

Note: After an application invokes saiCreateRecognizer, the only command that USAI can execute before the return of SAIEVN_ENGINE_READY is saiReleaseRecognizer.

The following illustration shows NaturalAccess and Universal Speech Access API interaction when creating recognizer resources:

The following example shows how an application creates an Universal Speech Access API recognizer resource:

DWORD rc = SUCCESS;
CTAQUEUEHD queueHd;
CTAHD contextHd;
SAI_RECOGNIZER_HANDLE recogHd;
CTA_SERVICE_NAME cta_srvc_name;
CTA_INIT_PARMS cta_init_parms;
CTA_SERVICE_DESC cta_srvc_desc;
SAI_URL g_server = "SpeechServer";
SAI_RTP_ENDPOINT rtpEndpoint;
CTA_EVENT *event;
// Initialize Natural Access environment
ctaInitialize(cta_srvc_name,cta_init_parm)
ctaCreateQueue(NULL, 0, queueHd)
ctaCreateContext(queueHd, 0, NULL, contextHd)
ctaOpenServices(contextHd, cta_srvc_desc, 1)
rtpEndPoint.Port = 2000;
rtpEndPoint.ipAddress = "10.10.1.1"
rc = saiCreateRecognizer(contextHd, rtpEndpoint, g_server, 0, recogHd );
if ( rc == SUCCESS )
{
// Wait for SAIEVN_ENGINE_READY or SAIEVN_ENGINE_FAIL
rc = ctaWaitEvent( queueHd, event, 0 );
if ( (rc == SUCCESS) && (event == SAIEVN_ENGINE_READY))
{
SAI_EVENT_ENGINE_READY* serverPort = (SAI_EVENT_ENGINE_READY*) (event->buffer );
printf("Engine created successfuly, Port # :%d\n", serverPortàenginePort);
}
else if((rc == SUCCESS) && (event == SAIEVN_ENGINE_FAIL))
{
printf("Engine creation failed, engine not ready.\n");
}
}
else
{
printf("saiCreateRecognizer failed.\n");