IMP & Parallax Emic2 Text-to-Speech Module

Still very messy and many features missing, but the general setup works:

CODE
`
::IMP_ID <- hardware.getimpeeid();
server.log(“STARTING DEVICE:”+IMP_ID);

::SpeechReady <- 0;
::speechSerial <- hardware.uart57;

// Serial Communication with EMic2
function readSerial()
{
local serialConn = hardware.uart57;
local readBuffer = blob(1);
local byte;
local byteIndex = 0;
local str = “”;

while((byte=serialConn.read())!=-1){
    readBuffer.writen(byte, 'b'); //Can comment if you don't want to use the blob
    server.log(format("Byte %d = %d = 0x%2X = %c", byteIndex++, byte, byte, byte)); //Can comment if you don't want individual byte logging
    str += byte.tochar(); //Converts integer read by UART into ASCII char for string representation
}
if(str.len() > 0){ //Function may get called by callback when no data is present - no need to log
    server.log("Read String Representation = " + str);
}



if(SpeechReady==0)
{
    SpeechReady = 1;
    
    server.log("speak");

     serialConn.write('\

'); // Send a CR in case the system is already up
serialConn.flush();

    serialConn.write('N'); // Select voice
serialConn.write("1"); // Our voice from Beyond
serialConn.write('\

‘); // Terminate the voice command
serialConn.write(‘S’); // Select voice
serialConn.write(“I am Redddeee!”);
serialConn.write(’
’); // Terminate the voice command

server.log("SAID");
}

// wait till spoken
//while((byte=serialConn.read().tochar())!=":"){}

}`

To anyone trying this, I would recommend, setting up clean functions for speaking and voice settings, etc.
Also always wait till one text is finished and the module is ready.
Who knows, I might do a ‘class’ on this.