home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d534 / term.lha / Term / Source.LZH / termSpeech.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  3KB  |  140 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: termSpeech.c
  6.  *    Created ..: Thursday 27-Jun-91 18:29
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    27-Jun-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* Local symbols. */
  18.  
  19. STATIC struct MsgPort        *NarratorPort;
  20. STATIC struct narrator_rb    *NarratorRequest;
  21. STATIC UBYTE             SpeechString[512],FormatString[512];
  22. struct Library            *TranslatorBase;
  23.  
  24.     /* DeleteSpeech():
  25.      *
  26.      *    Free the data associated with the speech function.
  27.      */
  28.  
  29. VOID
  30. DeleteSpeech()
  31. {
  32.     if(TranslatorBase)
  33.     {
  34.         CloseLibrary(TranslatorBase);
  35.  
  36.         TranslatorBase = NULL;
  37.     }
  38.  
  39.     if(NarratorRequest)
  40.     {
  41.         if(NarratorRequest -> message . io_Device)
  42.             CloseDevice(NarratorRequest);
  43.  
  44.         DeleteIORequest(NarratorRequest);
  45.  
  46.         NarratorRequest = NULL;
  47.     }
  48.  
  49.     if(NarratorPort)
  50.     {
  51.         DeleteMsgPort(NarratorPort);
  52.  
  53.         NarratorPort = NULL;
  54.     }
  55. }
  56.  
  57.     /* CreateSpeech():
  58.      *
  59.      *    Open translator.library and narrator.device, perform
  60.      *    the necessary setups for the speech function.
  61.      */
  62.  
  63. BYTE
  64. CreateSpeech()
  65. {
  66.     if(TranslatorBase = OpenLibrary("translator.library",0))
  67.     {
  68.         if(NarratorPort = CreateMsgPort())
  69.         {
  70.             if(NarratorRequest = (struct narrator_rb *)CreateIORequest(NarratorPort,sizeof(struct narrator_rb)))
  71.             {
  72.                     /* Any channel will do. */
  73.  
  74.                 NarratorRequest -> ch_masks        = &AnyChannel[0];
  75.                 NarratorRequest -> nm_masks        = 4;
  76.  
  77.                     /* This is a write request. */
  78.  
  79.                 NarratorRequest -> message . io_Command    = CMD_WRITE;
  80.                 NarratorRequest -> message . io_Data    = (APTR)SpeechString;
  81.  
  82.                 if(!OpenDevice("narrator.device",0,NarratorRequest,0))
  83.                 {
  84.                     SpeechSetup();
  85.  
  86.                     return(TRUE);
  87.                 }
  88.             }
  89.         }
  90.     }
  91.  
  92.     DeleteSpeech();
  93.  
  94.     return(FALSE);
  95. }
  96.  
  97.     /* Say(UBYTE *String,...):
  98.      *
  99.      *    Translate a string into phonemes and speak it.
  100.      */
  101.  
  102. VOID
  103. Say(UBYTE *String,...)
  104. {
  105.     if(TranslatorBase && SpeechConfig . Enabled)
  106.     {
  107.         va_list VarArgs;
  108.  
  109.         va_start(VarArgs,String);
  110.         VSPrintf(FormatString,String,VarArgs);
  111.         va_end(VarArgs);
  112.  
  113.         if(!Translate(FormatString,strlen(FormatString),SpeechString,511))
  114.         {
  115.             NarratorRequest -> message . io_Length = strlen(SpeechString);
  116.  
  117.             SendIO(NarratorRequest);
  118.             WaitIO(NarratorRequest);
  119.         }
  120.     }
  121. }
  122.  
  123.     /* SpeechSetup():
  124.      *
  125.      *    Transfer the configuration data into the setup.
  126.      */
  127.  
  128. VOID
  129. SpeechSetup()
  130. {
  131.     if(NarratorRequest)
  132.     {
  133.         NarratorRequest -> rate        = SpeechConfig . Rate;
  134.         NarratorRequest -> pitch    = SpeechConfig . Pitch;
  135.         NarratorRequest -> sex        = SpeechConfig . Sex;
  136.         NarratorRequest -> volume    = SpeechConfig . Volume;
  137.         NarratorRequest -> sampfreq    = SpeechConfig . Frequency;
  138.     }
  139. }
  140.