(Page 4 of 7 in this chapter)


2.3 Creating NaturalText Services

After initializing the CT Access environment, you can open NaturalText services by calling the function ctaOpenServices. Calling ctaOpenServices with the service name set to "TTS" and the service manager name set to "ADIMGR" establishes an instance of the NaturalText service.

When you open TTS services you must specify the MVIP address of the DSP resources that will be used for text-to-speech. This includes a board, stream, and timeslot. Typically, you pass the same values that were passed to the ADI service.

Opening the TTS service also secures a text-to-speech license. A license is required to run any NaturalText functions. For more information about obtaining licenses, refer to the NaturalText Installation Manual.

Note: If the TTS service cannot find the license configuration file specified by the NMSLMFDB environment variable, or if the password in the file is incorrect, opening the TTS service will return the event CTAEVN_OPEN_SERVICES_DONE with the reason CTAERR_NO_LICENSE.

Use the function ctaWaitEvent to retrieve the acknowledgment of ctaOpenServices and any events generated by the TTS service.

The following code sample shows a way to initialize the CT Access environment and open a NaturalText context:

/*******************************************************************************
                                DemoSetup

 Synchronously opens a port on a device with the basic CT Access services.
 Note: The TTS service is initialized here but not yet opened on the
 context.  This illustrates how to defer opening the TTS service, since
 it may be a scarce resource.
*******************************************************************************/
void DemoSetup(
    unsigned   ag_board,          /* AG board number                                  */
    unsigned   mvip_stream,    /* MVIP stream                                          */
    unsigned   mvip_slot,        /* MVIP timeslot                                      */
    CTAQUEUEHD *ctaqueuehd,    /* returned CT Access queue handle  */
    CTAHD           *ctahd)              /* returned CT Access context hd      */
{
    CTA_SERVICE_NAME servicelist[] =     /* for ctaInitialize */
    {   { "ADI", "ADIMGR" },
        { "TTS", "ADIMGR" },             /* Include the TTS service */
        { "SWI", "SWIMGR" },
        { "VCE", "VCEMGR" }
    };

    /* Note: The list of sevice descriptors below does not include
     * the TTS service.  See DemoOpenTTSService for code which opens
     * the NaturalText service ("TTS" ).  This is done
     * separately to show how TTS can be opened on an
     * as-needed basis. */

    CTA_SERVICE_DESC services[] =        /* for ctaOpenServices */
    {   { {"ADI", "ADIMGR"}, { 0 }, { 0 }, { 0 } },
        { {"SWI", "SWIMGR"}, { 0 }, { 0 }, { 0 } },
        { {"VCE", "VCEMGR"}, { 0 }, { 0 }, { 0 } }
    };

        /* DemoInitialize calls ctaInitialize */
    DemoInitialize( servicelist, sizeof(servicelist)/sizeof(servicelist[0]) );

    /* Fill in ADI service (index 0) MVIP address information */
    services[0].mvipaddr.board    = ag_board;
    services[0].mvipaddr.stream   = mvip_stream;
    services[0].mvipaddr.timeslot = mvip_slot;
    services[0].mvipaddr.mode     = ADI_FULL_DUPLEX;

    DemoOpenPort( 0, "DEMOCONTEXT", services,
                  sizeof(services)/sizeof(services[0]),
                  ctaqueuehd, ctahd );
}
/*****************************************************************************
                                DemoOpenPort
 Synchronously opens a port on a device.
*****************************************************************************/
void DemoOpenPort(
    unsigned      userid,                                    /*  for ctaCreateContext                          */
    char              *contextname,                        /*  for ctaCreateContext                          */
    CTA_SERVICE_DESC services[],                /*  for ctaOpenServices                            */
    unsigned      numservices,                          /*  number of "services"                          */
    CTAQUEUEHD  *ctaqueuehd,                          /*  returned CT Access queue handle    */
    CTAHD            *ctahd)                                    /*  returned CT Access context h          */
{
    CTA_EVENT event = { 0 };
    /* Open the Access application queue, attaching all defined serv managers.*/
    ctaCreateQueue( NULL, 0, ctaqueuehd );

    /* Create a CT Access context */
    ctaCreateContext( *ctaqueuehd, userid, contextname, ctahd );

    /* Open services */
    ctaOpenServices( *ctahd, services, numservices );

    /* Wait for services to be opened asynchronously. */
        /* DemoWaitForSpecificEvent calls ctaWaitEvent. */
    DemoWaitForSpecificEvent( *ctahd,
                               CTAEVN_OPEN_SERVICES_DONE, &event );
    if ( event.value != CTA_REASON_FINISHED )
    {
        DemoShowError( "Open services failed", event.value );
        exit( 1 );
    }
}
/*****************************************************************************
                                DemoOpenTTSService

 Synchronously open NaturalText on the given context.
*****************************************************************************/
void DemoOpenTTSService(
    CTAHD ctahd,
    unsigned   ag_board,                            /* AG board number                                        */
    unsigned   mvip_stream,                      /* MVIP stream                                                */
    unsigned   mvip_slot,                          /* MVIP timeslot                                         */
    TTS_VOICE  voice )                                /* Speaking voice:gender and language.*/
{
    CTA_EVENT event = { 0 };
    CTA_SERVICE_DESC services[] =        /* for ctaOpenServices */
{
{ {"TTS", "ADIMGR"}, { 0 }, { 0 }, { 0 } }
};
/* Fill in TTS service (index 0) MVIP address information */ services[0].mvipaddr.board = ag_board; services[0].mvipaddr.stream = mvip_stream; services[0].mvipaddr.timeslot = mvip_slot; services[0].mvipaddr.mode = ADI_FULL_DUPLEX; /* Fill in TTS service (index 0) MVIP voice argument */ services[0].svcargs.args[0] = voice; /* Open services */ ctaOpenServices( ctahd, services, sizeof(services)/sizeof(services[0]) ); /* Wait for services to be opened asynchronously */ DemoWaitForSpecificEvent( ctahd, CTAEVN_OPEN_SERVICES_DONE, &event ); if ( event.value != CTA_REASON_FINISHED ) { DemoShowError( "Open TTS Service failed.", event.value ); exit( 1 ); } }
To close a service, use the function ctaCloseServices with a specific CTA handle. The sample code that follows shows a way to close a TTS service:

/*****************************************************************************
                                DemoCloseTTSService

 Synchronously close NaturalText on the given context.
*****************************************************************************/
void DemoCloseTTSService( CTAHD ctahd )
{
    char *tts_service_names[] = { "TTS" };
    CTA_EVENT event = { 0 };

    ctaCloseServices( ctahd, tts_service_names,
sizeof(tts_service_names)/sizeof(tts_service_names[0]));
/* Wait for service to be closed asynchronously */ DemoWaitForSpecificEvent( ctahd, CTAEVN_CLOSE_SERVICES_DONE, &event ); if ( event.value != CTA_REASON_FINISHED ) { DemoShowError( "Close TTS Service failed.", event.value ); exit( 1 ); } }


(Page 4 of 7 in this chapter)


tech_support@nmss.com
Copyright © 1997, Natural MicroSystems, Inc. All rights reserved.