[comp.sys.amiga] Simple Example Desired

jwabik@shamash.UUCP (Jeff Wabik) (10/15/87)

This has probably been asked before, but, could someone post (or mail) a
working example using the translator and narrator devices?  I've been 
scratching my head for a few days here, even examining such goodies as
speechtoy.c, but with no luck.  My environment is Manx 3.4 ..  

The problem here is probably that I've got ANTIQUE RKMs..  Auuugh!
Would anyone care to make a recommendation for a replacement set of
documentation?

Thanks in advance ..

	-Jeff

hansb@ariel.unm.edu (Hans Bechtel) (10/16/87)

I need a good way of inputting what I type from the keyboard onto a 
window on my own screen that I have set up.  What should I use?

The Console.device

or

The Text(); command
???  Does anybody have working examples with very little amount of
source code needed to generate it including the window and screen
opening in it?  I want to make sure that I am doing it properly...

I know I can look in books, but I have tried without too much success
as of yet to do just that.

Thanks

Hans Bechtel

rap@dana.UUCP (Rob Peck) (10/16/87)

In article <224@shamash.UUCP>, jwabik@shamash.UUCP (Jeff Wabik) writes:
> This has probably been asked before, but, could someone post (or mail) a
> working example using the translator and narrator devices?  I've been 
> scratching my head for a few days here, even examining such goodies as
> speechtoy.c, but with no luck.  My environment is Manx 3.4 ..  
> 
> 	-Jeff

I created this 99 line program in the hopes that it would be killer
demo material.  It is too short, I believe, for the sources posting
hopefully qualifying as message-only status for all purposes.  This
is about as short and simple as you can get when dealing with the
narrator and translator.  To simplify it further, you could also
delete the creation of rn - the message block that reads the mouths.

I wanted to make the narrator sing.  It sorta does it, but the syllables
are too far apart to have anyone say "yes, it really does sing".  Yet
it does provide at least a jumping off point for folks to use
(creation method: 1. open speechtoy.c source, 2. remove anything
not strictly speech-related, 3. compile whats left.)  I was told by
Mark Barton that I'd have to get deep into the Narrator device code
in order to "really" do what I wanted, since it was not designed
to sing in the first place.  You'll find that he was right.

The test phrase, by the way, folks said "if you are going to make
it sing, surely you won't want to use 'Daisy, daisy....'"
Well, they were wrong.

Hope it helps.			Rob Peck	...ihnp4!hplabs!dana!rap

--- cut here, might be Manx-compatible (cc +L ...; ln ... c32.lib, at least)

#include "exec/types.h"
#include "exec/exec.h"
#include "exec/nodes.h"
#include "exec/lists.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 "devices/narrator.h"
#include "libraries/translator.h"

struct MsgPort *readPort=0;
struct MsgPort *writePort=0;
 
extern struct MsgPort *CreatePort();
extern struct IORequest *CreateExtIO();
		  
struct narrator_rb *wn=0;
struct mouth_rb *rn=0;
			   
struct Library *TranslatorBase =0;
    
UBYTE *sampleInput;
UBYTE outputString[500];
SHORT rtnCode, readError, writeError, error;
     
UBYTE audChanMasks[4] = { 3,5,10,12 };
						      
extern struct Library *OpenLibrary();
#define REVISION 1
char *words[ ] = {
		"da","zee","da","zee","give","me",
		"your","an","sir","doooo" };
long pitches[] = { 300, 285, 270, 250, 260, 270, 285, 270, 285, 230 };

main()
{
  long i;
  TranslatorBase = OpenLibrary("translator.library",REVISION);
  if(TranslatorBase == NULL) exit(20);

  writePort = CreatePort(0,0);
  if(writePort == NULL) goto cleanup;
		     
  readPort = CreatePort(0,0);
  if(readPort == NULL) goto cleanup;

  wn = (struct narrator_rb *)CreateExtIO(writePort,
    	sizeof(struct narrator_rb));

  rn = (struct mouth_rb *)CreateExtIO(readPort,
	sizeof(struct mouth_rb));

  if(rn == NULL || wn == NULL) goto cleanup;

  wn->ch_masks = audChanMasks;
  wn->nm_masks = 1;   /* restrict to one channel */
  wn->message.io_Data    = (APTR)outputString;
  wn->message.io_Length  = strlen(outputString);
  wn->mouths = 0;             /* NO MOUTHS! Wont read em anyhow.*/
  wn->message.io_Command = CMD_WRITE;

  error = OpenDevice("narrator.device",0,wn,0);
  if(error != 0) goto cleanup;

  for(i=0; i<10; i++)
  {
  sampleinput = words[i];
  rtnCode = Translate(sampleInput, 
  strlen(sampleInput),outputString,500);
			       
  wn->pitch = pitches[i];
  wn->mode  = 1;          /* ROBOTIC */
						
  wn->message.io_Data    = (APTR)outputString;
  wn->message.io_Length  = strlen(outputString);
  wn->message.io_Command = CMD_WRITE;

  writeError = DoIO(wn);
  }
cleanup:
  if(wn->message.io_Device) CloseDevice(wn);
  if(wn) DeleteExtIO(wn);
  if(rn) DeleteExtIO(rn);
  if(TranslatorBase) CloseLibrary(TranslatorBase);
  if(readPort) DeletePort(readPort);
  if(writePort) DeletePort(writePort);
}

bryce@hoser.berkeley.edu (Bryce Nesbitt) (10/20/87)

In article <1662@charon.unm.edu> hansb@ariel.UUCP (Hans Bechtel) writes:
>
>I need a good way of inputting what I type from the keyboard onto a 
>window on my own screen that I have set up.  What should I use?
>
>The Console.device
>or
>The Text(); command

You are in deep trouble if you try to use the Text() command to input.
It can only draw text onto the screen. :-)

The console.device can go in and out, but is somewhat complex to use.

The easiest way to getting keystrokes is to request Class VANILLAKEY
IDCMP messages.  You simply request this type of message in the IDCMP
field when opening the window.  Messages will start to flow in.  If
the Message->Class compares to VANILLAKEY then Message->Code will
contain the key.

|\ /|  . Ack! (NAK, SOH, EOT)
{o O} . bryce@hoser.berkeley.EDU -or- ucbvax!hoser!bryce
 (") 	The CBS nightly news:
  U	Dan Rather, paraphrased: "Mr. Analyst, do you think we will continue
	to see a drop in the market like today's?"
	Market Analyst: "Well, that can only happen for three more days."