TeleStax.orgCommunity Documentation

Chapter 7. Advanced RestComm Examples

7.1. Activating Text-to-Speech (TTS)
7.1.1. Say Verb
7.1.2. Record Verb
7.1.3. Dial Verb and Client
7.1.4. Dial Verb and Uri
7.1.5. Dial Verb and Conference
7.1.6. Gather Verb

In this chapter, you will learn how to use more advanced features of Restcomm verbs to create communications applications

You must get an API key from http://www.voicerss.org in order to proceed with this section. You can register for a free account and an API key will be emailed to you. Once you have the API key, open the $RESTCOMM_HOME/standalone/deployments/restcomm.war/WEB-INF/conf/restcomm.xml file and find the speech-synthesizer VoiceRSS section. Add your API key as shown below and restart RestComm


<speech-synthesizer
		class="org.mobicents.servlet.restcomm.tts.VoiceRSSSpeechSynthesizer">
		<service-root>http://api.voicerss.org</service-root>
		<apikey>2901c0aXXXXXXXXXXXXXX</apikey>

Once you have done that, you are ready to use Text-to-Speech feature of RestComm.

Create a file called test.xml in the $RESTCOMM_HOME/standalone/deployments/restcomm.war/demos/ directory and copy the content of the application below into the test.xml file and save it


<?xml version="1.0" encoding="UTF-8"?>
<Response>
        <Say>Welcome to RestComm, you have successfully tested the Say Verb</Say>
</Response>

From a command terminal run the Curl command below to bind the 5555 phone number to the test.xml file.


curl -X POST  http://ACae6e420f425248d6a26948c17a9e2acf:77f8c12cc7b8f8423e5c38b035249166@127.0.0.1:8080/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers.json -d "PhoneNumber=5555" -d "VoiceUrl=http://127.0.0.1:8080/restcomm/demos/test.xml"


If the command is successful, you will see an output similar to the following:


{
  "sid": "PN0834628c131e4b66bc862ae0b21b7cfa",
  "account_sid": "ACae6e420f425248d6a26948c17a9e2acf",
  "friendly_name": "5555",
  "phone_number": "+15555",
  "voice_url": "http://127.0.0.1:8080/restcomm/demos/hello-play.xml",
  "voice_method": "POST",
  "voice_fallback_method": "POST",
  "status_callback_method": "POST",
  "voice_caller_id_lookup": false,
  "date_created": "2013-08-15T17:45:21.409-06:00",
  "date_updated": "2013-08-15T17:45:21.409-06:00",
  "sms_method": "POST",
  "sms_fallback_method": "POST",
  "api_version": "2012-04-24",
  "uri": "/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PN0834628c131e4b66bc862ae0b21b7cfa.json"

Next, you have to configure your SIP phone and make a call to the test.xml dialing number 5555

Start the SIP phone Ekiga (see below) and dial 5555@127.0.0.1:5080. You will hear the content of the Say Verb in the test.xml file.

This verb is used to get user input and instruct RestComm to perform a specific task. This example is a little bit more elaborate and it will require the creation of a php file. You also must host the php file on a web server like Apache. Copy the Gather application below into the test.xml and save the file.


<?xml version="1.0" encoding="UTF-8"?>
<Response>
	 <Gather action="http://127.0.0.1/test-user-input.php" numDigits="1">
		 <Say>Welcome to Telestax RestCom.</Say>
		 <Say>For opening hours, press 1.</Say>
		 <Say>to talk to Alice, press 2.</Say>
	 </Gather>
 <!-- If customer doesn't input anything, prompt and try again. -->
	 <Say>Sorry, I didn't get your response.</Say>
	 <Redirect>http://127.0.0.1:8080/restcomm/demos/test.xml</Redirect>
 </Response>

Create a php file in the Apache /var/www/html directory. 

You can use any web server of your choice, in this example, we shall be using Apache on a Linux computer

Start the httpd server as follows sudo service httpd start

Create a new file called test-user-input.php in the /var/www/html directory

Copy the php application below into the test-user-input.php and save


<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';
 
    echo '<Response>';
 
    $user_input = (int) ($_POST['Digits']);
 
    if ($user_input == 1)
        
    {
         echo '<Say>Our Opening hours are 24 hours 7 Days a week </Say>';
        echo '<Say>Telestax appreciates your business</Say>';
        echo '<Say>You may Hang up or wait to be redirected to the main menu</Say>';
        echo '<Redirect>http://127.0.0.1:8080/restcomm/demos/test.xml</Redirect>';
   
    }  elseif($user_input == 2) {
 
        echo '<Say>You are being forwarded to Alice</Say>';
        echo '<Dial callerid="+1234568789">';
        echo '<Client>alice</Client>';
	echo '</Dial>';

     } 
    echo '</Response>';
?>

This example welcomes the user and offers two options. If the user presses 1, he hears the openining hours message. If the user presses 2, he will be redirected to user Alice.

To test the application using the Gather verb, dial any number from user Bob and follow the application instruction.