home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d807 / voicecode.lha / VoiceCode / C_Code / learn.c next >
Encoding:
C/C++ Source or Header  |  1993-01-25  |  1.7 KB  |  85 lines

  1. /* A test of voice.library from C. 
  2.   
  3.    This program learns max_num numbers and
  4.    then creates a file of frequency maps (nums)
  5.    for each number.
  6.  
  7.    Use recog.c to read the file of frequency 
  8.    maps and test recognition of the spoken 
  9.    numbers.
  10.  
  11.    ** link this code with voice.o
  12.  
  13.    Author: David J Benn
  14.      Date: 24th,27th,31st December 1992   
  15. */
  16.  
  17. #include <voice.h>
  18. #include <dos/dos.h>
  19. #include <exec/memory.h>
  20.  
  21. #define max_num 9L        /* learn max_num numbers */
  22.  
  23. struct  Library *VoiceBase;    /* must be called VoiceBase */
  24. BYTE     *MapBuffer;
  25. char     *num_name[] = { "one","two","three","four","five",
  26.             "six","seven","eight","nine" };
  27.  
  28. main()
  29. {
  30. LONG     i;
  31. struct     FileHandle *fh;
  32.  
  33.  /* open the library */
  34.  
  35.  VoiceBase = (struct Library *)OpenLibrary(VoiceName,0L);
  36.  if (VoiceBase == NULL) 
  37.     { printf("can't open voice.library!\n"); exit(10); }
  38.  
  39.  
  40.  /* specify the sampler */
  41.  
  42.  PickSampler(PERFECTSOUND3);
  43.  
  44.  
  45.  /* increase sampler gain a bit */
  46.  
  47.  GainUp();
  48.  
  49.  
  50.  /* allocate space for MapBuffer */
  51.  
  52.  MapBuffer = (BYTE *)AllocMem(FREQ_MAP_SIZE*max_num,MEMF_PUBLIC);
  53.  if (MapBuffer == NULL) 
  54.     { printf("AllocMem = NULL for MapBuffer!\n"); exit(10); }
  55.  
  56.  
  57.  /* learn max_num numbers */
  58.  for (i=0;i<max_num;i++) Learn(MapBuffer,num_name[i],NULL,i,100L,75L);
  59.  
  60.  
  61.  /* write MapBuffer to a file -- this can later be read into 
  62.     an equivalent MapBuffer in RAM as in recog.c */
  63.  
  64.  fh = (struct FileHandle *)Open("nums",MODE_NEWFILE); 
  65.  Write(fh,MapBuffer,FREQ_MAP_SIZE*max_num);
  66.  Close(fh);
  67.  
  68.  puts("Frequency maps for learned words written to 'nums'.");
  69.  
  70.  FreeMem(MapBuffer,FREQ_MAP_SIZE*max_num);
  71.  
  72.  /* decrease the gain so as to leave 
  73.     the sampler in the state it was in 
  74.     prior to running this program. 
  75.  */
  76.  
  77.  GainDown();
  78.  
  79.  
  80.  /* close voice.library */
  81.  
  82.  CloseLibrary(VoiceBase);
  83. }
  84.  
  85.