
#define ERR 1
#define SUCCESS 0
#define REV 0

#include "exec/types.h"
#include "exec/exec.h"
#include "exec/nodes.h"
#include "exec/memory.h"
#include "exec/interrupts.h"
#include "exec/ports.h"
#include "exec/libraries.h" 
#include "exec/io.h"
#include "exec/tasks.h"
#include "exec/execbase.h"
#include "libraries/translator.h"
#include "devices/audio.h"
#include "devices/narrator.h"
#include "stdio.h"

struct Library *TranslatorBase=NULL;
extern struct Library *OpenLibrary();
struct MsgPort *WPort,*RPort;
extern struct IORequest *CreateExtIO();
extern struct Library *OpenLibrary(); /* deze lijn kwam al eens voor ! */
struct narrator_rb *wmes;
struct mouth_rb *rmes;

BYTE audChanMasks[]={3,5,10,12};

main()
{
 UBYTE in_string[80],out_string[300];

 if(set_to_talk()==ERR)
   {
    printf("hier een fout");
    exit(FALSE);
   }

 for(;;)
  {
   printf("typ een zin ");
   gets(in_string);

   if(!strcmp(in_string,"%%"))
    break;

   if(get_phoneme(in_string,strlen(in_string),out_string,300)==ERR)
    exit(FALSE);

   if(talk_to_me(out_string)==ERR)
    exit(FALSE);
  };

 CloseDevice(wmes);

} /* end of main() */

get_phoneme(in,inlen,out,outlen)
UBYTE *in,*out;
SHORT inlen,outlen;
{
 TranslatorBase=(struct Library *)
                 OpenLibrary("translator.library",REV);

 if(TranslatorBase==NULL)
  return(ERR);

 if((Translate(in,inlen,out,outlen)) !=0)
  return(ERR);

 CloseLibrary(TranslatorBase);

 return(SUCCESS);
}

talk_to_me(speech)

UBYTE *speech;

{
 wmes->message.io_Data=(APTR)speech; 
 wmes->message.io_Length = strlen(speech);
 wmes->ch_masks=audChanMasks;
 wmes->nm_masks=sizeof(audChanMasks);

 wmes->mouths=0;
 wmes->volume=32;
 wmes->rate=20;
 wmes->sex=MALE;
 wmes->pitch=DEFPITCH;
 SendIO(wmes);

 while(rmes->voice.message.io_Error!=ND_NoWrite)
   DoIO(rmes);
}

set_to_talk()

{
 if((WPort=(struct MsgPort *)CreatePort(0,0))==NULL)
  return(ERR);

 if((RPort=(struct MsgPort *)CreatePort(0,0))==NULL)
  return(ERR);

 if((wmes=(struct narrator_rb *)
  CreateExtIO(WPort,sizeof(struct narrator_rb)))==NULL)
  return(ERR);

 if((rmes=(struct mouth_rb *)
  CreateExtIO(WPort,sizeof(struct narrator_rb)))==NULL)
  return(ERR);

 wmes->message.io_Command=CMD_WRITE;

 if(OpenDevice("narrator.device",0,wmes,0)!=0)
  return(ERR);

 rmes->voice.message.io_Device=wmes->message.io_Device;
 rmes->voice.message.io_Unit=wmes->message.io_Unit;
 rmes->width=0;
 rmes->height=0;
 rmes->voice.message.io_Command=CMD_READ;
 rmes->voice.message.io_Error=0;

 return(SUCCESS);
}


 




