include("js_modules/SpeechTools.jm");
var dft_min = 100;
var dft_confirm = 600;
var asr = new SpeechDetect(session, "speechlib", "127.0.0.1");
asr.AutoUnload = true;
asr.debug = 1;
asr.setTTS("cepstral", "david");
numberObtainer = new SpeechObtainer(asr, 1, 5000);
numberObtainer.setGrammar("number", "ABNFPhone.gram", "result", dft_min, dft_confirm, true);
numberObtainer.setTopSound("Say a phone number please");
numberObtainer.setBadSound("I didn't understand you, please try again");
numberObtainer.addRegEx("x{0,1}(\\d*)");
yesnoObtainer = new SpeechObtainer(asr, 1, 5000);
yesnoObtainer.setGrammar("yesno", "pizza/yesno.gram", "result", 500, 250, true);
yesnoObtainer.setBadSound("I didn't understand you, please try again");
yesnoObtainer.addItem("yes,no");
session.answer();
session.execute("sleep", "1000");
function get_yn(ob, text) {
while(session.ready()) {
ob.setTopSound(text);
var yn = ob.run();
if (ob.needConfirm) {
yesnoObtainer.setTopSound("I couldn't hear you, " + text);
continue;
}
return yn;
}
}
while(session.ready()) {
items = numberObtainer.run();
var yn;
yn = get_yn(yesnoObtainer, items[0] + ", should i dial that number?");
if (yn[0] == "yes") {
asr.speak("ok, stand by");
session.execute("transfer", items[1]);
} else {
asr.speak("ok, I will not dial that number");
}
}