Hi
I thought someone else will reply on this, but it seems like you're doomed with me.
Here is my reply for you: both improved (you asked for it), prepared for SAS/C 6.5x and with the answer for your question inside. Try it and find it out!
Cheers
/***************************************************/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/translator.h>
#include <clib/alib_protos.h>
#include <dos/dos.h>
#include <devices/narrator.h>
#include <stdio.h>
#include <string.h>
const static BYTE audChanMasks[]={3,5,10,12};
/***************************************************************/
int get_phoneme( UBYTE *in, SHORT inLen, UBYTE *out, SHORT outLen)
{
struct Library *TranslatorBase;
int retVal, error;
TranslatorBase = (struct Library*)OpenLibrary("translator.library",1);
if( !TranslatorBase ) {
puts("Cannot Open Translator.library!");
return RETURN_FAIL;
}
retVal = RETURN_OK;
// Translate this string to phonetics
if(error=Translate(in,inLen,out,outLen) != 0 ) {
printf("Cannot Translate %d\n",error);
retVal = RETURN_FAIL;
}
CloseLibrary(TranslatorBase);
return retVal;
}
/***************************************************************/
int talk_to_me(UBYTE *speech) {
struct narrator_rb *wmes;
struct mouth_rb *rmes;
struct MsgPort *WPort;
struct MsgPort *RPort;
if((WPort=CreatePort(0,0)) == NULL)
return RETURN_FAIL;
if((RPort=CreatePort(0,0)) == NULL ) {
DeletePort( WPort );
return RETURN_FAIL;
}
if((wmes=(struct narrator_rb*)CreateExtIO(WPort,sizeof(struct narrator_rb))) == NULL) {
DeletePort( RPort );
DeletePort( WPort );
return RETURN_FAIL;
}
if((rmes=(struct mouth_rb*)CreateExtIO(RPort,sizeof(struct mouth_rb))) == NULL) {
DeleteExtIO( wmes );
DeletePort( RPort );
DeletePort( WPort );
return RETURN_FAIL;
}
wmes->message.io_Command = CMD_WRITE;
wmes->message.io_Data = (APTR)speech;
wmes->message.io_Length = strlen(speech);
wmes->ch_masks = audChanMasks;
wmes->nm_masks = sizeof(audChanMasks);
if(OpenDevice("narrator.device", 0, wmes, 0) != 0) {
DeleteExtIO( rmes );
DeleteExtIO( wmes );
DeletePort( RPort );
DeletePort( WPort );
return RETURN_FAIL;
}
wmes->mouths = 0;
wmes->volume = 64;
wmes->rate = 20;
wmes->sex = MALE;
wmes->pitch = DEFPITCH;
rmes->voice.message.io_Device = wmes->message.io_Device;
rmes->voice.io_Unit = wmes->message.io_Unit;
rmes->width = 0;
rmes->height = 0;
rmes->voice.message.io_Command = CMD_READ;
rmes->voice.io_Error = 0;
SendIO(wmes);
{
unsigned cnt = 0;
while(rmes->voice.message.io_Error != ND_NoWrite) {
DoIO(rmes);
++cnt;
}
printf( "cnt = %u\n", cnt );
}
WaitPort( WPort );
CloseDevice( wmes );
DeleteExtIO( rmes );
DeleteExtIO( wmes );
DeletePort( RPort );
DeletePort( WPort );
return RETURN_OK;
}
/***************************************************************/
int main(void)
{
UBYTE in_string[] = "test string", out_string[300];
//printf("Enter a string ");
//gets(in_string);
if( get_phoneme(in_string, strlen(in_string),out_string, 300) ) {
puts("get_phoneme error!");
return RETURN_FAIL;
}
printf("The phoneme translation of %s is %s\n", in_string, out_string);
if( talk_to_me(out_string) )
return RETURN_FAIL;
return RETURN_OK;
}