The following programs are two examples of how to write a working C or C++ client application using the speech engine API. Both versions were compiled with Visual Studio 6.0.
/*
Copyright LumenVox, LLC 2003;
This code is a sample only and is provided as convenience.
No warranty is expressed or implied when using this sample code
*/
#include <LV_SRE.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
/*128 KB file */
#define MAXAUDIOLENGTH 131072
/* ExportLogMsg callback */
void SPLogging(const char* String, void* p)
{
/* if p had some definition, then we could do some stuff with it */
printf("%s\n", String);
}
int main (int argc, char* argv[])
{
/* Audio File stuff */
char* audioFileName;
int audioHandle;
char* audioBuffer[MAXAUDIOLENGTH];
int audioLength;
/* HPORT stuff */
HPORT hport;
int grammarset = 1;
int voicechannel = 1;
int numconcepts;
int index;
/* Open the port */
hport = LV_SRE_OpenPort(SPLogging, NULL, 6);
/* Add two phrases to a custom grammar */
LV_SRE_AddPhrase(hport, grammarset, "no", "no");
LV_SRE_AddPhrase(hport, grammarset, "yes", "yes");
/* Acquire the audio data
assumed to be PCM_16KHZ */
audioFileName = "testAudio.pcm";
audioHandle = _open(audioFileName, _O_BINARY | _O_RDONLY);
audioLength = _read(audioHandle, audioBuffer, MAXAUDIOLENGTH);
/* Load the audio data into a voice channel */
LV_SRE_LoadVoiceChannel(hport, voicechannel, audioBuffer,
audioLength, PCM_16KHZ);
/* Save the request and answer files */
LV_SRE_SetProperty(hport, PROP_SAVE_SOUND_FILES, 1);
/* Decode, filtering out of vocabulary words;
control returns immediately */
LV_SRE_Decode(hport, voicechannel, grammarset, LV_DECODE_USE_OOV);
/* Do some processing while waiting for the SRE to finish */
/* Now see if the SRE has finished
1000 milliseconds = 1 second */
LV_SRE_WaitForEngineToIdle(hport, 1000, voicechannel);
/* We are assuming the Speech Engine finished;
process the results from the decode */
numconcepts = LV_SRE_GetNumberOfConceptsReturned(hport, voicechannel);
for (index = 0; index < numconcepts; index++)
{
printf("Concept: %s\n", LV_SRE_GetConcept(hport, voicechannel, index));
printf("Conf: %d\n", LV_SRE_GetConceptScore(hport, voicechannel, index));
printf("\n");
}
/* Close the port */
LV_SRE_ClosePort(hport);
return 0;
}
/*
Copyright LumenVox, LLC 2003;
This code is a sample only and is provided as convenience.
No warranty is expressed or implied when using this sample code
*/
#include <LVSpeechPort.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
//128 KB file
#define MAXAUDIOLENGTH 131072
//ExportLogMsg callback
void SPLogging(const char* String, void* p)
{
//if p had some definition, then we could do some stuff with it
printf("%s\n", String);
}
int main (int argc, char* argv[])
{
//Audio File stuff
char* audioFileName;
int audioHandle;
char* audioBuffer[MAXAUDIOLENGTH];
int audioLength;
//LVSpeechPort stuff
LVSpeechPort myport;
int grammarset = 1;
int voicechannel = 1;
int numconcepts;
int index;
//Open the port
myport.OpenPort(SPLogging, NULL, 6);
//Add two phrases to a custom grammar
myport.AddPhrase(grammarset, "no", "no");
myport.AddPhrase(grammarset, "yes", "yes");
//Acquire the audio data
// assumed to be PCM_16KHZ
audioFileName = "testAudio.pcm";
audioHandle = _open(audioFileName, _O_BINARY | _O_RDONLY);
audioLength = _read(audioHandle, audioBuffer, MAXAUDIOLENGTH);
//Load the audio data into a voice channel
myport.LoadVoiceChannel(voicechannel, audioBuffer,
audioLength, PCM_16KHZ);
//Save the request and answer files
myport.SetProperty(PROP_SAVE_SOUND_FILES, 1);
//Decode, filtering out of vocabulary words;
// control returns immediately
myport.Decode(voicechannel, grammarset, LV_DECODE_USE_OOV);
//Do some processing while waiting for the Speech Engine to finish
//Now see if the Speech Engine has finished
// 1000 milliseconds = 1 second
myport.WaitForEngineToIdle(1000, voicechannel);
//We are assuming the Speech Engine finished;
// process the results from the decode
numconcepts = myport.GetNumberOfConceptsReturned(voicechannel);
for (index = 0; index < numconcepts; index++)
{
printf("Concept: %s\n", myport.GetConcept(voicechannel, index));
printf("Conf: %d\n", myport.GetConceptScore(voicechannel, index));
printf("\n");
}
//Close the port
myport.ClosePort();
return 0;
}
Complete Help Topic List | Speech Engine Product Information