/* speech.c - speech routines for robot using GI SPO256-AL2 Narrator
   chip. Written in IC.

    Joe Larkin
    EEL5934
    */


/*arrays to hold vocabulary string (phonem data) and pointers to words in that
string*/
char words[100];
int vocab[20];

/*initialize vocabulary - to add more words increase size of words[] and
  add new phonems strings. End each word with a pause to shut the chip
  up and seperate words with 255. Have vocab contain offset into array
  words[] to point to beginning of words */

void init_words() {
/*noise   */
words[0] = 56;
words[1] = 5;
words[2] = 55;
words[3] = 4 ;
words[4] = 255;
vocab[0] = 0;

/*light */
words[5] = 1;
words[6] = 45;
words[7] = 6;
words[8] = 17;
words[9] = 4;
words[10] = 255;
vocab[1] = 5;

/* IR */
words[11] = 24;
words[12] = 6 ;
words[13] = 3;
words[14] = 59;
words[15] = 4;
words[16] = 255;
vocab[2] = 11;

/*heat*/
words[17] = 27;
words[18] = 19;
words[19] = 2;
words[20] = 17;
words[21] = 4;
words[22] = 255;
vocab[3] = 17;

/* sleeping */
words[23] = 55;
words[24] = 45;
words[25] = 19;
words[26] = 9;
words[27] = 12;
words[28] = 44;
words[29] = 4;
words[30] = 255;
vocab[4] = 23;

/* scanning */
words[31] = 55;
words[32] = 55;
words[33] = 2;
words[34] = 42;
words[35] = 26;
words[36] = 11;
words[37] = 12;
words[38] = 44;
words[39] = 4;
words[40] = 255;
vocab[5] = 31;

/* o.k. */
words[41] = 53;
words[42] = 3;
words[43] = 42;
words[44] = 7;
words[45] = 20;
words[46] = 4;
words[47] = 255;
vocab[6] = 41;

/* zero */
words[48] = 43;
words[49] = 60;
words[50] = 53;
words[51] = 4;
words[52] = 255;
vocab[7] = 48;

/* one */
words[53] = 46;
words[54] = 15;
words[55] = 15;
words[56] = 11;
words[57] = 4;
words[58] = 255;

vocab[8] = 53;

/* two */
words[59] = 13;
words[60] = 31;
words[61] = 4;
words[62] = 255;
vocab[9] = 59;

/* three */
words[63] = 29;
words[64] = 14;
words[65] = 19;
words[66] = 4;
words[67] = 255;
vocab[10] = 63;

/* four  */
words[68] = 40;
words[69] = 40;
words[70] = 58;
words[71] = 4;
words[72] = 255;
vocab[11] = 68;

/* five */
words[73] = 40;
words[74] = 40;
words[75] = 6;
words[76] = 35;
words[77] = 4;
words[78] = 255;
vocab[12] = 73;

/* hunting */
words[79] = 27;
words[80] = 15;
words[81] = 11;
words[82] = 13;
words[83] = 12;
words[84] = 44;
words[85] = 4;
words[86] = 255;
vocab[13] = 79;

/* wander */
words[87] = 46;
words[88] = 23;
words[89] = 11;
words[90] = 21;
words[91] = 51;
words[92] = 4;
words[93] = 255;
vocab[14] = 87;


/*  Some additional words from G. McComb book

    I           24  6
    am           7  7 16
    a           24
    talking     13 23 23  2 42 12 44
    computer    42 15 16  9 49 22 13 51
    wordsing     13  7 55  2 13 12 44
    one         46 15 15 11
    two         13 21
    three       29 14 19
    four        40 40 58
*/
}

/* talk translates process priorities into words and then outputs
to SPO256-AL2 chip */
void talk(int i) {
    if (i==0) i = vocab[2];  /* IR */
    if (i==1) i = vocab[3];  /*heat*/
    if (i==19) i = vocab[13]; /*hunting*/
    if (i==20) i = vocab[5]; /*scanning*/
    if (i==21) i = vocab[1]; /*light*/
    if (i==22) i = vocab[0]; /*noise*/
    if (i==23) i = vocab[4]; /*sleeping*/
    if (i==24) i = vocab[14]; /*wander*/
    if (i==100) i = vocab[6];

    /*say the word - voice output port is at $2400*/
    while(words[i] != 255) {
         poke(0x2400,0x00);
         poke(0x2400,words[i]);
         while(peek(0x1000)<128) {};
         i++;
      }

   }


/*just say word number i in words[]*/
void say(int i) {
    i = vocab[i];
    while(words[i] != 255) {
         poke(0x2400,0x00);
         poke(0x2400,words[i]);
         while(peek(0x1000)<128) {};
         i++;
      }

   }


/*output a pause - good if routines crash or if need to shutup quick*/

void quiet() {
         poke(0x2400,0x00);
         poke(0x2400,0x04);
         while(peek(0x1000)<128) {};
         }

