Interfacing Emic 2 text to speech module with I2c on Arduino

I've been trying to use the emic text to speech module, (Emic 2 Text-to-Speech module : ID 924 : $59.95 : Adafruit Industries, Unique & fun DIY electronics and kits) in my code while using I2c communication with my Arduinos. I have tested the I2c with serial.print statments of the text when getting a 1 or 0 from the master arduino.But when I add the emic.speak command the whole program doesn't run at all, but it is still verified.When I run the module alone it's fine but when i put it in any other code it doesn't work. Any help would be greatly appreciated.

Slave-

#include <Wire.h>
#include <SoftwareSerial.h>  // Needed by the EMIC2 library
#include <SD.h>  // Needed by the EMIC2 library, though not utilized in this example
#include "EMIC2.h"



#define RX_PIN 0  // Connect SOUT pin of the Emic 2 module to the RX pin
#define TX_PIN 1  // Connect SIN pin of the Emic 2 module to the TX pin

EMIC2 emic;
void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600); 
  emic.begin(RX_PIN, TX_PIN); //set' s up the emic pins
    
  emic.setVoice(8);// 
}

void loop() {
  
}


void receiveEvent(int howMany) {
  while (Wire.available()) { 
  int x = Wire.read();    
  if (x == 1){
  emic.speak("yes");//HERE is the one line that if I add the code just doesnt work.
  Serial.print("yes");  
  }
  if (x == 0){
  Serial.print("no");
  
  }
  }
           // print the integer
}

Master-

#include<Wire.h>
void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;
byte y = 1;

void loop() {
  Wire.beginTransmission(8); // transmit to device #8       // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting
  delay(3000);

  Wire.beginTransmission(8); // transmit to device #8       // sends five bytes
  Wire.write(y);              // sends one byte
  Wire.endTransmission();    // stop transmitting
  delay(3000);

It looks to me like you are trying to use the hardware serial pins to talk to the emic instance AND to debug your program. I can't see how that is ever going to work.

I'm also going to guess that the emic object expects interrupts to be enable, so speak() can do it's thing. When your interrupt handler is executing (the receiveEvent() function), interrupts are disabled.

You could, if you KNEW what you were doing, re-enable interrupts when the ISR is running, but that is NOT guaranteed to work.

What you should do is set a flag in the ISR, and then, in loop(), when the ISR ends, see what the flag is set to, and perform the required action, then clear the flag.

Hi thank you PaulS for the response, I've been spending all morning trying to implement re-enabling interrupts and flags, and have still gotten the same result. I'm not sure that my code is correct, if you could show me an example of how I should set a flag or enable interrupts in this code specifically that would be great. Still, a newcomer to Arduino and still don't understand exactly what to do.

if you could show me an example of how I should set a flag or enable interrupts in this code specifically that would be great.

That you are struggling means that you should NOT be trying to reenable interrupts.

Make x a global, and deal with it in the loop() function.

int x = -1;

void receiveEvent(int howMany)
{
  while (Wire.available())
  {
     x = Wire.read();
  }
}

void loop()
{
   if(x == 1)
   {
      emic.speak("yes");//HERE is the one line that if I add the code just doesnt work.
      Serial.print("yes");
      x = -1;
   }
   else if(x == 0)
   {
      emic.speak("no");
      Serial.print("no");
      x = -1;
   }
}