Posting Tropo Transcriptions to Google AppEngine

Now that Tropo offers transcriptions, I would like to provide another example of using cloud services to manage your transcription results. In this case we will use Google AppEngine’s (GAE) Java implementation by deploying with JRuby, leveraging a similar architecture to what we use on Tropo for hosting our scripting languages.

I have created another Sinatra application (tropo-transcriptions) that provides an HTTP REST API for receiving POSTs of transcriptions from the Tropo cloud. The same application then allows you to get those results, either by fetching all or a single transcription. The app takes advantage of Google’s BigTable on GAE, storing all of the transcriptions right in the cloud in a schemaless data store. Using the unofficial Ruby/JRuby Google library, appengine-jruby, I have already created everything you need to simply download and deploy the application. This means that it already has JRuby and all of the Ruby gems baked into the app, so you get running with minimal fuss.

The first step is to install the google-appengine gem and download the tropo-transcriptions source code (you may do a Git clone or download from Github):

TropoTranscriptionInstall

After having signed up for Google AppEngine and creating an application, then you need to make one configuration change to your application you just downloaded. Editing the file tropo-transcriptions/config.ru, make the following change to line 3:

:application => 'tropo-transcriptions'

becomes:

:application => 'your-app-name'

Then the last step is to deploy your application to Google AppEngine. To do this simply cd into your application’s directory and enter:

  appcfg.rb update .

You will be prompted for your GAE username and password and you should then see:

TropoTranscriptionDeployGAE

Thats it, you are now up and running. There are now three resources available on your new HTTP web services app:

1. POST to receive transcriptions

  http://your-app-name.appspot.com/receive_transcription

2. GET to fetch all transcriptions

  http://your-app-name.appspot.com/transcriptions

3. GET to fetch a single transcription based on GUID

  http://your-app-name.appspot.com/transcription?guid=5fad8750-7316-012c-00bd-0400580fde23

Now, you may start using your new server to store your transcription results. Simply use the first URL in the transcriptionOutURI portion of your recording request of your Tropo script:

  answer
  say 'Welcome to ruby recording test'

  event = record('Say something after the beep.',
                           { :repeat              => 0,
                             :bargein             => true,
                             :beep                => true,
                             :silenceTimeout      => 2,
                             :maxTime             => 30,
                             :timeout             => 4,
                             :recordURI           => 'http://tropo.to-a-domain.com/post_audio?filename=file123456.wav',
                             :transcriptionOutURI => 'http://your-app-name.appspot.com/receive_transcription',
                             :transcriptionID     => '123456' })

  log 'Recorded file: ' + event.recordURI
  say 'Thanks for your testing ruby on Tropo platform'
  hangup

Make a few calls and you should see this when you put the second URL above in your browser:

TranscriptionResult

There is more to come…

An App for Posting Tropo Audio Files to Amazon S3 via Heroku

At Voxeo Labs we clearly have an affinity for clouds. Now that we provide the ability to easily push recorded audio files out of the Tropo cloud, we would like to provide an example of how to receive and post these files using other great clouds.

For this example we are going to use Sinatra to create a REST web service application. This application will then be deployed to Heroku where it will receive and then push the recorded audio files from Tropo up to an Amazon S3 account.

First, Sinatra provides a simple domain specific language in Ruby for creating REST web services, or whole web sites if you choose to. In this case we are using Sinatra to write our REST API to receive and then process the audio file. Creating an HTTP resource with Sinatra is as simple as this:

  get '/pizza' do
    order params['toppings']
    # Do some more stuff
  end

To get this resource you would then put this in your web browser:

  http://www.yourhost.com/pizza?toppings=pepperoni

If we take this a step further, writing the code to receive an audio file and post to Amazon S3 is not much harder:

post '/post_audio_to_s3' do
  AWS::S3::S3Object.store(params['file_name'],
                          File.open(params['filename'][:tempfile].path),
                          AWS_CONFIG['bucket_name'])
end

In your Tropo app you may then write a script to record and send an audio file:

  answer
  say 'Welcome to the recording application'
  startCallRecording 'http://www.yourhost.com/post_audio_to_s3?file_name=myfilename.wav'
  ask 'Do you like chocolate?', { :choices => 'yes, no' }
  stopCallRecording
  hangup

Now we have our web service, but where to run it? This is where Heroku comes in. Heroku is an ‘instant Ruby platform’ that allows you to deploy an application, via Git, and have it up and running on a scalable infrastructure in minutes. Lucky for us, Heroku excels at running Sinatra apps, and they even have the AWS-S3 library built in. All you need is a Heroku account, which is free to get started with a Blossom, and you are ready to start running your web service.

Last but not least, you will need an Amazon S3 account to store your files. Thats it, you may now start moving your files through the clouds to Amazon, or use this as an example to store them wherever you choose. The full application ready to deploy locally or to Heroku is available at Github here.