First let's create our flow class. Each app will have a top-level flow object. In the Package Explorer, right-click on your project Hello and select New / Class. Name it App1. Here's the Package Explorer (ignore Model.java for now)
You should then be able to edit the App1.java file, adding the following:
import org.speakright.core.*;
public class App1 extends SRApp {
public App1() {
add(new PromptFlow("Welcome to SpeakRight!"));
}
}
This flow will simply say "Welcome to SpeakRight!" and hang up.
There are a number of ways to run your app. Eventually you'll embed it in a Java servlet and point a VoiceXML browser at it. But for now, let's use the ITest console utility that comes with SpeakRight. Switch back to Hello.java, which should have been created when you made the project.
import org.speakright.itest.*;
public class SRHello {public static void main(String[] args) {
System.out.println("SRHello");
SRInteractiveTester tester = new SRInteractiveTester();
SRFactory factory = new SRFactory();
SRRunner runner = factory.createRunner("", "", "", null);
App1 app = new App1();
tester.run(run, app);
System.out.println("Done.");}
}
For a simple app we pass empty strings to createRunner. For more information on the parameters to pass to createRunner, see Initialization.
OK. Let's run the app. In the Package Explorer, find your class file Hello.java, right-click and select Run As and Java Application. ITest runs in the java console. You should see this in the Console view
The "1>" indicates this is the first turn. On each turn your app will create a VoiceXML page. Type "go" and press Enter. You'll see some logging and the VoiceXML:
When a SpeakRight app is in a java servlet, this VoiceXML page would be sent to the VoiceXML server (as part of an HTTP reply). The server would execute the page, and send back the results (as a new HTTP request) . In ITest, we take the place of the VoiceXML server. In the "go" command we specify the results of executing the most recent page. In this case, the page is output only; it only plays text-to-speech audio, so there is no user input to send back. So type "go" and press Enter again. The app has nothing more to do so it finishes, along with ITest.
That's it. You've created your first SpeakRight app. To see how a fully-functioned app is written see Simpsons Demo, or get more documentation at Table Of Contents.
2 comments:
I've tried your code in eclipse.
I had this error :
the "SRFactory" could not be resolved to a type
Actually, I couldn't find "SRFactory" class in Speakright jar file
I'd like to know how can I fix this problem
Yes , i also have the same problem SRFactory undeclared .
Post a Comment