how can i have it say it once and thats it but once evertime the function is run?

JaiJai
edited April 2016 in Library Questions

i found a sketch that has the pc say whatever i want but the issue is that it will keep saying over and over, also i notice that it is very slow at processing and while the pc says anything the video output becomes slow or freezes for like 500ms which is crazy

import guru.ttslib.*;

TTS Server;

void setup() {
  size(100, 100);
  Server = new TTS();
}

void draw() {
}

void mousePressed() {
  Server.speak("Good day?");
}

now if i was to use a function inside draw and every time that functions condition is met the pc will say what ever is on that function right? but the issue is that while that function is being used the pc will keep saying the same thing over and over so HOW can i get it to say what ever JUST ONCE ?

Tagged:

Answers

  • Does it work just once in draw? Is there a Server.stop() thing?

    import guru.ttslib.*;
    TTS Server;
    boolean speak = false;
    
    void setup() {
      size(100, 100);
      Server = new TTS();
    }
    
    void draw() {
      if(speak) {
        speak = false;
        Server.speak("Good day?");
      }
    }
    
    void mousePressed() {
      speak = true;
    }
    
  • im not sure if there is such functions i really hate how processing kinda hides everything deep in folders, Arduino's libraries are clear and fast to find including all their header and cpp files, trying to do the same with java in processing is a headache

  • edited April 2016

    import guru.ttslib.*; is not Processing.

    http://local-guru.net/blog/pages/ttslib

    Library: http://www.local-guru.net/projects/ttslib/ttslib-0.4.zip
    Source code: http://www.local-guru.net/projects/ttslib/ttslib-src-0.4.zip
    Last modified: ‎3/‎10/‎2013 ‏‎9:17 AM
    I just tried your sketch and the example from the library and worked worked fine.

    import guru.ttslib.*;
    
    TTS tts;
    
    void setup() {
      size(100,100);
      smooth();
      tts = new TTS();
    }
    
    void draw() {
      background(255);
      fill(255);
      ellipse( 35, 30, 25, 35 );
      ellipse( 65, 30, 25, 35 );
      fill(0);
      ellipse( 40, 35, 10, 10 );
      ellipse( 60, 35, 10, 10 );
      noFill();
      arc(50,50,50,50,0,PI);
    
    }
    
    void mousePressed() {
      tts.speak("Hi! I am a speaking Processing sketch");
    }
    
  • @AverageJoe okay so i tried your code and it did not work so my new question is where do i place this function from draw

      if (speak) {
        speak = false;
      }
    

    if i have multiple tabs and in every tab i have a speak function

  • edited April 2016

    Try using the mouseReleased method instead of mousePressed

  • Could there be a bad library install or something? I don't understand why a thread wouldn't stop looping a call.

  • @quark i dont see no diff in using one or the other, although i do know their is a diff

  • @AverageJoe i dont think so because aside from the modification im looking for everything works fine

  • if i use this

    void mouseReleased() {
      int loc = mouseX + mouseY*video.width;
      trackColor = video.pixels[loc];
      Server.speak("Tracking, please stand back about 4 feet please,..thank you");
    }
    

    but if i use this

    void LEDs()
    {
      Rectangle[] faces = opencv.detect();
    
      if (faces.length == 1) 
      {
        Server.speak("good day");
        port.write("S"); // LIGHT UP
      }
    
      else if (faces.length == 0)
      {
        delay(2500);
        Server.speak("good night");
        port.write("D"); // LIGHTS OFF
      }
    }
    

    it will keep saying as long as there is no face "good night, good night, good night, good night" lol just haywire and the same for if it sees a face "good day, good day, good day"

  • So what you want is, you only want it to say "good night" when the face goes away, and you only want it to say "good day" when the face turns up?

    In that case you'll need to change your logic a bit and detect if faces.length changed value in an iteration.

    Rectangle[] faces = opencv.detect();
      if (previousFacesLength != faces.length)
      {
    
    
        if (faces.length == 1) 
        {
          Server.speak("good day");
          port.write("S"); // LIGHT UP
        } else if (faces.length == 0)
        {
          delay(2500);
          Server.speak("good night");
          port.write("D"); // LIGHTS OFF
        }
        previousFacesLength = faces.length;
      }
    
  • @colouredmirrorball no sorry, but you missed understood. i want it to say it once not over and over while any of those statements are true or high

  • That's exactly what I tried to do. Not sure if it works though. Line 2 of my code should ensure the loop only runs when the amount of faces is different. Assuming of course you want to say a message as soon as a face (dis)appears.

  • yes this is what i like BUT only to be said once not over and over as it is in the draw "which just loops over and over as long as that function is running"

  • Yes. The trick is to rewrite the function so that it does not run if it shouldn't, even if it got called from draw(). Or if you don't like that, find some logic that doesn't call the function from draw. This is usually done by boolean flags. Is a face detected? Yes? Have you already called the function?

    -> yes: don't call it again -> no: call it and make sure you don't call it again (set a boolean to false).

Sign In or Register to comment.