Posts Tagged ‘recording’

Posting Tropo Recordings to Amazon S3 via Heroku

Friday, September 3rd, 2010

Tropo has the ability to record the audio of calls for you using the record method. To get the recordings, you need an application that will accept an HTTP POST or PUT and then store the audio recordings somewhere for you. Just over a year ago we blogged about using Heroku to host the application and then send those files on to Amazon S3.

If you want the source code to do this your self, it is available on Github here. The original blogpost may be found here. Of course you are not limited to using Heroku and Amazon S3, but this serves as a working example.

Processing recordings with PHP

Thursday, June 10th, 2010

When you tell Tropo to record audio, either through a call recording or by using the record command to record a specific prompt, Tropo then sends that audio to your server. You can give Tropo FTP credentials and we’ll FTP it over to you, or you can give an http URL and we’ll make an POST to that URL containing your file.

When Tropo POSTS an audio file, we submit it as multipart form data, so the same tools you’d use to process a file upload field on a form can be used to save your recording. The form field name Tropo uses for the file is “filename“.

Here’s an example using the Tropo WebAPI, PHP, and the PHP WebAPI library. In this example, I’m building a simple voicemail recorder, asking the caller to leave a message at the beep, and then saving the recorded audio to my server.

I’m also introducing some logging, using the excellent KLogger class to write a log file every time we save a recording.

First, a walkthrough of the important parts of the code, then a link to the full code at the end.

<?php
  $tropo->record(array(
    'say' => 'Leave your message at the beep.',
    'url' => getself() . '?record', // append ?record to the URL
    ));

function getself() {
 $pageURL = 'http';
 $url = ($_SERVER["HTTPS"] == "on") ? 'https' : 'http';
 $url .= "://" . $_SERVER["SERVER_NAME"];
 $url .= ($_SERVER["SERVER_PORT"] != "80") ? ':'. $_SERVER["SERVER_PORT"] : '';
 $url .= $_SERVER["REQUEST_URI"];
 return $url;
}
?>

Create a recording prompt, saying “Leave your message at the beep.” Tropo has a beep parameter that you can use to turn off the beep if you want. It’s on by default, and we want to leave it on here. We also add the URL where we’d like to send the recording using a simple function that gives us the full URL of the current application. Appended to the URL is ?record, a flag we’ll use to see if the request to our app is an incoming call or a call recording being posted.

This PHP code generates the follow JSON that’s sent to Tropo:

{
    "tropo": [
        {
            "record": {
                "say": {
                    "value": "Leave your message at the beep."
                },
                "url": "http://example.com/recordingdemo.php?record"
            }
        }
    ]
}

So now to save the file…

<?php
  $target_path = 'path/to/recording/' . $_FILES['filename']['name'];
  if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) {
    $log->LogInfo("$target_path [{$_FILES['filename']['size']} bytes] was saved");
  } else {
    $log->LogError("$target_path could not be saved.");
  }
?>

In this code, which we only run if the ?record flag is present, we use PHP’s global $_FILES array to fetch the file data out of the multipart form post. We start by setting the path and filename we’d like to use for saving the file (line 2) using the filename that Tropo gives us in $_FILES['filename']['name']. Then in line 3, we move the uploaded file from the temporary location that PHP stores a new upload in to the path we chose. If the file is moved successfully, we write a log entry with the path and file size (line 4). If an error occurred, we note that in the log on line 6.

To get the whole sample code, grab the Tropo WebAPI PHP library from github and look in the Samples directory or just grab the sample off Github directly.

Tropo Adds Transcription for Recordings

Wednesday, August 26th, 2009

We have been busy adding additional features to Tropo with more to come. Today we are making available the ability to transcribe recorded audio and have the results posted to you via email or an HTTP POST. In addition to this, we have also created an option that allows you to send the recorded audio file out of the Tropo cloud directly to your servers via FTP or an HTTP POST. Now you may have easy access to recordings and what is being said!

To take advantage of this all you need to do is add a few extra options to your record method. Here is a Ruby example:

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.03456789,
:recordURI           => 'http://tropo.to-a-domain.com/post_audio?filename=file123456.wav',
:transcriptionOutURI => 'http://tropo.to-a-domain.com/receive_transcription',
:transcriptionID     => '123456' })

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

(Link)

Don’t forget that these new options are available in any of the languages supported by Tropo. So do not hesitate to add this to your Groovy, Javascript, PHP, or Ruby scripts today!

We have more to come shortly, so stay tuned for additional features and helper apps to take advantage of these new features.