/* A test of voice.library from C. 
  
   This program learns max_num numbers and
   then creates a file of frequency maps (nums)
   for each number.
 
   Use recog.c to read the file of frequency 
   maps and test recognition of the spoken 
   numbers.

   ** link this code with voice.o

   Author: David J Benn
     Date: 24th,27th,31st December 1992   
*/

#include <voice.h>
#include <dos/dos.h>
#include <exec/memory.h>

#define max_num 9L		/* learn max_num numbers */

struct  Library *VoiceBase;	/* must be called VoiceBase */
BYTE 	*MapBuffer;
char 	*num_name[] = { "one","two","three","four","five",
			"six","seven","eight","nine" };

main()
{
LONG 	i;
struct 	FileHandle *fh;

 /* open the library */

 VoiceBase = (struct Library *)OpenLibrary(VoiceName,0L);
 if (VoiceBase == NULL) 
    { printf("can't open voice.library!\n"); exit(10); }


 /* specify the sampler */

 PickSampler(PERFECTSOUND3);


 /* increase sampler gain a bit */

 GainUp();


 /* allocate space for MapBuffer */

 MapBuffer = (BYTE *)AllocMem(FREQ_MAP_SIZE*max_num,MEMF_PUBLIC);
 if (MapBuffer == NULL) 
    { printf("AllocMem = NULL for MapBuffer!\n"); exit(10); }


 /* learn max_num numbers */
 for (i=0;i<max_num;i++) Learn(MapBuffer,num_name[i],NULL,i,100L,75L);


 /* write MapBuffer to a file -- this can later be read into 
    an equivalent MapBuffer in RAM as in recog.c */

 fh = (struct FileHandle *)Open("nums",MODE_NEWFILE); 
 Write(fh,MapBuffer,FREQ_MAP_SIZE*max_num);
 Close(fh);

 puts("Frequency maps for learned words written to 'nums'.");

 FreeMem(MapBuffer,FREQ_MAP_SIZE*max_num);

 /* decrease the gain so as to leave 
    the sampler in the state it was in 
    prior to running this program. 
 */

 GainDown();


 /* close voice.library */

 CloseLibrary(VoiceBase);
}

