home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / c_smples.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  12.7 KB  |  505 lines

  1. 18-Jun-88 15:12:43-MDT,13516;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 15:12:26 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22601; Sat, 18 Jun 88 14:41:28 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24761; Sat, 18 Jun 88 14:41:25 MDT
  8. Date: Sat, 18 Jun 88 14:41:25 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182041.AA24761@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: SimpleSpeech.c.shar
  13.  
  14. #! /bin/sh
  15. #
  16. # This is a shell archive.  Save this into a file, edit it
  17. # and delete all lines above this comment.  Then give this
  18. # file to sh by executing the command "sh file".  The files
  19. # will be extracted into the current directory owned by
  20. # you with default permissions.
  21. #
  22. # The files contained herein are:
  23. #
  24. #    9 simplespeech.c
  25. #    1 speech.h
  26. #    1 chat.c
  27. #    1 chat.h
  28. #
  29. echo 'Extracting simplespeech.c'
  30. if test -f simplespeech.c; then echo 'shar: will not overwrite simplespeech.c'; else
  31. sed 's/^X//' << '________This_Is_The_END________' > simplespeech.c
  32. X/*
  33. X *    Simplespeech.c
  34. X *
  35. X *    Version:    1.01
  36. X *    Date:        24/3/86
  37. X *
  38. X *    A sample speech program written in Megamax C using Apple's MacinTalk
  39. X *    speech driver.  I use the SimpleTools package for menus and DA handling.
  40. X *    
  41. X *    I use the strange kludge in chat.c because I found that I could not
  42. X *    call speechon,then speechoff,then speechon again. I tried to, and got
  43. X *    a "deep-shit" error and entered macsbug. Consequently, I kludged chat.c
  44. X *    to keep my speech segment separate from the main program.
  45. X *    
  46. X *    I hope you don't mind the 'bad' code I write. My philosophy is :-
  47. X *    "If it works, use it until it doesn't - then hack at it until it does..."
  48. X *
  49. X *    Help spread sources around the world.
  50. X *
  51. X *
  52. X *    I hope you can get something out of it. It is "giftware".
  53. X *
  54. X *
  55. X *    Jason Haines             ISD: +61 2 73-4444
  56. X *    ElecEng Undergraduate    STD:  (02) 73-4444
  57. X *    73 Davidson Avenue      ARPA: munnari!ipso!runx.oz!baron@SEISMO
  58. X *    Concord NSW 2137        UUCP: seismo!munnari!basser!ipso!runx!baron
  59. X *    AUSTRALIA                ACS: baron@runx
  60. X *
  61. X */
  62. X
  63. X#include "stdio.h"
  64. X#include "speech.h"
  65. X#include <qd.h>
  66. X#include <qdvars.h>
  67. X#include <misc.h>
  68. X#include <event.h>
  69. X#include <pack.h>
  70. X#include <win.h>
  71. X#include <seg.h>
  72. X#include <res.h>
  73. X#include <chat.h>
  74. X#include <font.h>
  75. X#include <dialog.h>
  76. X#include <toolbox.h>
  77. X
  78. Xchar *null[] = { 0 }; /* this is needed for use of execv */
  79. X
  80. X/* SimpleTools Declarations */
  81. X
  82. X#define itemdisable    0L
  83. X#define itemenable    1L
  84. X#define itemcheck    2L
  85. X#define itemuncheck    3L
  86. Xextern char applestring[];
  87. Xextern windowptr windowpoint();
  88. Xextern int wprocid;
  89. Xextern int dogoaway;
  90. Xextern int windmenu;
  91. X
  92. X/* End of SimpleTools Declarations */
  93. X
  94. X/* MacinTalk Declarations */
  95. X
  96. Xspeechhandle thespeech;
  97. X#define DEFPITCH    110
  98. X#define DEFRATE        140
  99. X
  100. X/* End of MacinTalk Declarations */
  101. X
  102. X/* Dialog Defs */
  103. X#define SAYITEM        1
  104. X#define CANCELITEM    2
  105. X#define OKITEM        2
  106. X#define OKITEM2        2
  107. X#define OKITEM3        1
  108. X#define MOREITEM    3
  109. X#define SAYTEXTITEM    3
  110. X#define GENTEXTITEM    2
  111. X/* End of Dialog Defs */
  112. X
  113. Xchar str[256], infilename[256];
  114. Xint c, err;
  115. XFILE *input_file,  *fopen();
  116. Xint i = 0;
  117. Xint voicemode, voicepitch, voicerate;
  118. Xrect therect;
  119. Xdialogptr    mydialogptr, aboutdialogptr, about2dialogptr, about3dialogptr,
  120. X            pitchdialogptr, ratedialogptr;
  121. Xint itemtype,myitemhit;
  122. Xhandle itemhandle;
  123. Xrect disprect;
  124. Xchar speechstr[256];
  125. X
  126. X#define TRUE        1
  127. X#define FALSE        0
  128. X#define WXORIGIN1    50
  129. X#define WYORIGIN1    50
  130. X#define WIDTH1        400
  131. X#define HEIGHT1        250
  132. X#define WXORIGIN2    50
  133. X#define WYORIGIN2    50
  134. X#define WIDTH2        400
  135. X#define HEIGHT2        250
  136. X
  137. Xzerostr(string)
  138. Xchar string[];
  139. X{
  140. X    string[0] = '\0';
  141. X}
  142. X
  143. X
  144. Xexit_to_other()
  145. X{
  146. X    transfer(null);
  147. X}
  148. X
  149. X
  150. Xexit_to_shell()
  151. X{
  152. X    chat("",voicemode,voicepitch,voicerate,LAST_CALL);
  153. X    exittoshell();
  154. X}
  155. X
  156. Xnop()
  157. X{
  158. X}
  159. X
  160. Xset_pitch()
  161. X{
  162. X    int err, tmp;
  163. X    char answer[255];
  164. X    
  165. X    zerostr(answer);
  166. X    showwindow(pitchdialogptr);
  167. X    drawdialog(pitchdialogptr);
  168. X    do
  169. X    {
  170. X        modaldialog(NULL,&myitemhit);
  171. X    } while (myitemhit != OKITEM3);
  172. X    getditem(pitchdialogptr,GENTEXTITEM,&itemtype,&itemhandle,&disprect);
  173. X    getitext(itemhandle,&answer);
  174. X    setitext(itemhandle,"");
  175. X    tmp = atoi(answer);
  176. X    hidewindow(pitchdialogptr);
  177. X    if ((tmp < 69) || (tmp > 450))
  178. X    {
  179. X        paramtext("Pitch","69\311450","","");
  180. X        alert(708,NULL);
  181. X    }
  182. X    else
  183. X    {
  184. X        voicepitch = tmp;
  185. X        speechpitch(thespeech,voicepitch,(short)voicemode);
  186. X        menu("Speech","Reset to defaults^4",itemenable);
  187. X    }
  188. X}
  189. X
  190. Xset_rate()
  191. X{
  192. X    int err, tmp;
  193. X    char answer[255];
  194. X    
  195. X    zerostr(answer);
  196. X    showwindow(ratedialogptr);
  197. X    drawdialog(ratedialogptr);
  198. X    do
  199. X    {
  200. X        modaldialog(NULL,&myitemhit);
  201. X    } while (myitemhit != OKITEM3);
  202. X    getditem(ratedialogptr,GENTEXTITEM,&itemtype,&itemhandle,&disprect);
  203. X    getitext(itemhandle,&answer);
  204. X    setitext(itemhandle,"");
  205. X    hidewindow(ratedialogptr);
  206. X    tmp = atoi(answer);
  207. X    if ((tmp < 85) || (tmp > 425))
  208. X    {
  209. X        paramtext("Rate","85\311425","","");
  210. X        alert(708,NULL);
  211. X    }
  212. X    else
  213. X    {
  214. X        voicerate = tmp;
  215. X        speechrate(thespeech,voicerate);
  216. X        menu("Speech","Reset to defaults^4",itemenable);
  217. X    }
  218. X}
  219. X
  220. Xset_natural_mode()
  221. X{
  222. X    voicemode = natural;
  223. X    menu("Speech","Robotic Speech",itemuncheck);
  224. X    menu("Speech","Natural Speech",itemcheck);
  225. X    menu("Speech","Reset to defaults^4",itemenable);
  226. X}
  227. X
  228. Xset_robotic_mode()
  229. X{
  230. X    voicemode = robotic;
  231. X    menu("Speech","Robotic Speech",itemcheck);
  232. X    menu("Speech","Natural Speech",itemuncheck);
  233. X    menu("Speech","Reset to defaults^4",itemenable);
  234. X}
  235. X
  236. Xreset_settings()
  237. X{
  238. X    voicemode = natural;
  239. X    menu("Speech","Robotic Speech",itemuncheck);
  240. X    menu("Speech","Natural Speech",itemcheck);
  241. X    voicepitch = DEFPITCH;
  242. X    voicerate = DEFRATE;
  243. X    menu("Speech","Reset to defaults^4",itemdisable);
  244. X}
  245. X
  246. Xenter_speech()
  247. X{
  248. X    showwindow(mydialogptr);
  249. X    drawdialog(mydialogptr);
  250. X    chat("Go ahead, bash the keebord",voicemode,voicepitch,voicerate,NORMAL_CALL);
  251. X    do
  252. X    {
  253. X        modaldialog(NULL,&myitemhit);
  254. X        if (myitemhit == SAYITEM)
  255. X        {
  256. X            getditem(mydialogptr,SAYTEXTITEM,&itemtype,&itemhandle,&disprect);
  257. X            getitext(itemhandle,&speechstr);
  258. X            chat(speechstr,voicemode,voicepitch,voicerate,NORMAL_CALL);
  259. X        }
  260. X    } while (myitemhit != CANCELITEM);
  261. X    hidewindow(mydialogptr);
  262. X}
  263. X
  264. X
  265. Xtell_about_me()
  266. X{
  267. X    int itemhit;
  268. X    
  269. X    showwindow(aboutdialogptr);
  270. X    drawdialog(aboutdialogptr);
  271. X    chat("Hello, I am Simple Speech, a sample speech program written in Cee using Apples Mackin Talk speech driver",voicemode,voicepitch,voicerate,NORMAL_CALL);
  272. X    chat("written by Jayson Haines, copy rite 9teen atee6.",voicemode,voicepitch,voicerate,NORMAL_CALL);
  273. X    chat("For more info, just hit the button.",voicemode,voicepitch,voicerate,NORMAL_CALL);
  274. X    do
  275. X    {
  276. X        modaldialog(NULL,&itemhit);
  277. X    } while ((itemhit != OKITEM) && (itemhit != MOREITEM));
  278. X    hidewindow(aboutdialogptr);
  279. X    if (itemhit == MOREITEM)
  280. X    {
  281. X        showwindow(about2dialogptr);
  282. X        drawdialog(about2dialogptr);
  283. X        chat("I am a giftware program, so you do not need to pay enee money to enn joy mee.",voicemode,voicepitch,voicerate,NORMAL_CALL);
  284. X        chat("If u like mee, keep mee. But, do not sell me..",voicemode,voicepitch,voicerate,NORMAL_CALL);
  285. X        do
  286. X        {
  287. X            modaldialog(NULL,&itemhit);
  288. X        } while (itemhit != OKITEM2);
  289. X        hidewindow(about2dialogptr);
  290. X    }
  291. X    showwindow(about3dialogptr);
  292. X    drawdialog(about3dialogptr);
  293. X    do
  294. X    {
  295. X        modaldialog(NULL,&itemhit);
  296. X    } while (itemhit != OKITEM3);
  297. X    hidewindow(about3dialogptr);
  298. X}
  299. X
  300. X
  301. Xspeak_file()
  302. X{
  303. X    char messagestr[256];
  304. X    
  305. X    if (!(err = getfile("TEXT",infilename)))
  306. X        return(0);
  307. X    if ((input_file = fopen (infilename, "r")) == NULL)
  308. X    {
  309. X        alert(1998,NULL);
  310. X        return(0);
  311. X    }
  312. X    /* SYNTAX: chat(string,mode,pitch,rateint,chatstat) */
  313. X    while ( (c = getc(input_file)) != EOF )
  314. X    {
  315. X        if (c=='\n')
  316. X        {
  317. X            str[i] = '\0';
  318. X            if (i>0)
  319. X                chat(str,voicemode,voicepitch,voicerate,NORMAL_CALL);
  320. X            i = 0;
  321. X        }
  322. X        else
  323. X            str[i++] = c;
  324. X    }
  325. X}
  326. X
  327. Xmenusetup()
  328. X{
  329. X    menu (applestring,"About SimpleSpeech^1\311",tell_about_me);
  330. X    menu (applestring,"About SimpleSpeech^1\311",itemenable);
  331. X    menu("File","Open Speech File/O^2",speak_file);
  332. X    menu("File","Open Speech File/O^2",itemenable);
  333. X    menu("File","Transfer\311^7",exit_to_other);
  334. X    menu("File","(-",nop);
  335. X    menu("File","Quit/Q",exit_to_shell);
  336. X    menu("Edit","Undo",nop);
  337. X    menu("Edit","Undo",itemdisable);
  338. X    menu("Edit","Copy/C",nop);
  339. X    menu("Edit","Copy/C",itemdisable);
  340. X    menu("Edit","Cut/X",nop);
  341. X    menu("Edit","Cut/X",itemdisable);
  342. X    menu("Edit","Paste/V",nop);
  343. X    menu("Edit","Paste/V",itemdisable);
  344. X    menu("Edit","Clear",nop);
  345. X    menu("Edit","Clear",itemdisable);
  346. X    menu("Speech","Enter some words of wisdom^3",enter_speech);
  347. X    menu("Speech","Enter some words of wisdom^3",itemenable);
  348. X    menu("Speech","Set Pitch",set_pitch);
  349. X    menu("Speech","Set Pitch",itemenable);
  350. X    menu("Speech","Set Rate",set_rate);
  351. X    menu("Speech","Set Rate",itemenable);
  352. X    menu("Speech","Reset to defaults^4",reset_settings);
  353. X    menu("Speech","Reset to defaults^4",itemdisable);
  354. X    menu("Speech","Robotic Speech",set_robotic_mode);
  355. X    menu("Speech","Robotic Speech",itemuncheck);
  356. X    menu("Speech","Natural Speech",set_natural_mode);
  357. X    menu("Speech","Natural Speech",itemcheck);
  358. X}
  359. X
  360. Xwindowsetup()
  361. X{
  362. X}
  363. X
  364. X
  365. Xmain()
  366. X{
  367. X    simpletools("About SimpleSpeech^1\311");
  368. X    menusetup();
  369. X    windowsetup();
  370. X    voicepitch = DEFPITCH;
  371. X    voicerate = DEFRATE;
  372. X    voicemode = natural;
  373. X    chat("",voicemode,voicepitch,voicerate,FIRST_CALL);
  374. X    mydialogptr = getnewdialog(21200,NULL,(windowptr) -1);
  375. X    aboutdialogptr = getnewdialog(21201,NULL,(windowptr) -1);
  376. X    about2dialogptr = getnewdialog(21202,NULL,(windowptr) -1);
  377. X    about3dialogptr = getnewdialog(18165,NULL,(windowptr) -1);
  378. X    ratedialogptr = getnewdialog(2300,NULL,(windowptr) -1);
  379. X    pitchdialogptr = getnewdialog(23620,NULL,(windowptr) -1);
  380. X    for (;;) simpleevents();
  381. X}
  382. ________This_Is_The_END________
  383. if test `wc -l < simplespeech.c` -ne 350; then
  384.     echo 'shar: simplespeech.c was damaged during transit'
  385.   echo '      (should have been 350 bytes)'
  386. fi
  387. fi        ; : end of overwriting check
  388. echo 'Extracting speech.h'
  389. if test -f speech.h; then echo 'shar: will not overwrite speech.h'; else
  390. sed 's/^X//' << '________This_Is_The_END________' > speech.h
  391. X#define    noexcpsfile    ''        /*signals Reader to use only basic rules*/
  392. X#define    noreader    'noReader'    /*signals SpeechOn to NOT bring in Reader*/
  393. X#define    fullunitt    -4000        /*error code for driver unit table full*/
  394. X
  395. Xtypedef    int        speecherr;
  396. Xtypedef    short        speechrecord[100];    /*of byte {Driver parm block, used internally*/
  397. Xtypedef    speechrecord    *speechpointer;        /*pointer to driver parm block*/
  398. Xtypedef    speechpointer    *speechhandle;        /*handle to driver parm block*/
  399. X
  400. Xtypedef    short    sex;
  401. X#define    male    0
  402. X#define    female    1
  403. X
  404. Xtypedef    short    f0mode;
  405. X#define    natural    0
  406. X#define    robotic    1
  407. X#define    nochange 2
  408. X
  409. Xtypedef    short    language;
  410. X#define    english 0
  411. X#define    french    1
  412. X#define    spanish    2
  413. X#define    german    3
  414. X#define    italian    4
  415. X
  416. Xtypedef struct {
  417. X    sex        thesex;
  418. X    language    thelanguage;
  419. X    int        therate;
  420. X    int        thepitch;
  421. X    f0mode        themode;
  422. X    char        thename[256];
  423. X    long        refcon;
  424. X    } voicerecord;
  425. Xtypedef    voicerecord    *voiceptr;
  426. X
  427. ________This_Is_The_END________
  428. if test `wc -l < speech.h` -ne 36; then
  429.     echo 'shar: speech.h was damaged during transit'
  430.   echo '      (should have been 36 bytes)'
  431. fi
  432. fi        ; : end of overwriting check
  433. echo 'Extracting chat.c'
  434. if test -f chat.c; then echo 'shar: will not overwrite chat.c'; else
  435. sed 's/^X//' << '________This_Is_The_END________' > chat.c
  436. X/*
  437. X    Speech utility - useful for a verbose about... box.
  438. X    Must have the Macintalk driver on the boot disk for this to run.
  439. X*/
  440. X
  441. X#include <speech.h>
  442. X#include <mem.h>
  443. X#include <chat.h>
  444. X
  445. X#define BUFFSIZE 4000L    /* arbitrary */
  446. Xextern speechhandle thespeech;
  447. X
  448. X
  449. Xint chat(string,mode,pitch,rate,chatstat)
  450. Xchar string[];
  451. Xint mode;
  452. Xint pitch;
  453. Xint rate;
  454. Xint chatstat;
  455. X{
  456. X    handle output;
  457. X    short i;
  458. X    long strlength;
  459. X    speecherr sperr;
  460. X
  461. X    if (chatstat == FIRST_CALL)
  462. X    {
  463. X        sperr = speechon("",&thespeech);
  464. X    }
  465. X    strlength = (long) strlen(string);
  466. X    speechpitch(thespeech,pitch,mode);
  467. X    speechrate(thespeech,rate);
  468. X    output = (handle)newhandle(0L);
  469. X    sperr = reader(thespeech,string,strlength,output);
  470. X    if (strlength < 1) 
  471. X        return(0);
  472. X    sperr = macintalk(thespeech,output);
  473. X    disposhandle(output);
  474. X    if (chatstat == LAST_CALL)
  475. X    {
  476. X        sperr = speechoff(thespeech);
  477. X    }
  478. X}
  479. X
  480. ________This_Is_The_END________
  481. if test `wc -l < chat.c` -ne 44; then
  482.     echo 'shar: chat.c was damaged during transit'
  483.   echo '      (should have been 44 bytes)'
  484. fi
  485. fi        ; : end of overwriting check
  486. echo 'Extracting chat.h'
  487. if test -f chat.h; then echo 'shar: will not overwrite chat.h'; else
  488. sed 's/^X//' << '________This_Is_The_END________' > chat.h
  489. X/*
  490. X    Just a few defines to beautify the beast.
  491. X */
  492. X
  493. X
  494. X#define FIRST_CALL 1
  495. X#define NORMAL_CALL -1
  496. X#define LAST_CALL -128
  497. X
  498. ________This_Is_The_END________
  499. if test `wc -l < chat.h` -ne 9; then
  500.     echo 'shar: chat.h was damaged during transit'
  501.   echo '      (should have been 9 bytes)'
  502. fi
  503. fi        ; : end of overwriting check
  504. exit 0
  505.