We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Edit String while running
Page Index Toggle Pages: 1
Edit String while running (Read 275 times)
Edit String while running
Feb 21st, 2009, 8:07pm
 
So, I'm working on a project in which I am trying to integrate an AI conversation robot.  I'm pretty new to [all] this but I've got it set up now to where I can type a message, and it will post to an online chatbot and then print the response.  My problem is that I have to change the string, and then rerun the program whenever I want to send another message.

My goal is to make it so that I can edit the string while it is running with an outside voice recognition software (i.e. Windows speech recognition)which will just type whatever is said into any text field.  Then I think I will need to use something along the lines of "countdown" to automatically send the string once you pause for a certain amount of time after you have spoken your message.

Does anyone have any advice on how this might be accomplished?  Is there a way to have a little text field that you can just edit while the sketch is running?

Here is my chat sketch so far:

import processing.serial.*;
import cc.arduino.*;

Arduino arduino;

void draw()
{
   String send = "Hello.";  //message to be sent to chatbot
   
   try {
       // Construct data
   String botid = "botid=f5d922d97e345aa1" + "&" + "custid=22345678";
   botid += "&" + "input=" + send;
   
           // Send data
       URL url = new URL("http://www.pandorabots.com/pandora/talk-xml");
       URLConnection conn = url.openConnection();
       conn.setDoOutput(true);
       OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
       wr.write(botid);
       wr.flush();
   
       // Get the response
       BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
       String back;
       while ((back = rd.readLine()) != null) {
           
           int p1 = back.indexOf("<that>")+6;  //the response is in between "<that>" and "</that>"
           int p2 = back.indexOf("</that>");
           String response = back.substring(p1, p2);  //process line
           println(response);
           
           }
       wr.close();
       rd.close();
   } catch (Exception e) {
   }
   noLoop();
}


Thanks!

Re: Edit String while running
Reply #1 - Feb 21st, 2009, 8:32pm
 
Look at the Libraries section, you have a number of GUI libraries, like controlP5, allowing to add a text field to a sketch.
Re: Edit String while running
Reply #2 - Feb 21st, 2009, 10:10pm
 
Great suggestion, thanks!  This controlP5 library is pretty awesome.  From a quick test, the Textfield allows input from external speech recognition software, so it is definitely a huge boost towards the end goal.  
Thanks again,
rlj2104
Page Index Toggle Pages: 1