//----------------------------\\
// NXT Pet Program \\
//----------------------------\\
// OnStart: Starts the program.
function OnStart() {
// Create NXT object and connect.
nxt = app.CreateNxt();
nxt.ShowDevices();
// Create layout.
CreateLayout();
// Create speech recgognition and set callbacks.
spchrcg = app.CreateSpeechRec();
spchrcg.SetOnReady(function() {
// Show listening popup.
app.ShowPopup("Listening...", "Short");
});
spchrcg.SetOnResult(function(results) {
DetermineOutcome(results[0])
});
}
// CreateLayout: Creates the main layout.
function CreateLayout() {
// Create layout.
lay_main = app.CreateLayout("linear", "VCenter,FillXY");
// Create button.
btn_talk = app.CreateButton("Start Listening", 0.3, 0.1);
btn_talk.SetMargins(0, 0.05, 0, 0);
// Set button callbacks
btn_talk.SetOnTouch(function() {
// Start recognizing speech.
spchrcg.Recognize();
});
// Add button to layout.
lay_main.AddChild(btn_talk);
// Add layout to app.
app.AddLayout(lay_main);
}
// DetermineOutcome: Chooses an action from the spoken phrase.
function DetermineOutcome(phrase) {
if(results[0] == "play") {
nxt.PlaySoundFile("Woops.rso", 0)
}
}
Does anyone know why?