# Initializing USAI

Before calling functions from the USAI, the application initializes NaturalAccess and opens the required NaturalAccess APIs, including USAI.

To set up NaturalAccess:

Step | Action
1 | Initialize NaturalAccess and its services.
2 | Create event queues and contexts (associated with existing event queues).
3 | Opening Universal Speech Access API instances on contexts.

## Initializing NaturalAccess

To initialize NaturalAccess and its services, invoke ctaInitialize and specify the names of the services and service managers the application will use.

The following table lists some of the APIs and service managers that Universal Speech Access applications can use:

This API... | With this service manager... | Provides...
ADI | ADIMGR | DTMF detection and tone generation
NCC | ADIMGR | PSTN call control
MSPP | MSPMGR | RTP endpoint control
USAI | SAIMGR | Universal Speech Access API speech recognition and speech synthesis

For a list of the standard NaturalAccess APIs, refer to the Dialogic® NaturalAccess™ Software Developer’s Manual.

## Creating event queues and contexts

After initializing NaturalAccess and its services, the application creates event queues and contexts.

Step | Action
1 | Create one or more event queues by invoking ctaCreateQueue. Specify which service managers to attach to each queue. USAI uses the SAIMGR service manager.
2 | Create contexts by invoking ctaCreateContext and providing a queue handle (ctaqueuehd) returned from a previous call to ctaCreateQueue. Events for any services opened on the context are later routed to the associated event queue.

ctaCreateContext returns a context handle (ctahd). The application must specify a valid ctahd when invoking USAI functions. Events communicated back to the application are associated with the specified context handle. For information about NaturalAccess programming models and managing contexts and queues, refer to the Dialogic® NaturalAccess™ Software Developer’s Manual.

## Opening Universal Speech Access API instances

Opening an API on a context creates a service instance on that context. To open a USAI instance on a context, invoke ctaOpenServices and specify:

- A ctahd.

- The type of API (for example, USAI) to open.

- The appropriate service manager (for example, SAIMGR) for the specified API.