Tropo WebAPI Development Guide Home  |  Frameset Home

  Advanced Speech Control  |  TOC  |  Manipulating Say with SSML  

Advanced Grammars


While Tropo’s Simple Grammar is pretty awesome, it’s not really suited for extremely large data sets.

For example, let’s say you were writing a travel app and wanted to allow your users to speak their destination city or airport. There are hundreds, if not thousands of airports, and many more ways to actually say them. They could say “JFK”, “John F. Kennedy”, “NYC”, “New York International”, etc. These types of complex grammars are best suited for the Speech Recognition Grammar Specification (SRGS). The SRGS is a W3C standard way of controlling speech recognition engines. SRGS can take a variety of forms, with the most popular being Grammar XML (or GRXML for short).

To use GRXML from your Tropo Scripting application, simply provide the URL to an external file:

require 'tropo-webapi-ruby'
require 'sinatra'

post '/index.json' do
  
  t = Tropo::Generator.new
  
  t.ask :name => 'destinations', 
        :timeout => 60, 
        :say => {:value => "What's your destination?"},
        :choices => {:value => "http://myserver.com/destinations.grxml"}
  
  t.on :event => 'continue', :next => '/continue.json'
  
  t.response
  
end

post '/continue.json' do
  
  v = Tropo::Generator.parse request.env["rack.input"].read
  
  t = Tropo::Generator.new
  
  answer = v[:result][:actions][:destinations][:value]
  
  t.say(:value => "You said " + answer)
  
  t.response
  
end
var http = require('http');
var express = require('express');
var app = express.createServer();
var tropo_webapi = require('tropo-webapi');

// Required to process the HTTP body.
// req.body has the Object while req.rawBody has the JSON string.

app.configure(function(){
	app.use(express.bodyParser());
});

app.post('/', function(req, res){
	
    var tropo = new TropoWebAPI();
    
    var say = new Say("What's your destination?");
    var choices = new Choices("http://myserver.com/destinations.grxml");

    // (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
	
    tropo.ask(choices, null, null, null, "destinations", null, null, say, 60, null);
	
    tropo.on("continue", null, "/continue", true);
	
    res.send(TropoJSON(tropo));
	
});

app.post('/continue', function(req, res){
	
    var tropo = new TropoWebAPI();

    var answer = req.body['result']['actions']['value'];
	
    tropo.say("You said " + answer);
		
    res.send(TropoJSON(tropo));

});

app.listen(8000);
console.log('Server running on port :8000');
<?php

require 'tropo.class.php';
require 'lib/limonade.php';

dispatch_post('/start', 'app_start');
function app_start() {

	$tropo = new Tropo();

	$options = array("choices" => "http://myserver.com/destinations.grxml", "name" => "destination", "timeout" => 60);
 
	$tropo->ask("What's your destination?", $options);

	$tropo->on(array("event" => "continue", "next" => "hello_world.php?uri=continue"));

	$tropo->RenderJson();

}

dispatch_post('/continue', 'app_continue');
function app_continue() {

	$tropo = new Tropo();
	@$result = new Result();
	
	$answer = $result->getValue();
	
	$tropo->say("You said " . $answer);
	
	$tropo->RenderJson();

}

run();

?>
from itty import *
from tropo import Tropo, Result

@post('/index.json')
def index(request):

	t = Tropo()

	t.ask(choices = "http://myserver.com/destinations.grxml", timeout=60, name="destinations", say = "What's your destination?")	
	
	t.on(event = "continue", next ="/continue")
	
	return t.RenderJson()
	
@post("/continue")
def index(request):
	
	r = Result(request.body)
	t = Tropo()
	
	answer = r.getValue()
	
	t.say("You said " + answer)
	
	return t.RenderJson()
	
run_itty(server='wsgiref', host='0.0.0.0', port=8888)

Note that if you use PHP, the above example includes the Limonade framework, so you would need to define the end of the start URL in Tropo to include the resource name, like http://www.example.com/test.php?uri=start:

The Tropo docs can't cover the entire scope of all the potential advanced grammar functionality out there, as there's quite a bit, so we recommend reviewing the following resource for more information:

http://www.w3.org/TR/speech-grammar/

Next Step: Manipulating Say with SSML


  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login
  Advanced Speech Control  |  TOC  |  Manipulating Say with SSML  

© 2012 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site