home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d807 / voicecode.lha / VoiceCode / C_Code / recog.c < prev    next >
C/C++ Source or Header  |  1993-01-24  |  2KB  |  107 lines

  1. /* A test of voice.library from C. 
  2.   
  3.    This program reads a file of max_num frequency maps
  4.    associated with max_num numbers, then allows you to 
  5.    test recognition of the latter.
  6.    
  7.    Use learn.c to learn the numbers and create the
  8.    corresponding file of frequency maps (nums). 
  9.  
  10.    To quit the program, hold the left mouse button 
  11.    down while speaking a word. After the current 
  12.    recognition attempt, the program will exit.
  13.  
  14.    ** link this code with voice.o
  15.  
  16.    Author: David J Benn
  17.      Date: 24th,27th,31st December 1992   
  18. */
  19.  
  20. #include <voice.h>
  21. #include <dos/dos.h>
  22. #include <exec/memory.h>
  23.  
  24. #define max_num 9L        /* max_num numbers */
  25.  
  26. #define MOUSE     0xbfe001
  27.  
  28. #define ABS(x) (x) >= 0 ? (x) : -(x)
  29.  
  30. struct  Library *VoiceBase;    /* must be called VoiceBase */
  31. BYTE     *MapBuffer;
  32. char     *num_name[] = { "one","two","three","four","five",
  33.             "six","seven","eight","nine" };
  34. char     *err[] = { 
  35.           "  ",
  36.           "No match",
  37.           "Volume too high",
  38.           "Volume too low",
  39.           "Confused by noise" 
  40.              };
  41.  
  42. main()
  43. {
  44. char     *mouse=(char *)MOUSE;
  45. SHORT    wd;
  46. struct     FileHandle *fh;
  47.  
  48.  /* open the library */
  49.  
  50.  VoiceBase = (struct Library *)OpenLibrary(VoiceName,0L);
  51.  if (VoiceBase == NULL) 
  52.     { printf("can't open voice.library!\n"); exit(10); }
  53.  
  54.  
  55.  /* specify the sampler */
  56.  
  57.  PickSampler(PERFECTSOUND3);
  58.  
  59.  
  60.  /* increase sampler gain a bit */
  61.  
  62.  GainUp();
  63.  
  64.  
  65.  /* allocate space for MapBuffer */
  66.  
  67.  MapBuffer = (BYTE *)AllocMem(FREQ_MAP_SIZE*max_num,MEMF_PUBLIC);
  68.  if (MapBuffer == NULL) 
  69.     { printf("AllocMem = NULL for MapBuffer!\n"); exit(10); }
  70.  
  71.  
  72.  /* read into MapBuffer from a file created by learn.c */
  73.  
  74.  fh = (struct FileHandle *)Open("nums",MODE_OLDFILE); 
  75.  if (fh == NULL) { puts("'nums' does not exist."); exit(10); }
  76.  Read(fh,MapBuffer,FREQ_MAP_SIZE*max_num);
  77.  Close(fh);
  78.  
  79.  
  80.  /* recognise some words until left mouse button held down
  81.     using the MapBuffer we've just read */
  82.  
  83.  while ((*mouse & 0x40) == 0x40)
  84.  {
  85.   printf("Speak a number from 1 to %ld.\n",max_num);
  86.   wd = Recognize(MapBuffer,max_num,HIGH_RES);
  87.   if (wd >= 0) printf("You said: %s.\n",num_name[wd]);
  88.   else
  89.       printf("ERROR: %s.\n",err[ABS(wd)]);
  90.  }
  91.  
  92.  FreeMem(MapBuffer,FREQ_MAP_SIZE*max_num);
  93.  
  94.  
  95.  /* decrease the gain so as to leave
  96.     the sampler in the state it was in
  97.     prior to running this program.
  98.  */
  99.  
  100.  GainDown();
  101.  
  102.  
  103.  /* close voice.library */
  104.  
  105.  CloseLibrary(VoiceBase);
  106. }
  107.