Tropo WebAPI Development Guide Home  |  Frameset Home

  Playing Audio Files  |  TOC  |  Making a Call  

Recording Audio


Want to record what the user has to say? Just use the record method.

require 'tropo-webapi-ruby'
require 'sinatra'

post '/record.json' do
  
  t = Tropo::Generator.new
  
  t.record({ :name => 'recording',
             :url => 'http://example.com/recording.rb', 
             :choices => { :terminator => "#"}
             }) do
                  say :value => 'Please leave a message'
              end
  t.response
  
end
var http = require('http');
var tropo_webapi = require('tropo-webapi');

var server = http.createServer(function (request, response) {

    var tropo = new TropoWebAPI();
	
    var say = new Say("Please leave a message.");
    var choices = new Choices(null, null, "#");

    //function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username)
    tropo.record(null, null, null, choices, null, null, null, null, null, "recording", null, say, null, null, "http://example.com/recording.js", null, null);
	
    response.end(TropoJSON(tropo));

}).listen(8000); 
<?php

require 'tropo.class.php';

$tropo = new Tropo();

$tropo->record(array(
  'say' => 'Please leave a message.',
  'url' => 'http://example.com/recording.php',
  'terminator' => '#'
  ));

$tropo->RenderJson();
?>
from itty import *
from tropo import Tropo

@post('/index.json')
def index(request):

	t = Tropo()

	t.record(name = "recording", choices = {"terminator": "#"} , say = "Please leave a message.", url = "http://example.com/recording.py")
	
	return t.RenderJson()

run_itty(server='wsgiref', host='0.0.0.0', port=8888)

{
   "tropo":[
      {
         "record":{
            "say":[{"value":"Please leave a message"}],
            "name":"recording",
            "url":"http://example.com/recording.js",
            "choices":{"terminator":"#"}
         }
      }
   ]
}

There a couple typical optional parameters that you might want to set, however. The following example shows a modification to the timeout (the amount of time Tropo will wait--in seconds and after playing the prompt--for the user to begin a response) as 10 seconds instead of the default 30:

require 'tropo-webapi-ruby'
require 'sinatra'

post '/record.json' do
  
  t = Tropo::Generator.new
  
  t.record({ :name => 'recording',
             :timeout => 10,
             :url => 'http://example.com/recording.rb', 
             :choices => { :terminator => "#"}
             }) do
                  say :value => 'Please leave a message'
              end
  t.response
  
end
var http = require('http');
var tropo_webapi = require('tropo-webapi');

var server = http.createServer(function (request, response) {

    var tropo = new TropoWebAPI();
	
    var say = new Say("Please leave a message.");
    var choices = new Choices(null, null, "#");

    //function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username)
    tropo.record(null, null, null, choices, null, null, null, null, null, "recording", null, say, 10, null, "http://example.com/recording.js", null, null);
	
    response.end(TropoJSON(tropo));

}).listen(8000); 
<?php

require 'tropo.class.php';

$tropo = new Tropo();

$tropo->record(array(
    'say' => 'Please leave a message.',
    'url' => 'http://example.com/recording.php',
    'terminator' => '#',
    'timeout' => 10
  ));

$tropo->RenderJson();
?>
from itty import *
from tropo import Tropo

@post('/index.json')
def index(request):

	t = Tropo()

	t.record(name = "recording", choices = {"terminator": "#"} , say = "Please leave a message.", url = "http://example.com/recording.py", timeout = 10)
	
	return t.RenderJson()

run_itty(server='wsgiref', host='0.0.0.0', port=8888)
{
   "tropo":[
      {
         "record":{
            "say":[{"value":"Please leave a message"}],
            "name":"recording",
            "url":"http://example.com/recording.js",
            "timeout":10,
            "choices":{"terminator":"#"}
         }
      }
   ]
}

That covers the basics of incoming calls; now you're ready for outbound.

Next Step: Making a Call


  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login
  Playing Audio Files  |  TOC  |  Making a Call  

© 2012 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site