Posts Tagged ‘transcription’

Send a Fax with your Voice!

Monday, February 21st, 2011

Tropo just recently partnered with PamFax to deliver faxing capabilities via an API.  Jason Goecke wrapped their API with a very simple Ruby gem called pamfaxr available at GitHub and installable using a “gem install pamfaxr” from your command line.  Using the PamFaxr Ruby gem, I will demonstrate how to send a simple fax as well as how to build a Tropo Voice to Fax transcription application using our Scripting API!

Getting Started

Before you can start sending faxes, you need to head over to the PamFax site and sign up for a PamFax account. After you fill out and submit the form, you’ll get an email with your login credentials and how to get started.

You also need to install the Ruby gem called pamfaxr on to the system where you are going to run the application that will send the fax. The Ruby gem is available at GitHub and should install simply by typing “gem install pamfaxr” from your command line. You will need to edit the code to have your PamFax username and password.

Sending A Fax From The Command Line

Before we involve Tropo, here is the Ruby/Sinatra code for simply sending a fax from the command line using the PamFaxr gem:

require 'rubygems'
require 'pamfaxr'

# Pass user name and password
pamfaxr = PamFaxr.new :username => 'your_username',
                      :password => 'secret'

# Create a new FaxJob
faxjob = pamfaxr.create_fax_job

# Add the cover sheet
covers = pamfaxr.list_available_covers
pamfaxr.set_cover(covers['Covers']['content'][1]['id'], 'Chris was here 2!')

# Add files
# pamfaxr.add_remote_file('https://s3.amazonaws.com/pamfax-test/R-intro.pdf')
# pamfaxr.add_file('examples/R-intro.pdf')

# Add a recipient
pamfaxr.add_recipient('+14802191300')

# Loop until the fax is ready to send
loop do
  fax_state = pamfaxr.get_state
  break if fax_state['FaxContainer']['state'] == 'ready_to_send'
  sleep 5
end

# Send the fax
pamfaxr.send_fax

Just copy that code into a text file, edit it to have your information in it and then run it with ruby from your command line. In a short bit you should have a fax waiting for you.

Sending Faxes From Tropo

Now for the fun Tropo Voice to Fax application code! The first code snippet is written in Ruby runs on the Tropo cloud. It greets the caller, asks for your fax number, records your voice/fax message and sends the transcription via a callback to the Ruby/Sinatra application that sends the actual fax.  Here’s the Tropo code:

say "Welcome to the Tropo fax demo.", :voice => 'dave'

result = ask "What's your fax number? Please include your country code.", {
   :choices => "[11 DIGITS]", :voice => 'dave'}

record "Please say what you would like for me to fax.", {
    :beep => false,
    :voice => 'dave',
    :maxTIme => 60,
    :silenceTimeout  => 2,
    :transcriptionOutURI => "http://web1.tunnlr.com:11053/transcribe?fax=" + result.value
    }

say "Your voice is being converted to a facsimily!  Go check your fax machine!  Goodbye.", :voice => 'dave'

hangup

Here is the complimentary Ruby/Sinatra code that catches the Tropo transcription callback and sends the fax of the transcription to the number specified in the Tropo script using the PamFaxr gem as demonstrated above. This code needs to be run on a publicly-accessible web server to which Tropo can connect and send the data. You have several options including:

  • Running the code on your own publicly-available webserver
  • Running the code on a hosting service like Heroku
  • Running the code on your local machine and use a service like Tunnlr to make the service available

Once you have the Ruby/Sinatra code below running in one of those locations, you’ll just update the Tropo code above with the correct URL (on line 11).

The code is here:

require "rubygems"
require "sinatra"
require 'json'
require 'pamfaxr'

pamfaxr = PamFaxr.new :username => 'your_username',
                      :password => 'secret'

post "/transcribe" do

  transcript_json = JSON.parse(request.body.read)
  identifier = transcript_json['result']['identifier']
  transcript = transcript_json['result']['transcription']

  # Create a new FaxJob
  faxjob = pamfaxr.create_fax_job

  # Add the cover sheet
  covers = pamfaxr.list_available_covers
  pamfaxr.set_cover(covers['Covers']['content'][1]['id'], transcript)

  # Add a recipient
  pamfaxr.add_recipient('+' + params[:fax])

  # Loop until the fax is ready to send
  loop do
    fax_state = pamfaxr.get_state
    break if fax_state['FaxContainer']['state'] == 'ready_to_send'
    sleep 5
  end

  # Send the fax
  pamfaxr.send_fax

end

Wow, that was fun!  I hope that you enjoyed this demonstration and I hope that you find both our PamFaxr gem and our Tropo Scripting API useful and powerful.

Use SantaCall.Us to Get Christmas Gift Ideas!

Saturday, December 11th, 2010

Tropo launched and open-sourced a Ruby-based outbound dialing and transcription service for Christmas called SantaCall.Us!  This service allows you to enter a loved one’s phone number and name from the site to have Santa Claus call them to wish them Merry Christmas.

If you include your email address in the form, Santa will proceed to ask them for a Christmas wish.  Wishes are then transcribed in real time and emailed back to you for shopping ideas.

With only 12 days left until Christmas, we hope that you find this service both useful and fun for the holidays!

Merry Christmas,

Tropo

WebAPI: Now with outbound and transcription

Thursday, May 6th, 2010

When we released the new WebAPI last month, two things were missing. You couldn’t make an outbound call and transcription wasn’t available for recordings. Today we’ve added some things to make working with text and IM easier and brought parity to the Web and Scripting APIs, ensuring both have all the same features. So whether you want to host yourself and communicate over JSON or like the simplicity of our hosted Scripting API, you can do all the same things.

Here’s what’s new:

  • Outbound calls no longer require “Channel” parameter.
  • Quickly send a text message with new “message” feature
  • Outbound calling and messaging from the Web API
  • Transcriptions on the WebAPI
  • Sweden and Italy

No Channel required

When sending a text message or instant message, you need to provide call() with the network you want to send it out on. Previously we required you to also tell us if it was a voice or text channel. Obviously, if it’s an SMS message, it’s a text channel and not voice, so we’ve added defaults to the channel parameter. Now you can save a few keystrokes and just do this (JavaScript shown):

call('tel:+14075551212',{network:'SMS'});

Send a Message()

One thing people use Tropo’s text features for a lot is alerting. Sending a quick message out used to require that you set up a call, then say() something on that call and finally hang up the call. You can still do that if you want, but now you can do it all in one step;

<?php
message("Home team just scored. It's now Home: 4, Visitors: 1", array('network'=>'SMS', 'to'=>'14075551212'));
?>

Quick and easy, just fire off a message. This also comes in very handy if you want to fire of a text message while your application is on a voice call.

<?php
answer();
say('Thanks for calling the Tropo information service. Sending you a text message now.');
message('Here is what you were looking for...', array('network'=>'SMS', 'to'=>$currentCall->callerID));
?>

For reference, you can take a look at the message docs on either the Scripting or WebAPI.

Outward Bound

The session API can now kick off a WebAPI call. When you pass in the token for your WebAPI application, Tropo will now POST the JSON for the call to your URL so you can handle it. You can now respond to these POST requests with a new call element in the JSON.

{"tropo":[
   {"call":{
       "to":"tel:+13055195825"
   }},
   {"say":{
       "value":"Welcome to Tropo."
   }},
]}

For a full list of what options you can provide the call element, check out the WebAPI documentation for Call and the Session API.

Transcriptionist

When you record a caller’s input, you can now request that it be transcribed to text. Our transcription API can email you the text of the recording or POST it to the URL of your choosing.

{"tropo":[
   {"record":{
        "beep":true,
        "say":{
            "value":"I'm not here right now. Record your message after the beep."
        },
        "transcription": {
            "url":"mailto:you@example.com"
        }
    }},
]}

You can even pass in an ID that we’ll give to you when we hand you the transcription so you can tell different transcriptions apart. As always, the docs have the details on how to use a URL instead of email and all the other options you’ve got.

The new features are available for development applications today. The production servers will get upgraded in the near future, after we’ve seen the new code put through its paces on some developer applications.

And finally, we’ve added numbers in Sweden and Italy to our pool, allowing developers to purchase local numbers in those countries. Like elsewhere outside the US, these numbers can only be added to production accounts.

Transcriptions: how to do it and use it!

Friday, March 26th, 2010

So you have got a great application, it does all this fancy stuff and now you want to add transcriptions, but how? Well its actually quite simple! Transcriptions in Tropo are sent as a XML body, via POST, to the URL specified in the transcriptionOutURI parameter of the recording method. So below I have taken an example from our blog which showed how to actually do a transcription using the the record method.

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/transcriptions/tropoTranscribeCatch.php',
:transcriptionID     => '123456' })

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

So you can go ahead and deploy this bad boy to your hosted account and map it up to an application! So once this is done you need something on the other end to catch the transcription…what to do??!! Well I have a little example, which is also plug and play, that may be just what you are looking for! To start you simply deploy this little bit of ‘PHP Goodness ™’ to your webserver. This script will take the posted data, access the relevant nodes, and write it to disk for you.

<?
date_default_timezone_set('EST');

$obj = json_decode(@file_get_contents('php://input'));

$myFile = $obj->result->guid."-".$obj->result->identifier.".txt"; // Unique file name

touch ($myFile); 

$fh = fopen($myFile, 'a');

fwrite($fh, "Time Stamp:" . date('D, d M Y H:i:s T') . "\n");
// access XML data 
fwrite($fh, "Guid " . $obj->result->guid . "\n");
fwrite($fh, "Identifier: " . $obj->result->identifier . "\n");
fwrite($fh, "Transcription: " . $obj->result->transcription . "\n");
fwrite($fh,"________________________________________\n");
fclose($fh);

?>



Few tips that may help as well:

  • You may want to make sure your webserver has write permissions to the directory were you will be saving transcriptions
  • (chmod -R 775 /var/htdocs/transcriptions/)).
  • Make sure your PHP install is at least PHP 5.2, as the json_decode extension used in this example requires it.



I really hope this helps, and if there are any questions please feel free to contact our support team. We are most certainly always here to help!

Regards,

John Dyer
Customer Engineer
Voxeo Support

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.