Listing 2. atul.c /* atul - a simple speech checklist for embedded systems */ #include #include #include #include espeak_POSITION_TYPE position_type; espeak_AUDIO_OUTPUT output; char *path=NULL; int BuffLen=500, Options=0; void* user_data; t_espeak_callback *SynthCallback; espeak_PARAMETER Parm; FILE *ckfp; /* Checklist file pointer */ char *ckBuf; /* Checklist item buffer */ char *mtchBuf; /* Checklist expected response buffer */ char *srBuf; /* Speech rec buffer */ char *reply; /* Trimmed reply */ int bsize=100; /* buffer length for all buffers */ int next; /* flag - true if should go to next prompt */ char Voice[] = {"default"}; unsigned int size, position=0, end_position=0, flags=espeakCHARS_AUTO|espeakENDPAUSE, *unique_identifier; void recordreply(){ /* read lines from stdin, which are piped in * from pocketsphinx_continuous. * Valid responses look like: * <9 digits>: reply (7 or 8 digits) * Returns a trimmed reply as char *reply * no spaces in return */ int i, j; while (!feof(stdin)) { getline (&srBuf, &bsize, stdin); if (srBuf[9]!= ':') continue; j=0; for (i=0; i\n", argc); return 0; } ckfp = fopen(argv[1], "r"); if (ckfp == NULL) { printf("Unable to open checklist file: %s\n", argv[1]); return 0; } /* Initialize the TTS subsystem */ output = AUDIO_OUTPUT_PLAYBACK; espeak_Initialize(output, BuffLen, path, Options); espeak_SetVoiceByName(Voice); /* Initialize speech recognition * piped in from pocketsphinx_continuous */ while (!feof(stdin)) { getline (&srBuf, &bsize, stdin); if (strncmp(srBuf, "READY...", 8)==0) break; } /* Go through the checklist */ next = 1; /* advance to next prompt */ while (!feof(ckfp)) { if (next) { getline (&ckBuf, &bsize, ckfp); getline (&mtchBuf, &bsize, ckfp); } size = strlen(ckBuf)+1; espeak_Synth( ckBuf, size, position, position_type, end_position, flags, unique_identifier, user_data ); espeak_Synchronize( ); fputs(ckBuf, stdout); next = checkreply(); } fclose(ckfp); free(ckBuf); free(srBuf); free(mtchBuf); return 0; }