Initializing a Speech Port

A speech port is a connection between your application and the Speech Engine. It is required for recognition; you must have a speech port open before you can do anything else with the Engine. For every port that is open, you will need one available Speech Engine license.

The only thing you must do to initialize a speech port is to have the Speech Engine service running on your machine, and call OpenPort:

C Code

HPORT port;
long error_code;
port = LV_SRE_OpenPort2(&error_code,NULL,NULL,0);

switch(error_code)
{
case LV_OPEN_PORT_FAILED__LICENSES_EXCEEDED:
     printf("licenses exceeded");
     break;
case LV_OPEN_PORT_FAILED__PRIMARY_SERVER_NOT_RESPONDING:
case LV_NO_SERVER_RESPONDING
     printf("Speech Engine server unavailable");
     break;
case LV_SUCCESS:
     printf("port opened");
     break;
}

C++ Code

LVSpeechPort port;
port.OpenPort( );
int error_code = port.GetOpenPortStatus();

switch(error_code)
{
case LV_FAILURE:
     cout <<"failed to open port";
     break;
case LV_OPEN_PORT_FAILED__PRIMARY_SERVER_NOT_RESPONDING:
case LV_NO_SERVER_RESPONDING
     cout << "Speech Engine server unavailable";
     break;
case LV_SUCCESS:
     cout << "port opened";
     break;
}

Other things you can do besides opening a port include

C Code

/* a structure to hold logfile info */
typedef struct logdata_s
{
     long file;
     long message_count;

}logdata_t;

void logdata_callback(const char* message, void* userdata)
{
     logdata_t* mydata = (logdata_t*)userdata;
     fprintf(mydata->file,"%s\n",message);
     ++(mydata->message_count;
}

int init_port (HPORT* port, logdata_t* app_message, logdata_t* log_message )
{
     long error_code;
     
     /* Register a callback to accept messages from the server
        or client library, at warning level 3  
      */

     LV_SRE_RegisterAppLogMsg(logdata_callback,app_message, 3);

     /* point the client library to a local server and a remote server */
     /* Note that this must be done before opening a port */
     LV_SRE_SetPropertyEx(NULL,PROP_EX_SRE_SERVERS,
                               PROP_EX_VALUE_TYPE_STRING,
                               "127.0.0.1,10.0.0.1",
                               PROP_EX_TARGET_CLIENT, 0);



     /* open the port, registering a callback to accept messages
        from the port at warning level 3
      */

     port = LV_SRE_OpenPort2(error_code, logdata_callback,log_message,3);

     /* turn on sound and response file logging */
     int save_sound_files=1;
     LV_SRE_SetPropertyEx(port,PROP_EX_SAVE_SOUND_FILES,
                               PROP_EX_VALUE_TYPE_INT_PTR,
                               &save_sound_files,
                               PROP_EX_TARGET_PORT,0);

     return error_code;
}

C++ Code

// a class to hold logfile info
struct logdata
{
     ofstream file;
     long message_count;
     static void callback(const char* message, void* userdata)
     {
          logdata* self = (logdata*)userdata;
          mydata->file << message << endl;
          ++(mydata->message_count;
     }
};

int init_port (LVSpeechPort& port, logdata* app_message, logdata* log_message )
{
     long error_code;
     
     // Register a callback to accept messages from the server
     // or client library, at warning level 3.

     LVSpeechPort::RegisterAppLogMsg(logdata_callback,app_message, 3);

     // point the client library to a local server and a remote server
     LVSpeechPort::SetClientPropertyEx(PROP_EX_SRE_SERVERS,
                                       PROP_EX_TYPE_STRING,
                                       "127.0.0.1,10.0.0.1");

     // open the port, registering a callback to accept messages
     // from the port at warning level 3.

     port.OpenPort(logdata_callback,log_message,3);

     // turn on sound and response file logging
     port.SetPropertyEx(PROP_EX_SAVE_SOUND_FILES,
                        PROP_EX_VALUE_TYPE_INT_PTR,
                        &save_sound_files);

     return port.GetOpenPortStatus();
}


Complete Help Topic List | Speech Engine Product Information