Tropo is part of CiscoLearn More

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. A complete list appears below.

Language Recognizer
Afrikaans af-za
Arabic ar-ww
Arabic (Jordanian) ar-jo
Assamese as-in
Basque eu-es
Bengali bn-bd
Bengali (Indian) bn-in
Bhojpuri bh-in
Bulgarian bg-bg
Cantonese cn-hk
Catalan ca-es
Czech cs-cz
Danish da-dk
Dutch nl-nl
Dutch (Belgian) nl-be
English (Australian) en-au
English (Indian) en-in
English (Singaporean) en-sg
English (South African) en-za
English (UK) en-gb
English (US) en-us (Default)
Finnish fi-fi
French fr-fr
French (Belgian) fr-be
French (Canadian) fr-ca
Galician gl-es
German de-de
German (Austrian) de-at
German (Swiss) de-ch
Greek el-gr
Gujarati gu-in
Hebrew he-il
Hindi hi-in
Hungarian hu-hu
Icelandic is-is
Indonesian id-id
Italian it-it
Japanese ja-jp
Kannada kn-in
Korean ko-kr
Malay ms-my
Malayalam ml-in
Mandarin zh-cn
Mandarin (Taiwanese) zh-tw
Marathi mr-in
Nepali ne-np
Norwegian no-no
Oriya or-in
Polish pl-pl
Portuguese pt-pt
Portuguese (Brazilian) pt-br
Punjabi pa-in
Romanian ro-ro
Russian ru-ru
Serbian sr-rs
Slovak sk-sk
Slovenian sl-si
Spanish es-es
Spanish (Argentinian) es-ar
Spanish (Colombian) es-co
Spanish (US & Mexican) es-us
Swedish sv-se
Tamil ta-in
Telugu te-in
Thai th-th
Turkish tr-tr
Ukrainian uk-ua
Urdu (Indian) ur-in
Urdu (Pakistani) ur-pk
Valencian va-es
Vietnamese vi-vn
Welsh cy-gb

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 Argentinian 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 => "Angelica",
        :choices => {:value => "[4 DIGITS]"},
        :recognizer => "es-ar"        
  
  t.on :event => 'continue', :next => '/continue.json'
  
  t.response
  
end

post '/continue.json' do
  
  t = Tropo::Generator.new
  
  t.say "Gracias", :voice => "Angelica"
  
  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-ar", say, 60, "Angelica");
	
    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, "Angelica");
		
    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-ar");
	
	//PHP as a whole may have difficulty processing accented characters right now; omission of the accents may cause pronunciation to be off
	
	$tropo->setVoice('Angelica');
	
	$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" => "Angelica"));
	
	$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-ar", voice = "Angelica")
	
	t.on(event = "continue", next ="/continue")

	return t.RenderJson()
	
@post("/continue")
def index(request):
	
	t = Tropo()
	
	t.say("Gracias", voice = "Angelica")
	
	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? All that's explained in the next chapter.