Tropo WebAPI Development Guide Home  |  Frameset Home

  Speaking Multiple Languages  |  TOC  |  International Dialing & SMS  

Multilingual Speech Recognition


On the other side of the multinational coin is recognizing input from a different language. This is controlled by the recognizer parameter. Most of the languages supported by voice are supported by recognizer, we'll specify below if we don't yet have a recognizer for a language:


While we have several options, Tropo can only listen for one language at a time, so it’s important to tell it which language to expect. Here's an example using both voice and recognizer with Mexican Spanish; we included the same example in English for comparison:

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

post '/index.json' do
  
  t = Tropo::Generator.new
  
  t.ask :name => 'digits', 
        :timeout => 60, 
        :say => {:value => "What's your four digit pin?"},
        :choices => {:value => "[4 DIGITS]"}     
  
  t.on :event => 'continue', :next => '/spanish.json'
  
  t.response
  
end

post '/spanish.json' do
  
  t = Tropo::Generator.new
  
  t.ask :name => 'digits', 
        :timeout => 60, 
        :say => {:value => "¿Cuál es su número de identificación?"},
        :voice => "soledad",
        :choices => {:value => "[4 DIGITS]"},
        :recognizer => "es-mx"        
  
  t.on :event => 'continue', :next => '/continue.json'
  
  t.response
  
end

post '/continue.json' do
  
  t = Tropo::Generator.new
  
  t.say "Gracias", :voice => "soledad"
  
  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 four digit pin?");

    // (value, mode, terminator)
    var choices = new Choices("[4 DIGITS]");

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

app.post('/spanish', function(req, res){
	
    var tropo = new TropoWebAPI();
    
    var say = new Say("¿Cuál es su número de identificación?");

    var choices = new Choices("[4 DIGITS]");

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

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

    // (value, as, name, required, voice)
    tropo.say("Gracias.", null, null, null, "soledad");
		
    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" => "[4 DIGITS]", "name" => "digits", "timeout" => 60);
 
	$tropo->ask("What's your four digit pin?", $options);

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

	$tropo->RenderJson();
}

dispatch_post('/spanish', 'app_spanish');
function app_spanish() {

	$tropo = new Tropo();
	
	$options = array("choices" => "[4 DIGITS]", "name" => "digits", "timeout" => 60, "recognizer" => "es-mx");
	
	//PHP as a whole may have difficulty processing accented characters right now; omission of the accents may cause pronunciation to be off
	
	$tropo->setVoice('soledad');
	
	$tropo->ask("Cual es su numero de identificacion?", $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("Gracias.", array("voice" => "soledad"));
	
	$tropo->say("You said " . $answer);
	
	$tropo->RenderJson();

}

run();
?>
# -*- coding: utf-8 -*-
# The above is a special comment that sets utf-8 encoding in order to read the Spanish characters

from itty import *
from tropo import Tropo

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

	t = Tropo()
	
	t.ask(choices = "[4 DIGITS]", timeout=60, name="digit", say = "What's your four digit pin?")
	
	t.on(event = "continue", next ="/spanish")

	return t.RenderJson()
	
@post('/spanish')
def index(request):

	t = Tropo()
	
	t.ask(choices = "[4 DIGITS]", timeout=60, name="digit", say = "¿Cuál es su número de identificación?", recognizer = "es-mx", voice = "soledad")
	
	t.on(event = "continue", next ="/continue")

	return t.RenderJson()
	
@post("/continue")
def index(request):
	
	t = Tropo()
	
	t.say("Gracias", voice = "soledad")
	
	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:

Need to know the rules and requirements for call internationally and for sending international text messages?

Next Step: International Dialing & SMS


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

login
  Speaking Multiple Languages  |  TOC  |  International Dialing & SMS  

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