• Aucun résultat trouvé

Of course, the user could simultaneously press the left Amiga key and N to flip the primary screen and requester window into view, but you can't be

Dans le document in utilities, in (Page 191-200)

sure everyone will think of that. Lots of people might assume the computer has mysteriously crashed or gone comatose.

The solution is to place your first SAY before the SCREEN and WIN DOW statements. The spoken message can be something innocuous, such as,

"Just a moment, please," or even a null string (" "). The object is to force the system requester window to appear—if it's necessary—before your secondary screen displaces the primary screen. Spelling Quizzer and Speech Constructor both use this technique.

Finally, the VolumeVoice and GenderVoice routines in Spelling Quizzer

are modular enough to be easily adapted to your own speech programs. To pre

vent possible conflicts with existing program variables, you might even convert

these routines into subprograms if you think you'll use them often.

Program 6-1. Speech Constructor

• *** speech Constructor ****

Initialize:*

DEFINT a-z*

DIM label?(10) 'For often-used messages.*

label?(0) = "Speech Constructor11*

label?(l)="*Press RETURN to exit*11*

label?(2)="*Click in this window*"*

label?(3)=" *to continue*"*

label?(4)="Just a moment, please,.."*

label?(5)="Press RETURN to keep current value."*

SAY TRANSLATE? ("Just a moment please.")*

WINDOW 1,"Speech Constructor",(0,0)-(631,185),20*

PRINT label?(4)*

DIM vowels?(12,2) 'Array for vowels.*

FOR x=l TO 12*

READ vowels?(x,l) 'Actual phonemes.*

READ vowels?(x,2) 'Example words.*

NEXT x*

DATA IY,beet,EH,bet,AA,hot,AO,talk,ER,bird,AX,about*

DATA IH,bit,AE,bat,AH,under,UH,look,OH,border,IX,solid*

DIM diphthongs?(6,2):' Array for diphthongs.*

FOR x=l TO 6*

READ diphthongs?(x,1) 'Actual phonemes.*

READ diphthongs?(x,2) 'Example words.*

NEXT x*

DATA EY,made,OY,boil,OW,low,AY,hide,AW,power,UW,crew*

DIM consonantsl?(13,2)x ' Array for 1st consonants.*

FOR x=l TO 13*

READ consonants1?(x,1) 'Actual phonemes.*

READ consonantsl?(x,2) 'Example words.*

NEXT x*

DATA R, red,W,away,M,men,NX, sing,S, sail,F, fed, Z,has*

DATA V,very,CH,check,/H,hole,B,but,D,dog,K,commodore*

DIM consonants2?(12,2) 'Array for 2nd consonants.*

FOR x=l TO 12*

READ consonants2?(x,l) 'Actual phonemes.*

READ consonants2?(x,2) 'Example words.*

NEXT x*

DATA L,yellow,Y,yellow,N,men,SH,rush,TH,thin,ZH,pleasure*

DATA DH,then,J,judge,/C,loch,P,put,T,toy,G,guest*

DIM special?(16,2):' Array for special phonemes.*

FOR x=l TO 16*

READ special?(x,1) ' Actual phonemes.*

READ special?(x,2) ' Examples & equivalents.*

NEXT x*

DATA DX,pity,QX,pause,RX,car,UL,=AXL,UM,=AXM,UN,=AXN*

DATA Q,kitt-en,LX,call,IL,=IXL,IM,=IXM,IN,=IXN*

DATA " ",(space)f".",period,"?",question mark*

DATA "-",dash,",",comma*

DIM voice%(8) 'Array for voice parameters.*

FOR x=0 TO 8*

READ voice%(x)*

NEXT x*

DATA 110,0,150,0,22200,64,10,0,0*

GOSUB MenuSetup*

GOTO MainMenu*

*

MenuSetup:*

'Design custom menu bar:*

MENU 1,0,0,"Project"*

MENU 1,1,0,"Make Phrase "*

MENU 1,2,0,"Erase Word "*

MENU 1,3,0,"Erase Phrase"*

MENU 1,4,0,"Open Phrase "*

MENU 1,5,0,"Save Phrase "*

MENU 1,6,0,"Print Phrase"*

MENU 1,7,0,"Type Word "*

MENU 1,8,0,"Translate "*

MENU 1,9,0,"Quit "*

MENU 2,0,0,"Speech"*

MENU 2,1,0,"Say Word "*

MENU 2,2,0,"Say Phrase "*

MENU 2,3,0,"Alter Voice"*

MENU 6,3,1,"N "*

MENU 6,4,1,"SH "*

MENU 6,5,1,"TH "*

MENU 6,6,1, "ZH "*

MENU 6,7,1, "DH "*

MENU 6,8,1,"J "*

MENU 6,9,1,"/C "*

MENU 6,10,1,"P "*

MENU 6,11,1, "T "*

MENU 6,12,1,"G "*

ON ERROR GOTO 0*

CLS*

'Define status of menu selections*

'for Main Menu bar.*

'Following items always on:*

MENU 1,0,1:MENU 1,8,1:MENU 1,9,1*

MENU 2,0,1:MENU 2,3,1:MENU 3,0,1:MENU 4,0,1*

MENU 5,0,1:MENU 6,0,1:MENU 7,0,1*

'Following items on or off*

'depending on whether a word*

'or phrase is currently in memory:*

IF LEN(phrase?)=0 THEN*

MENU 1,3,0:MENU 1,4,1:MENU 1,5,0:MENU 1,6,0:MENU 2,2,0*

ELSE*

MENU 1,3,1:MENU 1,4,0:MENU 1,5,1*MENU 1,6,1:MENU 2,2,1*

END IF*

IF LEN(word?)=0 THEN*

MENU 1,1,0:MENU 1,7,1:MENU 1,2,0:MENU 2,1,0*

ELSE*

MENU 1,1,1:MENU 1,2,1:MENU 1,7,0:MENU 2,1,1*

END IF*

WIDTH 80*

PRINT:PRINT "—Select choice from menu bar—"*

PRINT:PRINT "Current word: ";word$*

PRINT:PRINT "Current phrase: ";phrase?*

Checkmenloop:*

MenuID=MENU(0)-*

IF MenuID=0 THEN Che ckmen loop-*

MenuItem=MENU(1)-*

ON MenuID GOTO ProjectMenu,SpeechMenu,VowMenu,DipMenu,ConslMenu, Cons2Menu,SpecMenu-*

GOTO Checkmenloop-*

ProjectMenu:-*

'Handles selections from Project menu.-*

ON Menultem GOTO MakePhrase,NewWord,NewPhrase,OpenPhrase,SavePhr

ase, PrintPhrase, TypeWord, Trans late, Quit-*

4,

SpeechMenu :-*

'Handles selections from Speech menu.-*

ON Menultem GOTO SayWord,SayPhrase,AlterVoice-*

VowMenu: -*

'Handles selections from Vowels menu.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0«*

MENU 7,0,0:CLS-*

phoneme§=vowels? (Menultem, 1) -*

WIDTH 80:LOCATE 8,1:PRINT "Phoneme: ";phoneme$«*

PRINT:PRINT "Example: ";vowels?(Menultem, 2)-*

PRINT:PRINT "Current word + phoneme: "7word$+phoneme$«*

ON ERROR GOTO ErrorTrap-*

SAY word$+phoneme$,voice%«

ON ERROR GOTO 0-4

msgl$="Add phoneme to current word?"-*

CALL Requester (msgl$,"","ADD","CANCEL",0,answer%)«

IF answer%=0 GOTO MainMenu 'CANCEL was selected.-*

word$=word$+phoneme$ 'ADD was selected.-*

GOTO MainMenu-*

-*

DipMenu:4

'Handles selections from Diphthongs menu.**

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS-*

phoneme$=diphthongs$ (Menultem, 1) •*

WIDTH 80:LOCATE 8,1-*

PRINT "Phoneme: ";phoneme$«

PRINT:PRINT "Example: ";diphthongs? (Menultem, 2)-*

PRINT:PRINT "Current word + phoneme: ";word$+phoneme$<*

ON ERROR GOTO ErrorTrap-*

SAY word$+phoneme$,voice%-*

ON ERROR GOTO 0-*

msgl$="Add phoneme to current word?"-*

CALL Requester (msgl$ ,"", "ADD" , "CANCEL" ,0,answer%)-*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.-*

word$=word$+phoneme$ 'ADD was selected.-*

GOTO MainMenu-*

<*

ConslMenu:-*

'Handles selections from Consl menu.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS-*

phoneme?=consonantsl?(Menultem,1 )-*

WIDTH 80:LOCATE 8,1:PRINT "Phoneme: "; phoneme?-*

PRINT:PRINT "Example: ";consonants1$(Menultem,2)-*

PRINT:PRINT "Current word + phoneme: ";word$+phoneme$«

ON ERROR GOTO ErrorTrap-*

SAY word?+phoneme?,voice%<*

ON ERROR GOTO 0-*

msgl?="Add phoneme to current word?"*

CALL Requester (msgl?, "" /'ADD","CANCEL",0, answer%)-*

IF answer=0 GOTO MainMenu 'CANCEL was selected.-*

word?=word?+phoneme? 'ADD was selected.-*

GOTO MainMenu-*

4,

Cons2Menu:«

•Handles selections from Cons2 menu.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS-*

phoneme?=consonants2? (Menultem, 1)-*

WIDTH 80:LOCATE 8,1:PRINT "Phoneme: ";phoneme?-*

PRINT:PRINT "Example: Myconsonants2$(Menultem,2)*

PRINT:PRINT "Current word + phoneme: "7word?+phoneme?«

ON ERROR GOTO ErrorTrap-*

SAY word$+phoneme$,voice%-*

ON ERROR GOTO 0-*

msgl?="Add phoneme to current word?"-*

CALL Requester (msgl? ,IMI, "ADD" , "CANCEL" , 0, answer%)-*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.-*

word$=word$+phoneme$ 'ADD was selected.-*

GOTO MainMenu-*

•4

SpecMenu:-*

'Handles selections from Special menu.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS-*

'Next line skips to Stress selection:-*

IF Menultem=17 GOTO AddStress-*

phoneme$=special$ (Menultem, 1) -*

WIDTH 80:LOCATE 8,1:PRINT "Phoneme: ";phoneme?-*

PRINT:PRINT "Example: "; special?(Menultem, 2)-*

PRINT:PRINT "Current word + phoneme: " ;word?+phoneme?-*

ON ERROR GOTO ErrorTrap-*

SAY word?+phoneme?,voice%-*

ON ERROR GOTO 0-*

msgl?="Add phoneme to current word?"-*

CALL Requester (msgl?, "", "ADD" , "CANCEL" ,0,answer%)-*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.-*

word?=word?+phoneme? 'ADD was selected.-*

GOTO MainMenu-*

A

AddStress :<*

CLS:WIDTH 80:LOCATE 10,1-*

PRINT "Press key 1 to 9 to add stress to current word.1'-*

PRINT: PRINT label? (1)-*

Stressloop:-*

temp?=INKEY?-*

IF temp?="" GOTO Stressloop-*

IF temp?=CHR?(13) GOTO MainMenu 'Abort routine.-*

IF ASC(temp?)>48 AND ASC (temp?) < 58 THEN-*

•Key 1-9 was pressed.-*

word?=word?+temp?-*

GOTO MainMenu-*

ELSE-*

'Keypress was out of range.-*

GOTO AddStress*

END IF-*

«*

MakePhrase:-*

'Adds current word to phrase.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS-*

WIDTH 80:LOCATE 8,1:PRINT "Current word: ";word?-*

PRINT:PRINT "Current phrase: ";phrase?-*

ON ERROR GOTO ErrorTrap-*

SAY phrase?+word?,voice%-*

ON ERROR GOTO 0-*

msgl?="Add current word to phrase?"-*

CALL Requester (msgl?, "", "ADD" , "CANCEL" ,0,answer%)-*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.-*

phrase?=phrase?+word? 'ADD was selected.-*

GOTO MainMenu-*

A

NewWord: «*

'Erases current word.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS:LOCATE 10,1-*

PRINT "Current word: ";word?-*

msgl?="Erase current word?"-*

CALL Requester (msgl?, "", "ERASE", "CANCEL", 2, answer%)-*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.-*

word?="" 'ERASE was selected.-*

GOTO MainMenu-*

«*

NewPhrase:-*

'Erases current phrase.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS:LOCATE 10,1-*

PRINT "Current phrase: ";phrase?-*

msgl?="Erase current phrase?"-*

CALL Requester (msgl? ,"", "ERASE" , "CANCEL" , 2, answer%)-*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.-*

phrase?="" 'ERASE was selected.-*

GOTO MainMenu-*

A

OpenPhr ase:-*

'Loads previously stored phrase-*

'and voice parameters from disk.-*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0-*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0-*

MENU 7,0,0:CLS:WIDTH 80:LOCATE 8#1:PRINT label?(l)*

PRINT:PRINT "Enter filename of phrase to load:"*

LINE INPUT ">> ";filename?*

IF filename?="" GOTO MainMenu 'Abort routine.*

ON ERROR GOTO ErrorTrap*

OPEN filename? FOR INPUT AS #1*

PRINT:PRINT "Loading ";filename?;"..."*

FOR x=0 TO 8 'Get voice parameters.*

INPUT# l,voice%(x)*

NEXT x*

INPUT# 1,phrase? 'Get phrase.*

CLOSE #1*

ON ERROR GOTO 0*

GOTO MainMenu*

*

SavePhrase:*

1 Saves current phrase*

'and voice parameters on disk.*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0*

MENU 7,0,0:CLS:WIDTH 80:LOCATE 8,1*

PRINT label? (1)-.PRINT: PRINT "Enter filename to save:"*

LINE INPUT ">> ";filename?*

IF filename?="" GOTO MainMenu 'Abort routine.*

ON ERROR GOTO ErrorTrap*

OPEN filename? FOR OUTPUT AS #1*

PRINT:PRINT "Saving under filename ";filename?;"..."*

FOR x=0 TO 8 'Save voice parameters.*

WRITE* l,voice%(x)*

NEXT x*

WRITE# 1,phrase? 'Save phrase.*

CLOSE #1*

ON ERROR GOTO 0*

temp&=TIMER 'Wait for drive to finish...*

WHILE TIMER<temp&+6:WEND*

GOTO MainMenu*

A

PrintPhrase:*

'Prints current phrase on printer.*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0*

MENU 7,0,0:CLS*

msgl?="Click PRINT when ready."*

msg2?="(Be sure printer is online.)"*

CALL Requester (msgl?,msg2?,"PRINT","CANCEL",0,answer%)*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.*

'PRINT was selected:*

ON ERROR GOTO ErrorTrap*

OPEN "prt:" FOR OUTPUT AS #1*

PRINT# 1,"":PRINT# 1,""*

PRINT# 1,phrase?*

PRINT* 1,"":PRINT# 1,""*

CLOSE #1*

ON ERROR GOTO 0*

GOTO MainMenu*

TypeWord: *

'Allows keyboard entry of phonemes.*

MENU 1,0,0:MENU 2,0,0:CLS:PRINT label?(1):PRINT*

PRINT "This allows direct keyboard entry"*

PRINT "of a word or series of words in phonemes."*

PRINT "Phoneme menus are available for reference only."*

PRINT:PRINT "Enter valid phonemes and press RETURN:"*

PRINT:LINE INPUT ">> ",word$*

word?=UCASE?(word?) 'Convert to uppercase.*

Clearmenu:*

MenuID=MENU(0)*

IF MenuID=0 GOTO MainMenu*

MenuItem=MENU(1)*

GOTO Clearmenu*

*

Translate:*

'Translates English text to phonemes.*

'Accepts input from keyboard.*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0*

MENU 7,0,0:CLS:PRINT label§(1):PRINT*

PRINT "Enter English text to translate"*

PRINT "into phonemes and press RETURN:"*

PRINT:LINE INPUT ">> ",temp§*

IF temp?="" GOTO MainMenu 'Abort routine.*

PRINT:PRINT TRANSLATE? (temp?)*

ON ERROR GOTO ErrorTrap*

SAY TRANSLATE? (temp?),voice%*

ON ERROR GOTO 0*

PRINT:PRINT:GOSUB Clickmouse*

GOTO MainMenu*

*

Quit:*

'Exits program to BASIC*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0:MENU 7,0,0:CLS*

'Different warning if phrase in memory:*

msgl?="Quit program to BASIC?"*

IF LEN(phrase?)=0 THEN*

msg2?=""*

ELSE*

msg2?="Current phrase will be erased."*

END IF*

CALL Requester (msgl?,msg2?,"QUIT","CANCEL",2,answer%)*

IF answer%=0 GOTO MainMenu 'CANCEL was selected.*

CLS:END 'QUIT was selected.*

*

SayWord:*

'Speaks current word.*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0*

MENU 7,0,0:CLS:LOCATE 10,1*

PRINT "Current word: ";word?*

ON ERROR GOTO ErrorTrap*

SAY word?,voice%*

ON ERROR GOTO 0*

GOTO MainMenu*

SayPhrase:*

'Speaks current phrase.*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0*

MENU 7,0,0:CLS:LOCATE 10,1*

PRINT "Current phrase: ";phrase$*

ON ERROR GOTO ErrorTrap*

SAY phrase$,voice%*

ON ERROR GOTO 0*

GOTO MainMenu*

A

AlterVoice:*

'Alters voice parameters.*

MENU 1,0,0:MENU 2,0,0:MENU 3,0,0*

MENU 4,0,0:MENU 5,0,0:MENU 6,0,0:MENU 7,0,0*

parameter$="PITCH:"*

parnum=0 'Parameter number of voice% array.*

default=110 'Default value of parameter.*

loval=65:hival=320 'Legal lo & hi values.*

GOSUB NewVoice*

PRINT "Default value = ";default*

PRINT "Current value = ";voice%(parnum)*

PRINT "Enter value from";loval;"to";nival;"> ";*

INPUT "",temp$*

IF temp$="" THEN RETURN:1 Keep current value.*

temp=INT(VAL(temp$)) 'Convert string to value.*

IF temp<loval OR temp>hival GOTO NewVoice*

voice%(parnum)=temp*

RETURN*

4

Clickmouse:*

'Patiently waits for mouse click & release.*

PRINT label§(2):PRINT label$(3)*

Dans le document in utilities, in (Page 191-200)