home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / icss_e.zip / RECO.C < prev    next >
Text File  |  1993-05-25  |  5KB  |  144 lines

  1. /**********************************************************************/
  2. /*                IBM Continuous Speech Series  1.0                   */
  3. /**********************************************************************/
  4. /* Licensed Materials - Property of IBM                               */
  5. /* IBM Continuous Speech Series.                                      */
  6. /* (C) Copyright IBM Corporation 1992, 1993. All rights reserved.     */
  7. /*                                                                    */
  8. /* US Government Users Restricted Rights -                            */
  9. /* Use, duplication or disclosure restricted by GSA ADP Schedule      */
  10. /* Contract with IBM Corporation.                                     */
  11. /**********************************************************************/
  12. /*                                                                    */
  13. /* reco.c                                                             */
  14. /* ICSS Example API Program                                           */
  15. /*                                                                    */
  16. /**********************************************************************/
  17.  
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include "icssapi.h"
  24.  
  25. #define SIZEBUFFER 256
  26.  
  27. void quit(char *msg, long rc);
  28. void PrintCopyrightBanner(void);
  29.  
  30. /*
  31.  * main
  32.  * -----------------------------------------------------------------
  33.  */
  34. int main(int argc, char *argv[])
  35. {
  36.    char    inputbuf[SIZEBUFFER];
  37.    char    buffer[SIZEBUFFER];
  38.    long    rc      = -1;
  39.    long    context = 0;
  40.    long    notdone = 1;
  41.    long    spoke_too_soon;
  42.    float   utt_len;
  43.    float   acq_time;
  44.    float   reco_time;
  45.  
  46.    if(argc != 2)
  47.    {
  48.       printf("The reco example program requires one argument.\n");
  49.       printf("The name of a context to do recognition against.\n");
  50.       printf("Example: reco /icss/appl/samples/rl/context/rl.m.ctx\n");
  51.       return 0;
  52.    }
  53.    PrintCopyrightBanner();
  54.  
  55.    rc = ICSSStart(NULL);
  56.    if (rc != ICSS_SUCCESS)  quit("Error: Start Failed",rc);
  57.  
  58.    rc = ICSSStartConversation(
  59.                               "icssacpa",          /* ADC TYPE       */
  60.                               ICSS_DEFAULT_INT,    /* ADC Number     */
  61.                               ICSS_DEFAULT_STRING, /* rp system name */
  62.                               ICSS_DEFAULT_INT);   /* rp link type   */
  63.  
  64.    if (rc != ICSS_SUCCESS)  quit("Error: StartConversation Failed",rc);
  65.  
  66.    rc = ICSSLoadContext(&context, argv[1], ICSS_DEFAULT_FLOAT,
  67.                         ICSS_DEFAULT_FLOAT, ICSS_DEFAULT_FLOAT);
  68.    if (rc != ICSS_SUCCESS)  quit("Error: Define Context failed",rc);
  69.  
  70.    while(notdone)
  71.    {
  72.       printf("\nListen?[yes,no]>");
  73.       fflush(stdout);
  74.       gets(inputbuf);
  75.       if( (strstr(inputbuf,"NO" ) != NULL) ||
  76.           (strstr(inputbuf,"no" ) != NULL) )   { break; }
  77.       else
  78.       {
  79.          rc = ICSSListen(context, ICSS_DEFAULT_INT, NULL);
  80.  
  81.          if(rc != ICSS_SUCCESS)  quit("Error: Listen Failed",rc);
  82.  
  83.          printf("\nBEGIN SPEAKING\n");
  84.  
  85.          rc = ICSSGetSpokenWords(SIZEBUFFER-1, buffer, &spoke_too_soon,
  86.                                 &utt_len, &acq_time, &reco_time);
  87.          if (rc == ICSS_SUCCESS)
  88.          {
  89.             printf("The spoken text was: [%s]\n",buffer);
  90.             printf("Utterance Length %f\n",utt_len);
  91.             printf("Acquistion Time  %f\n",acq_time);
  92.             printf("Recognition Time %f\n",reco_time);
  93.             if (strstr(buffer,"EIGHT"))
  94.               system("RECO e:/test/devita/HAZMAT.CTX");
  95.          }
  96.          else
  97.          {
  98.             quit("Error: GetSpokenWords Failed",rc);
  99.          }
  100.       }
  101.    }
  102.  
  103.    rc = ICSSEndConversation();
  104.    if (rc != ICSS_SUCCESS)  quit("Error: Conversation End Failed",rc);
  105.  
  106.    ICSSEnd();
  107.  
  108.    return 0;
  109. }
  110.  
  111. /*
  112.  * quit
  113.  * -----------------------------------------------------------------
  114.  */
  115. void quit(char *msg, long rc)
  116. {
  117.    printf("%s rc=%d %s\n",msg,rc,ICSSErrorString[rc]);
  118.    exit(-1);
  119.    return;
  120. }
  121.  
  122. /*
  123.  * print banner
  124.  * -----------------------------------------------------------------
  125.  */
  126. void     PrintCopyrightBanner(void)
  127. {
  128.   printf("**********************************************************************\n");
  129.   printf("*                IBM Continuous Speech Series  1.0                   *\n");
  130.   printf("**********************************************************************\n");
  131.   printf("* Licensed Materials - Property of IBM                               *\n");
  132.   printf("* IBM Continuous Speech Series.                                      *\n");
  133.   printf("* (C) Copyright IBM Corporation 1992, 1993. All rights reserved.     *\n");
  134.   printf("*                                                                    *\n");
  135.   printf("* US Government Users Restricted Rights -                            *\n");
  136.   printf("* Use, duplication or disclosure restricted by GSA ADP Schedule      *\n");
  137.   printf("* Contract with IBM Corporation.                                     *\n");
  138.   printf("**********************************************************************\n");
  139.   printf("\n\n\n");
  140.   fflush(stdout);
  141.   /*sleep(2);*/
  142.   return;
  143. }
  144.