Archive for the ‘SourceCode’ Category

Speech Enabling Open311

Tuesday, August 9th, 2011

Since SpeechTEK is this week, I thought it was a good time to update a post I did several months ago on using speech recognition to capture a street address.

There are lots of reasons why you might want to collect a caller’s address over the phone.

In open government circles, there has been a lot of interest lately in using automated IVR systems to help gather non-emergency service requests for municipalities. This makes a lot of sense – many municipalities enable non-emergency service reporting through the use of a designated abbreviated dialing number – 3-1-1 – so there is a long history of reporting these issues using the telephone.

Address collection is used quite often in IVR systems, but typically relies on expensive proprietary or “black box” components that might not be suitable for all use cases. This is particularly true for municipalities and local governments who are under financial pressure and who need to do more with less.

In this post, I’ll show how to build a sophisticated address collection system that can be used for almost any city or town, large or small. All of the code for this example is on GitHub (and under active development) and many of the components I will use are free or open source.

Here is a screen cast demonstrating the system running on the Tropo platform.

How it works

The application demonstrated here relies on three primary ingredients:

  • A data source with all of the street names in a city (in this case, I used the San Francisco Basemap Street Centerlines file from DataSF.org)
  • A database that can store the data on street names and zip codes, and which can be queried to render a speech grammar. In this instance, I use CouchDB.
  • A telephony platform that supports speech recognition – in this case, Tropo.

The application is structured to ask the caller for a zip code – obtaining a zip code will help us constrain the number of choices in our speech grammar and help ensure a better recognition.

The application then builds an SRGS grammar in XML format using CouchDB’s view and list functions. This grammar contains a list of all of the streets in a particular zip code and allows a caller to add additional details, like house number and street direction (if applicable).

In the event that a successful match can’t be made (this is inevitable in some small percentage of calls), we ask the caller to say their full address and make a recording.

This recording can be transcribed after the call has ended to gather the caller’s address – this might be a manual step, or it could be automated using functionality provided by Tropo.

Building for the cloud

The example shown here is built to run on the Tropo cloud communication platform, and uses a cloud-based instance of CouchDB.

This same basic approach could be replicated with a more conventional architecture, and could also use a standard relational database (as I did in my previous post on this subject).

But using cloud-based components has a number of advantages that might be attractive to smaller governments that want to employ this approach, or even larger governments that face fiscal constraints or challenges.

Using a cloud-based platform like Tropo makes deployment and scaling easy. It also means that you get access to the latest and greatest technology to support the open specification for speech recognition grammars. The folks that work at Voxeo (the company behind Tropo) help write these standards.

Using CouchDB has a number of advantages too. Populating a CouchDB instance with street data is extremely easy with tools like shp2geocouch by Max Ogden. In addition, it’s actually pretty straightforward to write view and list functions to generate a speech grammar – after all it’s just JavaScript.

If you found this post and screen cast useful, head on over to the GitHub repo for this solution and sign on as a watcher – I’m going to be actively developing this with the goal of deploying it for a municipality in the near future.

Stay tuned!

2 Lines of Code To Enable Calling 1 Phone Number And Ringing Multiple Phone Numbers (like Google Voice)

Monday, July 18th, 2011
Phone Home

Have you ever wanted to give out a single phone number that in turn dials multiple phone numbers? And whichever phone answers first speaks to the caller?

I had just this case recently when I wanted a phone number I could start putting on Voxeo news releases that would ring my multiple phones and also could conceivably also ring someone else’s phone number. The number is also not tied to a single person so that if someone else started handling press inquiries, the number could just be redirected to the other person’s phone number(s). (In the programming world, we would call this an “abstraction layer”.)

Here’s literally all you have to do in Tropo Scripting (outside of having a free developer account at Tropo.com)… it’s really just one line of code using the transfer command and provide an array of phone numbers to call. Here’s how it looks in python, my language of choice:

say("Please wait while we connect your call.")
transfer(["+14079678424","+16037566424","+14074555859"], {
    "playvalue":"http://www.phono.com/audio/holdmusic.mp3"})

All I had to do was:

  • login to Tropo.com
  • create a new application
  • create a new hosted file
  • copy / paste this code in and change the phone numbers
  • save the hosted file
  • save the application
  • add a new phone number to the application
  • wait a minute or two and start calling!

That’s literally it.

If python isn’t your thing, you scroll down the documentation page for the transfer command and see examples in JavaScript, Ruby, Groovy and PHP. They are all basically the same simple solution.

Now, what’s cool about Tropo is that because Tropo can work with IP communications / unified communications systems, I can tell the transfer command to also use a SIP address as one of the endpoints to call:

say("Please wait while we connect your call.")
transfer(["+14079678424","+16037566424","sip:dyork@corpsip.voxeo.com"], {
    "playvalue":"http://www.phono.com/audio/holdmusic.mp3"})

This simple version works really well… but I can make a few other changes to it. Here’s a version that:

  • speaks with a different text-to-speech voice
  • provides an option for the caller to cancel the call (although they could of course just hang up)
  • covers the error condition of no one answering any of the phone numbers

The code is:

say("Please wait while we connect your call. Press star to cancel the call.",
    {"voice":"simon"})
transfer(["+14079678424","+16037566424","sip:dyork@corpsip.voxeo.com"], {
    "playvalue":"http://www.phono.com/audio/holdmusic.mp3", 
    "terminator": "*",
    "onTimeout": lambda event : say("I'm sorry, but nobody answered.")})

That’s it! Short and simple… and able to ring all the phones you want.

What’s also great is that I can add more phone numbers to this application on the inbound side so that I could in fact have a phone number in the UK or 40 other countries that call into this application… and then are transferred out to whichever phone I want to take the call on.

P.S. Sure, you can do this with services like Google Voice, but there are limits with some of those services. For instance, a Google Voice number is tied to your Google Account, so you may need to create another Google Account if you want a new Google Voice number. And while yes, you can add another number to your GV account for $20, it’s still tied to that one account. With Tropo, you can make as many of these type of applications as you want…

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!!

Telephony Black Magic with Tropo, Node.js and Redis

Tuesday, June 28th, 2011

In a previous post and screencast on this blog, I demonstrated an example application that highlights some of the more unique features of Tropo to support realtime applications.

Tropo’s unique ability to write to, and read from persistent socket connections during the execution of a call sets it apart from other platforms, and creates opportunities to do things that other platforms can only dream of.

In this screencast, I build upon and extend my earlier example using Redis, Node.js and jQuery to allow a user to inject text into a running Tropo session and have it read out over the phone using Text-to-Speech.

Here is an overview of the technical components of this example application (opens in new window).

What I get really excited about in this demo application – the code for which can be found on GitHub – is the ability to send TTS output to multiple subscribers. Redis’ PubSub functionality will send a message published on a channel to all subscribers, so if you have multiple people called in to your app, every one of them will get the message sent from a single publisher.

How cool is that?!?

if you’re building a realtime application that requires voice, SMS or IM functionality, look no further than the Tropo platform.

With Tropo and powerful tools like Redis and Node.js, you can make telephony black magic.

Have fun!

Realtime Conferencing Dashboard with Tropo and Chloe

Wednesday, June 22nd, 2011

In yet another installment on this blog demonstrating how to build realtime applications with Tropo, I walk you through the process of creating a conferencing dashboard with Tropo and the Chloe realtime web server from Mashion.

Chloe is a great open source project that works extremely well with the Tropo platform. With Chloe and some modest Tropo and jQuery code, you can build a sophisticated and powerful conferencing dashboard.

You can get executables for Chloe by visting the Chloe GitHub repo, and you may also download the source and build on your local machine as well.

The sample code that I demonstrate in this screencast is also available on GitHub.

This example demonstrates yet again how ideal Tropo is for building powerful realtime communication applications. Chloe is easy to work with, powerful and open source, making it an excellent compliment to the apps you can build with the Tropo platform.

Check out the Chloe project and stay tuned to this blog for more posts in the future about building realtime apps with Tropo.

ASR-as-a-Service

Saturday, May 21st, 2011

Automated Speech Recognition (ASR) as-a-Service can be powered via Tropo and SIP using this simple open source code provided below.  This service is perfect for adding speech recognition to your existing Asterisk, FreeSwitch, YATE, or enterprise app from the stone ages.

Here’s how it works!

You can transfer a phone call via SIP from a platform that doesn’t support ASR to Tropo along with the following SIP headers: prompt, choices, and returnaddress (SIP address). Tropo automatically answers the call and prompts the user the the text-to-speech (TTS) prompt passed. It automatically loads the ASR grammar with the choices passed. Upon successfully processing the speech recognition, Tropo transfers the call and the recognized result back to the return SIP adrress along with an x-voxeo-result SIP header containing your keyword spoken by the user.

Here’s the Tropo code using our hosted Scripting API:

This code is written in Ruby using our Tropo Scripting API.  You can use $currentCall.getHeader to get the SIP headers passed to your Tropo application and you can send headers to other SIP applications using the Tropo transfer method.  The speech recognition magic happens in the Ask method.

recoresult = ask $currentCall.getHeader("x-sbc-prompt"), {
   :choices => $currentCall.getHeader("x-sbc-choices")}

transfer $currentCall.getHeader("x-sbc-returnaddress"), {
    :headers => {'x-voxeo-result' => recoresult.value}
    }

Here’s how we tested it.

We used Phono, our browser-based webphone, to call Tropo and pass the prompt, choices, and returnaddress parameters.

phono.phone.dial("sip:9996106030@sip.tropo.com", {
  	headers: [
	{
		name:"returnaddress",
		value: "sip:9996106032@sip.tropo.com" // you could use returnaddress var to send the results back to Phono's SIP address
	},
	{
		name:"prompt",
		value: "What is your favorite color?"
	},
	{
		name:"choices",
		value: "blue,green,red,yellow"
	}
	],

Just to prove that yet another SIP application could receive the speech recognition results, we created another Tropo application in Ruby using the Scripting API to simple say the results.

say "You said " + $currentCall.getHeader("x-voxeo-result")

This second test application would typically be omitted for a real application since the returnaddress would most likely be the originating SIP address of your switch to return to your original callflow.  It’s cool that you could transfer to yet another application for additional processing!

What’s Next?

You can clone or fork this open source project on Github and use it today for as little as $.03 per minute for the Tropo call.  Let us know if you would prefer for us to build this service out for commercial use.

 

Extending GoogeVoice with Tropo

Friday, May 13th, 2011

We are always excited to see developers using Tropo to extend GoogleVoice functionality and features by adding things like SIP and Call Forwarding and Call-In enhancements.  Terry Swanson (@FunnyBoy243) is one of these cool developers who wrote 2 of these extensions and opensourced them for others to share and contribute:

His Call Forwarding Extender Tropo Script includes the following features that extend/add to the current Google Voice feature-set:

  1. Easy forwarding to SIP Numbers (especially compared to IPKall)
  2. Outbound call recoding
  3. Allows forwarding to numbers that cannot be verified through Google Voice (such as numbers with extensions).  You can append “postd=DIGITSp” and/or “pause=WAITTIMEms” in the CALL_DEST variable to allow the script to forward to your extension. For example, “+14155551212;postd=ppppp1234pp56″ would dial (415) 555-1212 wait 5 seconds (1 second for each p) dial 1 2 3 4, wait 2 seconds then dial 5 6. Look enter the Parameters section of the Tropo API for more information.

You can have this script call multiple SIP/Telephone numbers at the same time by using an array for the CALL_DEST variable. All numbers will ring and the first to answer the call will take the call.

Example: $CALL_DEST = array(“sip:2233486745@sip2sip.info”, “sip:2233486712@sip2sip.info”);

For step by step instructions, check out Terry’s original post here.

His Google Voice Call In Extender Tropo Script includes the following features that extend/add to the current Google Voice feature-set:

  1. SIP Address for your Google Voice number.
  2. Skype number for your Google Voice number.
  3. Phone Number Aliases for your Google Voice number – You can have multiple phone numbers from different areas forward to the same Google Voice number so they wont have to pay long distance fees to call your Google Voice number.

Here are some additional tips and tricks with this extension:

  1. You can have this script call multiple Google Voice numbers at the same time by using an array for the GV_NUM variable. All numbers will ring and the first to answer the call will take the call. Example: $GV_NUM = array(“5103364032″, “5103364002″);
  2. You can add International Phone numbers to allow people from other countries to call your Google Voice number without paying International rates.
  3. You can use the Skype number to make free telephone calls using Google Voice.

For step by step instructions, check out Terry’s original post here.

Hats off to you, Terry!  Keep up the good work!

Routing GoogleVoice to Tropo and OpenVoice

Wednesday, April 27th, 2011

Do you have a GoogleVoice phone number?  Would you like to route it to your Tropo application?  

You can permanently port your GoogleVoice phone number to your Tropo application by submitting a ticket to our Provisioning team via the GetHelp link in the Tropo portal but I would like to show you how to temporarily route your GoogleVoice number to Tropo.

In this screencast, I use a few unnecessary (but fun) geeky apps like Skype (to place PSTN calls) and Blink (for receiving SIP calls).  I also route my GoogleVoice number to @Zlu’s OpenVoice application.  OpenVoice is an open source GoogleVoice clone that runs on Tropo and also integrates with our Phono webphone!  It’s built using Ruby on Rails and its source code is available on Github at http://github.com/openvoice.  (OpenVoice also has an Android app available so check it out!)

Empire Avenue Stock Quotes by SMS

Tuesday, April 26th, 2011

Have you heard of EmpireAvenue? According to their website, “Empire Avenue is the Social Media Exchange, where you can buy and sell shares in any social media profile, meet new people, unlock Achievement badges, and earn boatloads of virtual cash by being active and social online! Buy shares in your friends, your followers, people with similar interests, brands you love, celebrities – anyone! All using a virtual currency and all for free!”

Cas Hoefman, a long time telephony geek and friend of Tropo, built an SMS hook into their API!

If you want to see a working sample just send a text message with DISRUPTIVE to (818) 900-2731 to get back our latest stock price or replace DISRUPTIVE with your own Empire Avenue Ticker Symbol to get your own latest stock price!  You can also scan the QR code on the left and we’ll do it for you.

Using Tropo, you can add SMS to virtually API to further extend services to meet your needs.  For more details on Cas’ application including the source code, please visit his blog post!

Deploying Tropo Apps with Orchestra.io

Friday, April 22nd, 2011

On a visit to Nashville, Tennessee, for the PHP Community Conference (Tropo is one of the sponsors) I got to hear a talk from Helgi Þorbjörnsson on front-end caching techniques.

During his talk Helgi mentioned a new Git-based deployment service for PHP applications – Orchestra.

Orchestra is very similar to other Git-based deployment service for different langages – Heroku for Ruby, and Nodester for Node.js – but it’s meant to support deployment of PHP-based applications.

If you’re like me, and you missed the chance to take part in the Codeita beta, you’re anxious to give a Git-based deployment service for PHP a try. When I checked out Orchestra, it looked incredibly easy to use, and a snap to get started with.

It’s also an excellent match for Tropo applications written with our PHP class library for WebAPI.

How easy is it to use Orchestra to deploy a PHP-based Tropo app?

I was able to write, deploy and test an app before Helgi had finished his presentation at the PHP Community Conference (about 20 minutes total with conference-grade wifi). I was even able to hear the end of Helgi’s talk.

Here is how I did it.

Building a Tropo WebAPI App

I built a very simply Tropo application using the PHP class library WebAPI.

My sample application is meant to answer an incoming call, ask the caller what their favorite programming language is (along with some choices), and then say something snarky based on their response.

Building a speech recognition app like this with Tropo is very easy. I also made use of the awesome Limonade PHP framework for my app.

All of the code for this app is made available on GitHub, which is also part of the process for deploying apps to Orchestra.

Setting up and Deploying to Orchestra

Orchestra settings

Go to the Orchestra site and create a new account. Take a spin through the knowledge base if you want more specifics on how everything works – you have two deployment options, a free deployment or an elastic deployment.

For the purposes of this post, I’ll use a free deployment.

You deploy your application to Orchestra by connecting a repo on GitHub with your Orchestra account – Simply set up a GitHub repo for your app, just as you would for a normal project. You’ll then use information about this repo to set things up in Orchestra.

When you tell Orchestra where your GitHub repo is, it will deploy your app and give you a public URL that you can use to access it.

Setting up a Tropo Application

Now that our application is deployed to Orchestra, we need to set up a phone number to use it in Tropo. Like all of the steps described above, this one is simple.

Log into your Tropo account and create a new application – when prompted select WebAPI. The URL that powers your application is the public URL provided by Orchestra when you deploy your application.

Since we’re using Limonade, we need to add a query string parameter for our starting route.

In our application, our starting route looks like this:

dispatch_post('start', 'tropoStart');
function tropoStart() {
 ...
}

So to access this route from Tropo, we would set up our app URL like this.


http://my-app-name.orchestra.io/index.php?uri=start

When you do this, you’ll be able to call the application and hear it work. Here is a quick screencast demonstrating how the app works.

One of the things I really like about Orchestra is that it uses a standard GitHub repo for deployment. Similar services for other languages often require you to set up a special stand alone repo for deployment, and for me this just always feels like an extra step I have to go through to deploy my app.

I love that I can push changes to GitHub and they are deployed by Orchestra. Quick and easy!

Orchestra has a number of add ons planned (i.e., for CouchDB and MongoDB) so it’s only going to get more awesome.

So if you want a fast, easy way to build powerful multi-channel communication apps in PHP, Tropo and Orchestra make a powerful combination.