clean this up and make it more organized.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14000 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West
2009-06-27 00:38:46 +00:00
parent 87e6e63ebb
commit 3be99f4aa0
13 changed files with 0 additions and 13 deletions

View File

@@ -0,0 +1,6 @@
This directory contains a javascript auto attendant which queries
FreeSWITCH for name / extension information rather than using
hardcoded values. It requires a wave file which says:
Please spell the name of the person using your telephone keypad
last name first. Press 1 for Q or Z.

View File

@@ -0,0 +1,242 @@
/*
* File: aadir.js
* Purpose: Auto Attendant directory.
* Machine: OS:
* Author: John Wehle Date: November 6, 2008
*
* Copyright (c) 2008 Feith Systems and Software, Inc.
* All Rights Reserved
*/
var digitTimeOut = 3000;
var interDigitTimeOut = 1000;
var absoluteTimeOut = 10000;
var base_dir = session.getVariable ("base_dir");
var domain = session.getVariable ("domain");
var voicemail_path = base_dir + "/storage/voicemail/default/" + domain + "/";
var file_exts = [ ".wav", ".mp3" ];
var extRE = /^1[0-9][0-9][0-9]$/g;
var operator = "operator";
var directory;
var directory_camelcase;
var translations = [ "0",
"QZ", "ABC", "DEF",
"GHI", "JKL", "MNO",
"PQRS", "TUV", "WXYZ" ];
var extension = "";
var dtmf_digits = "";
function load_directory ()
{
var i;
var name;
var number;
var dir = apiExecute ("xml_locate", "directory domain name " + domain);
var re = /\s+$/g;
var length = dir.search (re);
if (length == -1)
length = dir.length;
dir = dir.substring (0, length);
var xdir = new XML (dir);
directory = new Array ();
i = 0;
re = /[^A-Z0-9\s]/gi;
for each (var variables in xdir.groups.group.users.user.variables) {
name = "";
number = "";
for each (variable in variables.variable) {
if (variable.@name.toString() == "effective_caller_id_name")
name = variable.@value.toString();
if (variable.@name.toString() == "effective_caller_id_number")
number = variable.@value.toString();
}
if (name.length == 0 || number.length == 0 || number.search (extRE) == -1)
continue;
directory[i] = new Array (2);
directory[i][0] = name.replace (re, "");
directory[i][1] = number;
i++;
}
}
function build_camelcase_directory ()
{
var i;
var fname;
var lname;
var fre = /^[A-Z0-9]+/gi;
var lre = /[A-Z0-9]+$/gi;
directory_camelcase = new Array (directory.length);
for (i = 0; i < directory.length; i++) {
directory_camelcase[i] = new Array (2);
directory_camelcase[i][0] = "";
directory_camelcase[i][1] = 0;
fname = directory[i][0].match (fre);
lname = directory[i][0].match (lre);
if (fname.length != 1 || lname.length != 1) {
console_log ("err", "Can't parse " + directory[i][0] + " for directory\n");
continue;
}
directory_camelcase[i][0] = lname[0] + fname[0];
directory_camelcase[i][1] = directory[i][1];
}
}
function directory_lookup (digits)
{
var i;
var match = "";
var pattern = "^";
var re;
if (digits.length && digits[0] == 0)
return 0;
for (i = 0; i < digits.length; i++) {
if (isNaN (parseInt (digits[i], 10)))
return -1;
pattern += "[" + translations[parseInt (digits[i], 10)] + "]";
}
re = new RegExp (pattern, "i");
for (i = 0; i < directory_camelcase.length; i++)
if (directory_camelcase[i][0].search (re) != -1) {
if (! isNaN (parseInt (match, 10)))
return "";
match = directory_camelcase[i][1];
}
if (isNaN (parseInt (match, 10)))
return -1;
return match;
}
function on_dtmf (session, type, obj, arg)
{
if (type == "dtmf") {
dtmf_digits += obj.digit;
extension = directory_lookup (dtmf_digits)
return false;
}
return true;
}
function directory_prompt ()
{
var choice;
var index;
var repeat;
extension = "";
choice = "";
repeat = 0;
while (session.ready () && repeat < 3) {
/* play phrase - if digit keyed while playing callback will catch them*/
session.sayPhrase ("feith_aa_directory", "#", "", on_dtmf, "");
choice = dtmf_digits;
while ( isNaN (parseInt (extension, 10)) ) {
if (! session.ready ())
return "";
dtmf_digits = session.getDigits (1, '#', digitTimeOut,
interDigitTimeOut, absoluteTimeOut);
choice += dtmf_digits;
extension = directory_lookup (choice);
}
if (parseInt (extension, 10) >= 0)
break;
session.sayPhrase ("voicemail_invalid_extension", "#", "", on_dtmf, "");
dtmf_digits = "";
extension = "";
choice = "";
repeat++;
session.flushDigits ();
}
return extension;
}
var choice = "";
var fd;
var i;
var recorded_name;
session.answer ();
session.execute("sleep", "1000");
load_directory ();
build_camelcase_directory ();
dtmf_digits = "";
session.flushDigits ();
choice = directory_prompt ();
if (! session.ready ()) {
session.hangup();
exit();
}
if ( isNaN (parseInt (choice, 10)) || parseInt (choice, 10) <= 0) {
session.execute ("transfer", operator + " XML default");
exit();
}
for (i = 0; i < file_exts.length; i++) {
recorded_name = voicemail_path + choice + "/recorded_name" + file_exts[i];
fd = new File (recorded_name);
if (fd.exists) {
session.streamFile (recorded_name);
break;
}
}
session.execute ("phrase", "spell," + choice);
session.execute ("transfer", choice + " XML default");
exit();

66
scripts/javascript/api.js Normal file
View File

@@ -0,0 +1,66 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* api.js Demo javascript FSAPI Interface
*
* To use this script:
* 1) Put it in $prefix/scripts. (eg /usr/local/freeswitch/scripts)
* 2) Load mod_xml_rpc and point a browser to your FreeSWITCH machine.
* http://your.freeswitch.box:8080/api/jsapi?api.js
*/
/* Other possible js commands */
//env = request.dumpENV("text");
//xmlenv = new XML(request.dumpENV("xml"));
//request.addHeader("js-text", "You were in a javascript script");
if (session) {
request.write("Don't call me from the dialplan silly! I'm a web interface today.\n");
consoleLog("err", "Invalid usage!\n");
exit();
}
request.write("Content-Type: text/html\n\n");
request.write("<title>FreeSWITCH Command Portal</title>");
request.write("<h2>FreeSWITCH Command Portal</h2>");
request.write("<form method=post><input name=command size=40> ");
request.write("<input type=submit value=\"Execute\">");
request.write("</form><hr noshade size=1><br>");
if ((command = request.getHeader("command"))) {
cmd_list = command.split(" ");
cmd = cmd_list.shift();
args = cmd_list.join(" ");
if ((reply = apiExecute(cmd, args))) {
request.write("<br><B>Command Result</b><br><pre>" + reply + "\n</pre>");
}
}

View File

@@ -0,0 +1,21 @@
function onPlayFile(s, type, obj, arg)
{
try {
if (type == "dtmf") {
console_log("info", "DTMF digit: " + s.name + " [" + obj.digit + "] len [" + obj.duration + "]\n\n");
session.execute("phrase", "spell," + obj.digit);
}
} catch (e) {
console_log("err", e + "\n");
}
return true;
}
session.answer();
while(session.ready()) {
session.streamFile(argv[0], onPlayFile);
}

319
scripts/javascript/pizza.js Normal file
View File

@@ -0,0 +1,319 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* pizza.js ASR Demonstration Application
*
*/
include("js_modules/SpeechTools.jm");
function on_dtmf(a, b, c) {}
var dft_min = 100;
var dft_confirm = 600;
/***************** Initialize The Speech Detector *****************/
var asr = new SpeechDetect(session, "lumenvox", "127.0.0.1");
/***************** Be more verbose *****************/
asr.debug = 1;
/***************** Set audio params *****************/
asr.setAudioBase("/root/pizza/");
asr.setAudioExt(".wav");
/***************** Unload the last grammar whenever we activate a new one *****************/
asr.AutoUnload = true;
/***************** Create And Configure The Pizza *****************/
var pizza = new Object();
/***************** Delivery Or Take-Out? *****************/
pizza.orderObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.orderObtainer.setGrammar("order", "pizza/order.gram", "result", dft_min, dft_confirm, true);
pizza.orderObtainer.setTopSound("GP-DeliveryorTakeout");
pizza.orderObtainer.setBadSound("GP-NoDeliveryorTake-out");
pizza.orderObtainer.addItem("Delivery,Pickup");
/***************** What Size? *****************/
pizza.sizeObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.sizeObtainer.setGrammar("size", "pizza/size.gram", "result", dft_min, dft_confirm, true);
pizza.sizeObtainer.setTopSound("GP-Size");
pizza.sizeObtainer.setBadSound("GP-NI");
pizza.sizeObtainer.addItem("ExtraLarge,Large,Medium,Small,TotallyHumongous");
/***************** What Type Of Crust? *****************/
pizza.crustObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.crustObtainer.setGrammar("crust", "pizza/crust.gram", "result", dft_min, dft_confirm, true);
pizza.crustObtainer.setTopSound("GP-Crust");
pizza.crustObtainer.setBadSound("GP-NI");
pizza.crustObtainer.addItem("HandTossed,Pan,Thin");
/***************** Specialty Or Custom? *****************/
pizza.specialtyObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.specialtyObtainer.setGrammar("specialty", "pizza/specialty.gram", "result", dft_min, dft_confirm, true);
pizza.specialtyObtainer.setTopSound("GP-SpecialtyList");
pizza.specialtyObtainer.setBadSound("GP-NI");
pizza.specialtyObtainer.addItem("Hawaiian,MeatLovers,Pickle,Dali,Vegetarian");
/***************** Which Specialty? *****************/
pizza.typeObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.typeObtainer.setGrammar("type", "pizza/specialtyorcustom.gram", "result", dft_min, dft_confirm, true);
pizza.typeObtainer.setTopSound("GP-SpecialtyorCustom");
pizza.typeObtainer.setBadSound("GP-NI");
pizza.typeObtainer.addItem("Specialty,Custom");
/***************** What Toppings? *****************/
pizza.toppingsObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.toppingsObtainer.setGrammar("toppings", "pizza/pizza.gram", "result.toppinglist.ingredient", dft_min, 400, true);
pizza.toppingsObtainer.setTopSound("GP-Toppings");
pizza.toppingsObtainer.setBadSound("GP-NI");
pizza.toppingsObtainer.addItem("anchovie,artichoke,canadianbacon,everything,extracheese,garlic,goatcheese,bellpepper");
pizza.toppingsObtainer.addItem("mango,mushroom,olives,onions,pepperoni,pickle,pineapple,salami,sausage,shrimp,spinach,ham");
/***************** Change Delivery Or Size Or Crust, Add/Rem Toppings Or Start Over *****************/
pizza.arsoObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.arsoObtainer.setGrammar("arso", "pizza/arso.gram", "result", 500, 250, true);
pizza.arsoObtainer.setTopSound("GP-ARSO");
pizza.arsoObtainer.setBadSound("GP-NI");
pizza.arsoObtainer.addItem("delivery,size,crust,startover,add_topping,rem_topping");
/***************** Yes? No? Maybe So? *****************/
pizza.yesnoObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.yesnoObtainer.setGrammar("yesno", "pizza/yesno.gram", "result", 500, 250, true);
pizza.yesnoObtainer.setBadSound("GP-NI");
pizza.yesnoObtainer.addItem("yes,no");
/***************** Get Some Information *****************/
pizza.get = function(params, confirm) {
for(;;) {
if (!session.ready()) {
return false;
}
var main_items = params.run();
if (confirm && params.needConfirm) {
pizza.yesnoObtainer.setTopSound("Confirm" + main_items[0]);
var items = pizza.yesnoObtainer.run();
if (items[0] == "yes") {
break;
}
} else {
break;
}
}
return main_items;
};
/***************** Is This Right? *****************/
pizza.check = function () {
if (!session.ready()) {
return false;
}
asr.streamFile("GP-You_ordered_a");
asr.streamFile(pizza.size);
asr.streamFile(pizza.crust);
if (pizza.type == "Specialty") {
asr.streamFile(pizza.specialty);
asr.streamFile("pizza");
} else {
asr.streamFile("pizza");
asr.streamFile("GP-With");
for (key in pizza.toppings) {
if (pizza.toppings[key] == "add") {
asr.streamFile(key);
}
}
}
pizza.yesnoObtainer.setTopSound("GP-WasThisRight");
items = pizza.yesnoObtainer.run();
return items[0] == "yes" ? true : false;
};
/***************** Let's Remove The Toppings *****************/
pizza.clearToppings = function() {
if (!session.ready()) {
return false;
}
if (pizza.toppings) {
delete pizza.toppings;
}
pizza.have_toppings = false;
pizza.toppings = new Array();
}
/***************** Clean Slate *****************/
pizza.init = function() {
if (!session.ready()) {
return false;
}
pizza.add_rem = "add";
pizza.order = pizza.size = pizza.crust = pizza.type = false;
pizza.toppingsObtainer.setTopSound("GP-Toppings");
pizza.specialty = false;
pizza.clearToppings();
pizza.said_greet = false;
}
/***************** Welcome! *****************/
pizza.greet = function () {
if (!session.ready()) {
return false;
}
if (!pizza.said_greet) {
asr.streamFile("GP-Greeting");
pizza.said_greet = true;
}
};
/***************** Collect Order Type *****************/
pizza.getOrder = function() {
if (!session.ready()) {
return false;
}
if (!pizza.order) {
var items = pizza.get(pizza.orderObtainer, true);
pizza.order = items[0];
}
};
/***************** Collect Size *****************/
pizza.getSize = function() {
if (!session.ready()) {
return false;
}
if (!pizza.size) {
var items = pizza.get(pizza.sizeObtainer, true);
pizza.size = items[0];
}
};
/***************** Collect Crust *****************/
pizza.getCrust = function() {
if (!session.ready()) {
return false;
}
if (!pizza.crust) {
var items = pizza.get(pizza.crustObtainer, true);
pizza.crust = items[0];
}
};
/***************** Collect Pizza Type *****************/
pizza.getType = function() {
if (!session.ready()) {
return false;
}
if (!pizza.type) {
var items = pizza.get(pizza.typeObtainer, true);
pizza.type = items[0];
}
};
/***************** Collect Toppings *****************/
pizza.getToppings = function() {
if (!session.ready()) {
return false;
}
if (pizza.type == "Specialty" && !pizza.specialty) {
var items = pizza.get(pizza.specialtyObtainer, true);
pizza.specialty = items[0];
pizza.have_toppings = true;
} else if (!pizza.have_toppings) {
toppings = pizza.get(pizza.toppingsObtainer, false);
for(x = 0; x < toppings.length; x++) {
pizza.toppings[toppings[x]] = pizza.add_rem;
}
pizza.have_toppings = true;
}
};
/***************** Modify Pizza If You Don't Like It *****************/
pizza.fix = function() {
if (!session.ready()) {
return false;
}
asr.streamFile("GP-Wanted-No");
arso = pizza.get(pizza.arsoObtainer, false);
for (x = 0; x < arso.length; x++) {
if (arso[x] == "delivery") {
pizza.order = false;
} else if (arso[x] == "size") {
pizza.size = false;
} else if (arso[x] == "crust") {
pizza.crust = false;
} else if (arso[x] == "startover") {
pizza.init();
} else {
if (pizza.type == "Specialty") {
asr.streamFile("GP-ChangeSpec");
pizza.type = false;
pizza.clearToppings();
} else {
pizza.have_toppings = false;
if (arso[x] == "add_topping") {
pizza.add_rem = "add";
pizza.toppingsObtainer.setTopSound("GP-Adding");
} else {
pizza.add_rem = "rem";
pizza.toppingsObtainer.setTopSound("GP-Remove");
}
}
}
}
};
/***************** Tie It All Together *****************/
pizza.run = function() {
pizza.init();
for(;;) {
if (!session.ready()) {
break;
}
pizza.greet();
pizza.getOrder();
pizza.getSize();
pizza.getCrust();
pizza.getType();
pizza.getToppings();
if (pizza.check()) {
asr.streamFile(pizza.order);
break;
} else {
pizza.fix();
}
}
};
/***************** Begin Program *****************/
session.answer();
pizza.run();
asr.stop();

View File

@@ -0,0 +1,358 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* pizza.js ASR Demonstration Application
*
*/
include("js_modules/SpeechTools.jm");
function on_dtmf(a, b, c) {}
var dft_min = 40;
var dft_confirm = 70;
/***************** Initialize The Speech Detector *****************/
var asr = new SpeechDetect(session, "pocketsphinx");
/***************** Be more verbose *****************/
asr.debug = 1;
/***************** Set audio params *****************/
asr.setAudioBase("/root/pizza/");
asr.setAudioExt(".wav");
/***************** Unload the last grammar whenever we activate a new one *****************/
asr.AutoUnload = true;
/***************** Create And Configure The Pizza *****************/
var pizza = new Object();
/***************** Delivery Or Take-Out? *****************/
pizza.orderObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.orderObtainer.setGrammar("pizza_order", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.orderObtainer.setTopSound("GP-DeliveryorTakeout");
pizza.orderObtainer.setBadSound("GP-NoDeliveryorTake-out");
pizza.orderObtainer.addItemAlias("Delivery", "Delivery");
pizza.orderObtainer.addItemAlias("Takeout,Pickup", "Pickup");
/***************** What Size? *****************/
pizza.sizeObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.sizeObtainer.setGrammar("pizza_size", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.sizeObtainer.setTopSound("GP-Size");
pizza.sizeObtainer.setBadSound("GP-NI");
pizza.sizeObtainer.addItemAlias("^Extra\\s*Large", "ExtraLarge");
pizza.sizeObtainer.addItemAlias("^Large$", "Large");
pizza.sizeObtainer.addItemAlias("^Medium$", "Medium");
pizza.sizeObtainer.addItemAlias("^Small$", "Small");
pizza.sizeObtainer.addItemAlias("^Humongous$,^Huge$,^Totally\\s*Humongous$,^Totally", "TotallyHumongous");
/***************** What Type Of Crust? *****************/
pizza.crustObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.crustObtainer.setGrammar("pizza_crust", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.crustObtainer.setTopSound("GP-Crust");
pizza.crustObtainer.setBadSound("GP-NI");
pizza.crustObtainer.addItemAlias("^Hand\\s*Tossed$,^Tossed$", "HandTossed");
pizza.crustObtainer.addItemAlias("^Chicago\\s*style$,^Chicago$", "Pan");
pizza.crustObtainer.addItemAlias("^Deep,^Pan,^Baked", "Pan");
pizza.crustObtainer.addItemAlias("^New\\s*York,^Thin", "Thin");
/***************** Specialty Or Custom? *****************/
pizza.typeObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.typeObtainer.setGrammar("pizza_type", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.typeObtainer.setTopSound("GP-SpecialtyorCustom");
pizza.typeObtainer.setBadSound("GP-NI");
pizza.typeObtainer.addItemAlias("^Specialty$,^Specialty\\s*pizza$", "Specialty");
pizza.typeObtainer.addItemAlias("^pick", "Custom");
/***************** Which Specialty? *****************/
pizza.specialtyObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.specialtyObtainer.setGrammar("pizza_specialty", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.specialtyObtainer.setTopSound("GP-SpecialtyList");
pizza.specialtyObtainer.setBadSound("GP-NI");
pizza.specialtyObtainer.addItemAlias("^Hawaii,^Hawaiian", "Hawaiian");
pizza.specialtyObtainer.addItemAlias("^Meat", "MeatLovers");
pizza.specialtyObtainer.addItemAlias("Pickle,^World", "Pickle");
pizza.specialtyObtainer.addItemAlias("^Salvador,^Dolly,^Dali", "Dali");
pizza.specialtyObtainer.addItemAlias("^Veg", "Vegetarian");
/***************** What Toppings? *****************/
pizza.toppingsObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.toppingsObtainer.setGrammar("pizza_toppings", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.toppingsObtainer.setTopSound("GP-Toppings");
pizza.toppingsObtainer.setBadSound("GP-NI");
pizza.toppingsObtainer.addItemAlias("anchovie,anchovies", "anchovies");
pizza.toppingsObtainer.addItemAlias("artichoke,artichockes", "artichoke");
pizza.toppingsObtainer.addItemAlias("canadian\\s*bacon", "canadianbacon");
pizza.toppingsObtainer.addItemAlias("everything", "everything");
pizza.toppingsObtainer.addItemAlias("extra\\s*cheese", "extracheese");
pizza.toppingsObtainer.addItemAlias("garlic", "garlic");
pizza.toppingsObtainer.addItemAlias("goat\\s*cheese", "goatcheese");
pizza.toppingsObtainer.addItemAlias("bell\\s*pepper,bell\\s*peppers", "bellpepper");
pizza.toppingsObtainer.addItemAlias("mango", "mango");
pizza.toppingsObtainer.addItemAlias("mushroom,mushrooms", "mushroom");
pizza.toppingsObtainer.addItemAlias("olives", "olives");
pizza.toppingsObtainer.addItemAlias("onion,onions", "onions");
pizza.toppingsObtainer.addItemAlias("pepperoni", "pepperoni");
pizza.toppingsObtainer.addItemAlias("pickle,pickles", "pickle");
pizza.toppingsObtainer.addItemAlias("pineapple", "pineapple");
pizza.toppingsObtainer.addItemAlias("salami", "salami");
pizza.toppingsObtainer.addItemAlias("sausage", "sausage");
pizza.toppingsObtainer.addItemAlias("shrimp", "shrimp");
pizza.toppingsObtainer.addItemAlias("spinich", "spinich");
pizza.toppingsObtainer.addItemAlias("ham", "ham");
/***************** Change Delivery Or Size Or Crust, Add/Rem Toppings Or Start Over *****************/
pizza.arsoObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.arsoObtainer.setGrammar("pizza_arso", "", "result.interpretation.input", dft_min, 50, true);
pizza.arsoObtainer.setTopSound("GP-ARSO");
pizza.arsoObtainer.setBadSound("GP-NI");
pizza.arsoObtainer.addItemAlias("^delivery$", "delivery");
pizza.arsoObtainer.addItemAlias("^size$", "size");
pizza.arsoObtainer.addItemAlias("^crust$", "crust");
pizza.arsoObtainer.addItemAlias("^start\\s*over$", "startover");
pizza.arsoObtainer.addItemAlias("^add\\s*", "add_topping");
pizza.arsoObtainer.addItemAlias("^remove\\s*", "rem_topping");
/***************** Yes? No? Maybe So? *****************/
pizza.yesnoObtainer = new SpeechObtainer(asr, 1, 5000);
pizza.yesnoObtainer.setGrammar("pizza_yesno", "", "result.interpretation.input", dft_min, 20, true);
pizza.yesnoObtainer.setBadSound("GP-NI");
pizza.yesnoObtainer.addItemAlias("^yes,^correct", "yes");
pizza.yesnoObtainer.addItemAlias("^no", "no");
/***************** Get Some Information *****************/
pizza.get = function(params, confirm) {
for(;;) {
if (!session.ready()) {
return false;
}
var main_items = params.run();
if (confirm && params.needConfirm) {
pizza.yesnoObtainer.setTopSound("Confirm" + main_items[0]);
var items = pizza.yesnoObtainer.run();
if (items[0] == "yes") {
break;
}
} else {
break;
}
}
return main_items;
};
/***************** Is This Right? *****************/
pizza.check = function () {
if (!session.ready()) {
return false;
}
asr.streamFile("GP-You_ordered_a");
asr.streamFile(pizza.size);
asr.streamFile(pizza.crust);
if (pizza.type == "Specialty") {
asr.streamFile(pizza.specialty);
asr.streamFile("pizza");
} else {
asr.streamFile("pizza");
asr.streamFile("GP-With");
for (key in pizza.toppings) {
if (pizza.toppings[key] == "add") {
asr.streamFile(key);
}
}
}
pizza.yesnoObtainer.setTopSound("GP-WasThisRight");
items = pizza.yesnoObtainer.run();
return items[0] == "yes" ? true : false;
};
/***************** Let's Remove The Toppings *****************/
pizza.clearToppings = function() {
if (!session.ready()) {
return false;
}
if (pizza.toppings) {
delete pizza.toppings;
}
pizza.have_toppings = false;
pizza.toppings = new Array();
}
/***************** Clean Slate *****************/
pizza.init = function() {
if (!session.ready()) {
return false;
}
pizza.add_rem = "add";
pizza.order = pizza.size = pizza.crust = pizza.type = false;
pizza.toppingsObtainer.setTopSound("GP-Toppings");
pizza.specialty = false;
pizza.clearToppings();
pizza.said_greet = false;
}
/***************** Welcome! *****************/
pizza.greet = function () {
if (!session.ready()) {
return false;
}
if (!pizza.said_greet) {
asr.streamFile("GP-Greeting");
pizza.said_greet = true;
}
};
/***************** Collect Order Type *****************/
pizza.getOrder = function() {
if (!session.ready()) {
return false;
}
if (!pizza.order) {
var items = pizza.get(pizza.orderObtainer, true);
pizza.order = items[0];
}
};
/***************** Collect Size *****************/
pizza.getSize = function() {
if (!session.ready()) {
return false;
}
if (!pizza.size) {
var items = pizza.get(pizza.sizeObtainer, true);
pizza.size = items[0];
}
};
/***************** Collect Crust *****************/
pizza.getCrust = function() {
if (!session.ready()) {
return false;
}
if (!pizza.crust) {
var items = pizza.get(pizza.crustObtainer, true);
pizza.crust = items[0];
}
};
/***************** Collect Pizza Type *****************/
pizza.getType = function() {
if (!session.ready()) {
return false;
}
if (!pizza.type) {
var items = pizza.get(pizza.typeObtainer, true);
pizza.type = items[0];
}
};
/***************** Collect Toppings *****************/
pizza.getToppings = function() {
if (!session.ready()) {
return false;
}
if (pizza.type == "Specialty" && !pizza.specialty) {
var items = pizza.get(pizza.specialtyObtainer, true);
pizza.specialty = items[0];
pizza.have_toppings = true;
} else if (!pizza.have_toppings) {
toppings = pizza.get(pizza.toppingsObtainer, false);
for(x = 0; x < toppings.length; x++) {
pizza.toppings[toppings[x]] = pizza.add_rem;
}
pizza.have_toppings = true;
}
};
/***************** Modify Pizza If You Don't Like It *****************/
pizza.fix = function() {
if (!session.ready()) {
return false;
}
asr.streamFile("GP-Wanted-No");
arso = pizza.get(pizza.arsoObtainer, false);
for (x = 0; x < arso.length; x++) {
if (arso[x] == "delivery") {
pizza.order = false;
} else if (arso[x] == "size") {
pizza.size = false;
} else if (arso[x] == "crust") {
pizza.crust = false;
} else if (arso[x] == "startover") {
pizza.init();
} else {
if (pizza.type == "Specialty") {
asr.streamFile("GP-ChangeSpec");
pizza.type = false;
pizza.clearToppings();
} else {
pizza.have_toppings = false;
if (arso[x] == "add_topping") {
pizza.add_rem = "add";
pizza.toppingsObtainer.setTopSound("GP-Adding");
} else {
pizza.add_rem = "rem";
pizza.toppingsObtainer.setTopSound("GP-Remove");
}
}
}
}
};
/***************** Tie It All Together *****************/
pizza.run = function() {
pizza.init();
for(;;) {
if (!session.ready()) {
break;
}
pizza.greet();
pizza.getOrder();
pizza.getSize();
pizza.getCrust();
pizza.getType();
pizza.getToppings();
if (pizza.check()) {
asr.streamFile(pizza.order);
break;
} else {
pizza.fix();
}
}
};
/***************** Begin Program *****************/
session.answer();
pizza.run();
asr.stop();