Posts Tagged ‘Groovy’

Creating an internationalized Restaurants Finder application in minutes with Grails and Tropo

Wednesday, September 21st, 2011

Grails Logo In a previous blog post I already showed how we could pretty quickly create applications in Grails with the Tropo Grails Plugin and host them in Cloud Foundry with almost no effort. In this blog post I’m going to show a more ellaborated example. But, hey! In Tropo and Grails ellaborated examples don’t take more than 100 lines of code :)

One of the advantages of Tropo against its competitors is speech recognition and several internationalization features. Tropo understands 24 languages, so I thought that it would be pretty cool to create an application to find restaurants in a non-English speaking country as most of our blog posts are commonly focused on English. To implement my restaurants finder application I used the 11870 API service which is a Spanish web service that gives you the names, phone numbers and reviews of many services across any city in Spain (pretty cool).

So whats the idea around this restaurant finder? Basically imagine that you are on holidays with your wife in a city that you don’t know. And back in the hotel you made a reservation to a nice restaurant. Then you go through the day to visit the city and when it is time to go to the restaurant you realize that you don’t know where it is. Damn, you forgot the map! You don’t have any tourist service nearby, locals don’t know the restaurant location and you don’t have internet connection or an smartphone at hand. And of course your wife is starving! What do you do? Your marriage and peaceful holidays are at risk! Hopefully my restaurants finder could help you here :) Basically you dial a phone number, say the name of the city you are in, say the name of the restaurant and the application will tell you the phone number of the restaurant (it would be a one-liner change in the application to actually transfer your call to the restaurant’s phone).

But let’s look to some of the code. A first Grails action loads the name of all the cities with population bigger than 10.000. I’ve got a list from the Internet and just built a comma-separated list of cities. I use that list to create my choices statement that instructs Tropo to only accept one of those cities:


def index = {

    def citiesFile = applicationContext.getResource(
                            'classpath:cities.txt').file
    def citiesString = new String(IOUtils.toByteArray(
                            new FileInputStream(citiesFile)))
    def cities = citiesString.tokenize(',')

    def tropo = new TropoBuilder()
        tropo.tropo {
            say(value:"Bienvenido al servicio de información...", 
                  voice:"carmen")
            ask(name:'city',mode:"speech",
                         recognizer:"es-es", voice:"carmen") {
                say(value:"Diga el nombre de una ciudad")
                choices(value:citiesString)
            }
            on(event:'continue',next:'/tropo/restaurant')
        }
        tropo.render(response)	
}

That will prompt the user for the name of the city. Once the user says the name of a city a second Grails action will be triggered. In that action we call the 11870 API to fetch the list of available restaurants in that city. With that list I create another choices attribute that will instruct Tropo to only accept restaurants with a name in that list.

def restaurant = {

    def tropoRequest = request.JSON
    def place = tropoRequest.result.actions.value

    def map = restaurantMap(place)
    session["restaurants"] = map
    def restaurants = restaurantList(map)

    def tropo = new TropoBuilder()
    tropo.tropo {
        ask(name:'restaurante', mode:'speech', 
                      recognizer:'es-es', voice:'carmen') {
	    say(value:"Diganos el nombre de un restaurante en ${place}")
	    choices(value:restaurants)
	}
	on(event:'continue',next:'/tropo/info')
    }
    tropo.render(response)
}

In the code above, the method restaurantMap takes the name of the place and returns a map with all the restaurants in that place and their phone numbers. That map is stored in the HTTP session so later can be used to retrieve the phone number for the restaurant that the user has told. This is the actual code that invokes 11870 API and builds the map:

def restaurantMap(def place) {

    def query = "http://api.11870.com/api/v2/search?appToken=..."

    def feed = new XmlParser().parse(query)

    def restaurants = []
    def map=[:]
    feed.entry.each {
        restaurants << it.title.text()
        map.put(it.title.text(),it.'oos:telephone'.text())
    }
    map
}

Finally, once the user says the name of a restaurant, one last action will take the input and will use it to find the phone number of the restaurant:

def info = {

    def tropoRequest = request.JSON
    def restaurant = tropoRequest.result.actions.value

    def map = session["restaurants"]
    def phone = map.get(restaurant)

    def tropo = new TropoBuilder()
    tropo.tropo {
        say(value:"El teléfono de ${restaurant} es ${phone}...", 
              voice:"carmen")
        hangup()
    }
    tropo.render(response)		
}

That was pretty easy, wasn’t it? In very few lines of code we get a quite useful application. Provided you have an API to fetch restaurants from and a list of cities of a country then it would be fairly simple to add support for extra countries to this little example. There is many other things that could be done like handling nomatches and timeouts to make the application more reliable and user friendly, or dial the phone number of the restaurant and transfer the call. I hope you don’t mind if I leave these as exercises to the reader.

But wait, do you want to see the app in action? I’ve recorded a short video that goes through the source code and also shows the application working.

And that is it. I hope you liked it!

Deploying Tropo based applications to CloudFoundry with Grails

Tuesday, July 5th, 2011

Cloud Foundry is a Platform-as-a-Service platform that lets you deploy Spring, Grails, Rails and Node.js applications in the cloud. We’ve already shown in previous blog posts how you could easily create Tropo-powered Grails applications with Tropo’s Grails webapi plugin. However, in this blog post I’m going to show you an screencast in which you will learn how to deploy your applications to CloudFoundry.

As you will see in the screencast, deploying your Tropo applications with Grails to CloudFoundry is really easy. A few commands and you get your application not only in one, but in two cloud platforms!! So, you’ve got on one hand Tropo’s cloud platform which lets you run voice powered applications that can quickly scale and on the on the other hand you run all the business logic in CloudFoundry’s cloud platform. So you don’t have to worry about server and resources provisioning and you can take advantage of CloudFoundry’s infrastructure to scale.

So, here is the screencast:

Also, be sure to check these links to get extra information:

Hope you like it!!

Voice powered applications with Grails (Screencast)

Wednesday, April 20th, 2011

Grails Logo Hi. In a previous post we announced our new and shiny Grails Webapi library that allows all Grails developers to create voice and SMS powered applications very easily from their Grails applications.

If you go to the plugin’s web page at Grails.org you will find that there is already quite a few documentation out there. But I thought it would be quite useful to publish a screencast showing step by step how to create applications. This can be very interesting specially for developers that are not used to the Grails platform.

So here it is. It is a very short 15 minutes video in which I’ll show you how quick and easy you can create voice applications in Grails. I really hope you like it.

New Grails based WebApi implementation

Tuesday, February 8th, 2011

Grails LogoWe are happy to announce that today we just have released a brand new Grails based implementation of our WebApi. If you don’t know Grails, it is a Groovy based framework built in Java that lets you create very quickly applications that may run in any JVM powered application server like Tomcat, Oracle WebLogic or IBM WebSphere.

Grails is built on top of common Java application frameworks like Spring or Hibernate and therefore it lets you take advantage of all the already existing Java code but at the same time offering the flexibility and rapid development that platforms like Ruby on Rails are offering.

So, we are proud to expand our commitment to developers by supporting one of the coolest application frameworks out there. This is again an Open Source API so if you want to get started with it then you may head to the actual source code at Github. There is many unit tests built-in where you can find code samples. There is also a tutorial and a documentation page that you will find at the Grails plugin page. The plugin is already available in the official Grails repository page so you may use it in all your Grails applications just by running:

grails install-plugin tropo-webapi-grails

If you are using an IDE like SpringSource STS then you will happy to know that the plugin is also available from the Plugin Manager’s list of plugins so you can quickly import it in your grails based projects.

The next few days we will publishing up some examples that will help you to get started with this platform.

We hope you like it!

Tropo Now Speaks Asterisk Gateway Interface (AGI)

Friday, October 1st, 2010

The Asterisk community is a vibrant one, one that we actively support through our sponsorship and advocacy of Adhearsion. We have decided to take it a step further and created a Tropo Scripting application that turns Tropo into a giant Asterisk application platform in the cloud.   You can now run just about any Asterisk AGI application on Tropo.

Tropo AGItate was started on the Nerd Bird (good to have in-flight WiFi) from San Jose to Austin, on my way to LoneStar Ruby Conference. Jim Freeze – the organizer of LSRC – had recently been to AdhearsionConf in San Francisco; I wanted to be able to show something extra special during my talk there. On that one flight, I was able to get the basics working and show Tropo emitting AGI during my talk, just like that. (For those non-Asterisk folks out there, AGI is an API that lets external applications connect in to Asterisk and fully control it).

Since then, it’s been fun working on the application and expanding its capabilities. With Tropo AGItate, you could build your own interactive art display, a full blown cloud PBX like OpenVoice, or add Tropo capabilities to your own Asterisk server. The key features coming out today are:

  • Tropo can now speak AGI over TCP to any FastAGI server, including Adhearsion, PHPAGI, Asterisk-Java, etc.
  • A long list of Asterisk commands are supported, and of course all the Tropo ones.
  • While the script is written in Ruby, no Ruby knowledge is necessary to use it. Just point your Tropo application to the Ruby script on Github, upload a configuration file via FTP or WebDAV to your Tropo account, and you are ready.
  • Full support of Tropo Speech-Synthesis (TTS) and Speech-Recognition (ASR), but also for Asterisk sound files. Yes, tt-monkeys works!
  • Fail over to a SIP URI, in case your FastAGI server does not respond. This could be to another Tropo application, another Asterisk box, or anything that supports SIP.
  • You get all of the Tropo channels over AGI, including SMS, Instant Messaging and Twitter, all using the same application.
  • Support for custom SIP Headers in and out of Tropo.
  • And much more, with more to come…

Not only can you use AGI to write an entire cloud communications application, but you can also seamlessly integrate Tropo services into existing Asterisk systems using the interface you already know and love; after-all, its all SIP to us.

If you want to hear a Tropo AGItate ‘hello world’, give it a ring:

  • Phone/SMS: (408) 641-4410
  • Skype: +990009369991456829
  • SIP: sip:9991456829@sip.tropo.com
  • Jabber/XMPP: tropo_agitate@tropo.im

While this is great for all of the Asterisk developers out there, it also gave us the opportunity to showcase the power of the Tropo Scripting API. Tropo AGItate is 100% Tropo Scripting, no special libraries, no tricks, its all right there in the script. Tropo Scripting allows you to bend the Tropo cloud to your will; this is what we believe is truly innovative about our platform.

Stay tuned for more! We will be providing howtos, screencasts and more features soon.

Deutsch? French? Spanish? How To Use International Text-To-Speech (TTS) in Tropo Apps

Thursday, April 1st, 2010

Last week we announced that Tropo now included for free the ability to support Text-To-Speech in 8 languages. In this post, I want to show you how you can easily implement this in your Tropo app. First, though, if you want to hear the different voices, you can call these numbers now and try it out:

+1 (407) 374-9911
Skype: +990009369991430013
SIP: sip:9991430013@sip.tropo.com
iNum: +883510001805741

Here is what the JavaScript code looks like for that application (thanks to Voxeon Ron Blaisdell):

answer();
wait('500');

say("Hello world! This is a demonstration of the various voices & languages on Tropo.");

//English Female - Allison - en-us
say("1 2 3 4 5 this is Allison", { voice: 'allison' });

//Spanish Castillian Female - Carmen - es-es
say("1 2 3 4 5 this is Carmen", { voice: 'carmen' });

//French Female - Florence - fr-fr
say("1 2 3 4 5 this is Florence", { voice: 'florence' });

//English UK - Kate - en-uk
say("1 2 3 4 5 this is Kate", { voice: 'kate' });

//German Female - Katrin - de-de
say("1 2 3 4 5 this is Katrin", { voice: 'katrin' });

//Italian Female - Paola - it-it
say("1 2 3 4 5 this is Paola", { voice: 'paola' });

//Dutch Female - Saskia - nl-nl
say("1 2 3 4 5 this is Saskia", { voice: 'saskia' });

//American Spanish Female - Soledad - es-mx
say("1 2 3 4 5 this is Soledad", { voice: 'soledad' });

say("ta da");

hangup();

That’s literally all you need to do… add the { voice:'name' } parameter to the say function and there you go!

Now for those of you who don’t use JavaScript, the syntax is similar for the other languages.

Ruby:

say "J'aime les écureuils!", :voice => 'florence'
say "1 2 3 4 5 this in Florence", :voice => 'florence'

Python:

say ("Guten Tag!", {'voice':'katrin'})
say ("1 2 3 4 5 this is Katrin", {'voice':'katrin'})

Groovy:

say( "Hola, como estas?", [ 'voice':"carmen" ])
say( "1 2 3 4 5 this is Carmen", [ 'voice':"carmen" ])

PHP:

<?php say ("J'aime les écureuils!", array('voice'=>'florence')); ?>
<?php say ("1 2 3 4 5, this is Florence", array('voice'=>'florence')); ?>

That’s it! Simple and easy…

Today we support these languages and currently only female voices, but you can expect to see us releasing support for even more languages as well as male voices in the weeks and months ahead. And if you have a project that needs a specific voice, please do email our support team and let them know what you need.

Calling all web developers. Check out our cloud… earn some cash.

Tuesday, March 3rd, 2009

With Tropo, Voxeo makes it very easy for web developers to build voice and telephony applications using familiar languages – JavaScript, Groovy, PHP, Ruby and Python for starters. During the Tropo launch today at eComm, Voxeo announced that it would pay $100 cash for each selected sample app.   Here’s how it works:

  • Developers can join Tropo for free at www.tropo.com. When you sign up, you’ll receive a $200 usage credit for running applications in the future. For now, Tropo is in a free trial period.
  • Check out our documentation and samples by clicking the “documentation” tab or go directly to http://docs.tropo.com.
  • At our sole discretion we will pay $100 for any sample applications we like. All you need to do is write an app, submit it to us at www.tropo.com,and agree to publish it under the MIT license. If we like it we’ll PayPal you $100. 

Visit www.tropo.com to get started. Go from sign up to deployment in minutes. It’s that easy. 

Void where prohibited.

Get the Tropo sample applications – via git and Github

Tuesday, March 3rd, 2009

githublogo-1.jpgWould you like to easily get your hands on the Tropo sample applications? I mean, you certainly can download them from the Tropo documentation website, but we’ve also made them very easy to download from our account on Github. All you need do to is go to:

http://github.com/voxeo/tropo-samples/tree/master

If you just want to download the sample application files, simply click the “download” button and you’ll have a choice of a ZIP or tar file:

github-download.jpg

Alternatively, if you have the git version control system installed on your computer, you can simply clone our Github repository:

git clone git://github.com/voxeo/tropo-samples.git

That will pull a copy onto your local system. We will be updating the repository quite frequently over the next while, so from time to time you will want to do:

git pull origin master

in your “tropo-samples” directory. That will pull down the changes from our Github repo. If you are already a Github user and want to suggest changes for us, feel free to fork our repo and then request a pull. (And if that last sentence made no sense to you, that’s okay.)

If you would like to learn more about Git, you can watch my Emerging Tech Talk podcasts #24, Learning Git, Part 1: Intro to Version Control Systems and #25, Learning Git, Part 2: Getting Started with Git.

We hope this makes the source code more accessible to you all – please let us know what you think about making code available this way.


If you found this post interesting or helpful, please consider either subscribing via RSS or following us on Twitter.


Technorati Tags: , , , , , ,

Introducing Tropo… a new way to develop voice applications in languages you already know…

Tuesday, March 3rd, 2009

tropo.comlogo.jpgAt Voxeo, we love clouds but we don’t have our heads in them all the time. We realize not every developer wants to write applications in XML. There are lots of developers with lots of ideas, but they want to write their apps in the languages they’re already using. So we decided to do something about it – we created Tropo.

Tropo is an application platform that enables web developers to write communication applications in the languages they already use: Groovy, Ruby, PHP, Python and JavaScript. Tropo is in the cloud, so we manage the headaches of dealing with infrastructure and keeping applications up and running at enterprise-grade. Tropo is simple to deploy, requires no contracts and no up-front setup costs. With Tropo developers can build and deploy voice and telephony applications, or add voice to existing applications.

Previously developers had to write voice applications in VoiceXML. This has left out developers who either did not want to learn VoiceXML, wanted the flexibility of working in other development languages or have been working in VoiceXML for 10 years and are ready for a change.

Already, developers are having fun with the platform… take a look at the sample applications and you’ll see voice mashups that read you various news feeds (or your Google reader)… an app that gives you the ETA of trains on the BART system… location mashups using Yahoo!Local… weather examples… even a Monty Python quote server. (UPDATE: March 2, 2011 – A better place to start today is our Quickstart guide.)

With many applications still to be written and many existing applications that can be enhanced by adding voice, Tropo is unleashing the creativity of the web developer community on the communications world. We can’t wait to see what happens. Please visit www.tropo.com for more information and to sign up to get started today!


If you found this post interesting or helpful, please consider either subscribing via RSS or following us on Twitter.