Creates a synthesizer instance and allocates synthesizer engine resources.
DWORD saiCreateSynthesizer ( CTAHD ctahd, SAI_RTP_ENDPOINT rtpEndpoint, char *server, DWORD clientObjId, SAI_SYNTHESIZER_HANDLE *synthHd )
|
Argument |
Description |
|
ctahd |
NaturalAccess context handle associated with a call. |
|
rtpEndpoint |
SAI_RTP_ENDPOINT structure that specifies a client RTP endpoint where the RTP stream terminates: typedef struct For more information, refer to SAI_RTP_ENDPOINT. |
|
server |
Pointer to the server ID as set in the configuration file. If set to null, the SAI service uses the first speech server name listed in the SAI configuration file. |
|
clientObjId |
Client object ID to associate with the created synthesizer engine. This parameter is optional. |
|
synthHd |
Pointer to a returned SAI service handle associated with a synthesizer resource. |
|
Return value |
Description |
|
SUCCESS |
|
|
SAIERR_INVALID_PARAMETER |
One of the specified parameters is invalid. |
|
CTAERR_INVALID_HANDLE |
Specified ctahd parameter is invalid and therefore the returned synthHd is undefined. |
|
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 synthHd. If the operation failed, the application must call saiReleaseSynthesizer to release the returned synthHd. |
saiCreateSynthesizer allocates a speech server synthesizer resource and associates it with a synthHd. When the speech server successfully allocates the new synthesizer engine resource, the synthesizer enters a ready state and the application receives SAIEVN_ENGINE_READY. The RTP port through which the server transmits the synthesized voice stream is specified in the enginePort field.
Note: From the time the application creates the synthesizer to the time that the server responds to the request, requests from application to the synthesizer are rejected because the synthesizer is in an invalid state.
For more information, refer to Creating synthesizer resources.
//
// The TTS must be associated to a CTA context.
// The RTP endpoint defines the destination where the client receives 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 ttsHd returned by that function is used to refer to that TTS engine for all synthesis
// 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 source
// where the server terminates the audio stream. It contains IP address and port number.
//
DWORD demoTtsCreate( CTAQUEUEHD queueHd, CTAHD ctxtHd, SAI_SYNTHESIZER_HANDLE *ttsHd,
SAI_RTP_ENDPOINT ttsEp, DWORD *serverPortTts )
{
DWORD rc = SUCCESS;
CTA_EVENT event;
SAI_EVENT_ENGINE_CREATION* eventResult = NULL;
memset( &event, 0, sizeof(CTA_EVENT) );
if (*ttsHd != 0)
{
printf("A TTS already exists.\n");
return !SUCCESS;
}
rc = saiCreateSynthesizer( ctxtHd, ttsEp, g_server, 0, ttsHd );
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) )
{
*serverPortTts = 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",
*serverPortTts, eventResult->engineIp );
}
else
{
printf("Engine creation failed, error code: 0x%08x.\n", rc);
}
return rc;
}