Can I use delay() in the void setup() or void keypressed() ? How can I make a delay in setup?
              in 
             Core Library Questions 
              •  
              2 years ago    
            
 
           
             Hi All
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
                
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
              
           
 
            
           
             the delay() command only seems to work in the void draw()
            
            
             I really need it, or something similar, to work inside the void setup() or alternatively another void such as the void keypressed().
            
            
             Does anyone have anything which will do this?
            
            
             More detail, and my code, follows:
            
            
             I need this because I am using the mac speech engine to write an *.aiff file, and then I am using the unix program 'sox' (downloaded and installed using fink) to conver the *.aiff file into a *.wav file.  I ned to do this because the next step in my project build wil be to read the *.wav file into toxiclibs' audioutils, which seem to only support *.wav files right now.  This is so I can run it through OpenAL and get some 3D sound action on the go...
            
            
             Basically the delay is needed because sox won't run if it's input file has not yet been created.  Thus I need to give the mac speech engine time (about 100ms) to write the *.aiff file before I try to run sox on it.  An alternative would be to tell processing "while *.aiff does not exist, wait, else run sox"...  So if anyone knows how to ask processing whether a file exists yet, this would also solve my problem.
            
            
             Many thanks in advance, Sam
            
            
             Running in OSX 10.6, on a 2009 MacBookPro...
            
            
              void draw() {
             
             
              int a=1;
             
             
              String sa = nf(a, 2);
             
             
              println(sa); // prints "01"
             
             
              //String fileName = "number 01";
             
             
              String fileName = ("number" + sa);
             
             
              println(fileName); // prints "number01"
             
             
              String pathName = "/Users/SammyJ/Documents/Processing/RSS_feeds/_17c_aiff_to_wav_WithStop/data/";
             
             
              // --- TITLE ---
             
             
              String pathAndFile = (pathName + "MaleTitle_" + fileName);
             
             
              // FIRST write out the .aiff file
             
             
              String fulltext1 = ("say -o " + pathAndFile + ".aiff this is title number " + sa);
             
             
              println(fulltext1);
             
             
              String[] fulltext = split(fulltext1, " ");
             
             
              exec(fulltext);
             
             
              // SECOND convert it to a .wav file
             
             
              delay(100); // sox will not work until *.aiff file has been written
             
             
              // delay() only works inside a void draw() loop - not outside the loops, nor inside void setup()
             
             
              // 50ms seems to be the perfect delay for this length of text to speech processing!
             
             
              fulltext1 = ("/sw2/bin/sox " + pathAndFile + ".aiff " + pathAndFile + ".wav");
             
             
              println(fulltext1);
             
             
              fulltext = split(fulltext1, " ");
             
             
              exec(fulltext);
             
             
              //??? ? ? ? ? ? ??  GOT TO HERE - need to speak the text from the wav file next...
             
             
              // LAST speak the text if ran correctly...
             
             
              fulltext1 = ("say this is title number " + sa);
             
             
              fulltext = split(fulltext1, " ");
             
             
              exec(fulltext);
             
             
              exit(); // This is required because void draw() now encapsulates the file
             
             
              }
             
             
              
              1  
            
 
            
 
 
          