saiSpeakSynthesizer

Initiates a speech synthesis process.

Prototype

DWORD saiSpeakSynthesizer ( SAI_SYNTHESIZER_HANDLE synthHd, SAI_SPEAK_DATA_TYPE dataType, void *data, SAI_REQUEST_ID *requestId )

Argument

Description

synthHd

Handle associated with a synthesizer resource.

dataType

Payload data type. The following list shows supported speak data types and their associated numeric values:

  • SAI_SPEAK_DATA_TYPE_URL [0]: Data in URL format.

  • SAI_SPEAK_DATA_TYPE_XML [1]: Data in XML format.

  • SAI_SPEAK_DATA_TYPE_PLAIN_TEXT [2]: Data in non-formatted plain text format.

  • SAI_SPEAK_DATA_TYPE_DATA_LIST [3]: Data is a list of speak rules.

data

Pointer to the payload to play. This argument can consist of a URL, an XML document, a created speak grammar list, or plain text.

requestId

Pointer to a unique identifier associated with the request.


Return values

Return value

Description

SUCCESS

 

SAIERR_ENGINE_NOT_READY

Specified synthesizer engine is not ready to handle the request.

SAIERR_INVALID_PARAMETER

One of the specified arguments is invalid.

SAIERR_LIST_EMPTY

Speak list contains no item.

SAIERR_LIST_NOT_INITIALIZED

Specified speak list is not initialized. This error is only returned when datatype is SAI_SPEAK_DATA_TYPE_DATA_LIST.


Events

Event

Description

SAIEVN_TTS_SPEAK_ACKNOWLEDGED

Request was accepted and is being processed. Status code is indicated in the statusCode field of the SAIEVN_TTS_SPEAK_ACKNOWLEDGED event buffer.

SAIEVN_TTS_SPEAK_DONE

If the speech server successfully processes the command, the application receives this event indicating that the request is completed. The completion cause is returned in the completionCause field of the SAIEVN_TTS_SPEAK_DONE event buffer.

SAIEVN_TTS_SPEAK_MARKER_REACHED

Unsolicited event that may be returned by the synthesizer when markers are included into the speech data. The marker is returned in the SAIEVN_TTS_SPEAK_MARKER_REACHED event buffer.


Details

If the synthesizer is actively processing data or is paused when it receives the speech synthesis request, the synthesizer accepts the request. The SAI service returns an event indicating that the request status is PENDING. Otherwise, the event indicates the request status is IN_PROGRESS.

For more information, refer to Creating a synthesizer speak list.

See also

saiControlSynthesizer, saiPauseSynthesizer, saiResumeSynthesizer, saiStopSynthesizer

Example

//
// Start synthesis with speech located in a grammar list. TTS handle is used to reach the
// appropriate synthesis engine created previously.
// The Application waits on the event queue to receive the SAIEVN_TTS_SPEAK_ACKNOWNLEDGED and
// SAIEVN_TTS_SPEAK_DONE.
//
// A XML grammar is added to a grammar list. With saiAddSpeakRule, a name tag can be associated  
// to this grammar and used to make reference to this tool.
//
DWORD demoTtsSpeakGrammarList(  CTAQUEUEHD queueHd, SAI_SYNTHESIZER_HANDLE ttsHd )
{
    DWORD rc = SUCCESS;
    char textToSpeak[MAX_TEXT_TO_SPEAK];
    SAI_REQUEST_ID reqId = 0;
    strcpy( textToSpeak, (char *)"one one two");
    rc = saiInitSpeakList( speakRuleList, sizeof(speakRuleList) );
    if ( rc == SUCCESS )
    {
        //
        // Add a speak rule to the database.
        //
        rc = saiAddSpeakItem(speakRuleList, SAI_SPEAK_DATA_TYPE_PLAIN_TEXT, textToSpeak );
    }
    if ( rc == SUCCESS )
    {
        //
        // Call SAI speaking function. Use grammar list created previously.
        // reqId associated to the request is returned
        //
        rc = saiSpeakSynthesizer( ttsHd, SAI_SPEAK_DATA_TYPE_DATA_LIST, speakRuleList, &reqId );
    }
    if ( rc == SUCCESS )
    {
        //
        // Verify each event received in queue as long as the appropriate one
        // (in this case: SAIEVN_TTS_SPEAK_ACKNOWNLEDGED and SAIEVN_TTS_SPEAK_DONE) are
        // received or before timeout is over. Verify that status code, completion cause and
        // reqId are the same as buffer memory.
        //
        rc = demoWaitForEventSpeakFcn(queueHd, reqId);
    }
    if (rc == SUCCESS)
    {
        printf("Speak with SAI_SPEAK_DATA_TYPE_DATA_LIST succeed!.\n");
    }
    else
    {
        printf("Speak with SAI_SPEAK_DATA_TYPE_DATA_LIST failed, error code = 0x%08X.\n", rc);
    }

    return rc;
}