We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

How can I dynamically play back information in VXML?

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
shoeman
Posts: 12
Joined: Fri Oct 17, 2003 2:46 pm

How can I dynamically play back information in VXML?

Post by shoeman »

I need to read off a phonenumber back to the listener by playing an audio file for each digit back to back. E.g. 2.wav, 3.wav, 4. wav. I have the below code right now but I need to make it dynamic because the phonenumber might be 7, 10, or 11 digits. I tried foreach but it doesn't look like Plum supports it contrary to the documenation. I need some Javascript or something you support to pull this off.



<audio src="Your'>http://66.148.213.243:9000/ivr/audio/pr ... .wav">Your phone number is</audio> <break msecs="100"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(0,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(1,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(2,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(3,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(4,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(5,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(6,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(7,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(8,1) + '.wav'"/>
<audio expr="'http://66.148.213.243:9000/ivr/audio/numbers/' + document.customerPhoneNumber.substr(9,1) + '.wav'"/>


I want to try something like:

<var name="phoneDigits" expr="document.customerPhoneNumber.toCharArray()"/>
<foreach item="phoneDigit" array="phoneDigits">

Any equivalant that lets me loop through each digit of a number string and call an audio line is what I need.

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

playing back multiple audio files for numbers on IVR system

Post by support »

Dynamic voicexml is typically achieved in 2 ways:
1) uses javascript (the plum voice platform has ecma script support)
2) use server side processing to build the vxml pages at load time


For very dynamic pages, it's more elegant to use option 2. Plum's in-house IVR developers frequently generate dynamic vxml using php to construct the pages. Here is an IVR sample demonstrating how this works using php:

Code: Select all

<?php

//retrieve the phone number stored in a GET variable
$phone_number = $_GET['phone_number'];


function create_vxml_for_phonenumber($phone, $audio_url){

  $result = "";

  //loop through each digit in the phone number
  for($digit=0; $digit < strlen($phone); $digit++){
    $current_digit = $phone[$digit];
    $digit_url = $audio_url  .  "$current_digit.wav";
    $result .=  "<audio src=\"$digit_url\">$current_digit</audio>";
  } 

  return $result;
}

$phonenumber_vxml = create_vxml_for_phonenumber("5551234", "http://66.148.213.243:9000/ivr/audio/numbers/");
?>
In the above IVR example, the variable $phonenumber_vxml will contain the following:

Code: Select all

<audio src="http://66.148.213.243:9000/ivr/audio/numbers/5.wav">5</audio> 
<audio src="http://66.148.213.243:9000/ivr/audio/numbers/5.wav">5</audio> 
<audio src="http://66.148.213.243:9000/ivr/audio/numbers/5.wav">5</audio> 

<audio src="http://66.148.213.243:9000/ivr/audio/numbers/1.wav">1</audio> 
<audio src="http://66.148.213.243:9000/ivr/audio/numbers/2.wav">2</audio> 
<audio src="http://66.148.213.243:9000/ivr/audio/numbers/3.wav">3</audio> 
<audio src="http://66.148.213.243:9000/ivr/audio/numbers/4.wav">4</audio> 

Keep in mind this is not a complete IVR example. The rest of the voicexml for the IVR application is missing, and there's no error checking to ensure the string containing the phone number contains only numeric digits, or is of valid length. It simply demonstrates how you might constrct a function on the server side to generate voiceXML. If you are more comfortable using a different server side language, feel free to do something similar in Perl, or JSP, or ASP, or whichever you language you intend to use.

If you require more clarification or find this doesn't suit your problem, please feel free to reply with any issues you might encounter and we'll attempt to provide additional information.

Hope this helps!

The Plum Support Team
Last edited by support on Thu Feb 25, 2010 5:46 pm, edited 3 times in total.

shoeman
Posts: 12
Joined: Fri Oct 17, 2003 2:46 pm

so I assume...

Post by shoeman »

I assume that I would call the PHP script with a <script> variable inside the prompt tag? Btw, great answer. Thanks.

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Calling the php script using <submit> in IVR example

Post by support »

If you are calling the php script from another IVR application, use the <submit> tag. Assuming the previous IVR example is in a php file named get_phone.php, here's an IVR example that calls the IVR script:

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">

<var name="phone_number" expr="'6173246879'"/>

<form id="test_form">
  <block> 
     <submit next="get_phone.php" method="GET" namelist="phone_number"/>
  </block>
</form>
<vxml/>


In the above IVR example, we call the script that contains the function we defined earlier, and we pass it a a GET variable with the same name as the GET variable in the target page (our phone number to generate the vxml for).

IMPORTANT NOTE: when submitting to another page, we completely leave the page we are at, and transition to the new document. so when we submit to get_phone.php, it's important to remember get_phone.php must be a valid vxml document, containing the <vxml> tags, with no white space before or after, otherwise we will get a bad fetch error when we attempt to submit to the page.
Last edited by support on Thu Feb 25, 2010 5:47 pm, edited 2 times in total.

shoeman
Posts: 12
Joined: Fri Oct 17, 2003 2:46 pm

Post by shoeman »

I don't think you are following what I want to do here. I know how to generate dynamic vxml. It is documented everywhere and I have written a JSP to do it. I need to generate dynamic audio tags inside a prompt tag. Should I use <value expr="call Java Script here"/> or what? If I call a server side method how do I get the result back inside the prompt tag?

shoeman
Posts: 12
Joined: Fri Oct 17, 2003 2:46 pm

Post by shoeman »

It doesn't look like Plum supports script or submit tags inside prompts which makes it hard to dynamically generate these audio tags. How am I supposed to work around this?

Thanks,

John

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Explanation for IVR tags

Post by support »

Let's clear up a few points you touched on previously:

1) No, you cannot place <submit> tags within prompts. They generally go in <filled>
or <block> tags, but there are other places it can be declared as well.


The relationship of these IVR tags is hierarchical, and the parent/child sections for each IVR tag will tell you what is considered legal for a given context.

Let's look at a given example. Open up the Plum IVR programmer's reference manual and go to entry for the
<form> tag.

You will see a parent section and a child section that looks something like this:

Code: Select all

Child Tags
<block>, <catch>, <error>, <field>, <filled>, <grammar>, <help>, <initial>, <link>, <noinput>, <nomatch>, <property>, <record>, <subdialog>, <transfer>, <var> 

Parent Tags
<vxml> 
This means a <form> tag can contain any of tags listed in the child Tag section.
This IVR code is correct, because <block> IS a child tag of <form>:

Code: Select all

....
  <form>
     <block>
     </block>
  </form>
....
this code is incorrect, since <goto>
IS NOT a child tag of <form>:

Code: Select all

....
  <form>
     <goto .../>
  </form>
....



The parent tags section lists all of the tags that the <form> tag can be contained in. This code is correct, because <vxml> IS a parent tag of <form>:

Code: Select all

<vxml>
  <form>
....
  </form>
</vxml>
this code is incorrect, since <block> IS NOT a parent tag of <form>:

Code: Select all

<block>
  <form>
....
  </form>
</block>
As you can see, the Plum IVR Programmer's reference manual is a valuable reference companion for voiceXML development. Many of our developers frequently refer to it while building VXML apps, as it is a fairly comprehensive guide as to what is legal and what isn't once you know how to interpret it.


2) you are thinking about voicexml in a way that is slightly incorrect. An explanation:
In procedural or object oriented programming languages, there is a specific flow of execution. For example, here is a very simple php script:

Code: Select all

<?php
function test(){
  echo " there ";
}

  echo "hello ";
  test();
  echo "how are you?");
?>  


the output from the above script would be:

Code: Select all

  "hello there how are you?"
This demonstrates flow of execution. The php interpreter prints "hello". Then it jumps to the function and prints " there ". At this point, the function completes and execution JUMPS BACK TO WHERE IT LEFT OFF, and prints "how are you?".
This seems like a no-brainer, and is very standard behavior for languages such as java, c, etc. However voiceXML does NOT behave this way. There is no implicit "jump back to where I left off".
Now let's look at some voiceXML that illustrates this principal. Consider the following 2 voicexml documents:

document 1 (start_page.vxml):

Code: Select all

<?xml version="1.0"?> 
<vxml version="2.0"> 

<var name="full_name" expr="'Matthew T. Silverman'"/> 

<form id="test_form"> 
  <block> 
     Get ready, you are going on a trip!
     <submit next="another_page.php" method="POST" namelist="full_name"/> 

     OK, this is some test text to speech
  </block> 
</form> 
<vxml/> 


document 2 (another_page.php):

Code: Select all

<?xml version="1.0"?> 
<vxml version="2.0"> 

<?php
  //retrieve the full name from the POST variable
  $full_name = $_POST['full_name'];
?>

<!-- here we populate the vxml variable using the data
       we pulled from the POST variable -->
<var name="full_name" expr="'<?php echo $full_name ?>'"/> 


<form id="test_form"> 
  <block> 
    Hello <value expr="full_name"/>, nice to meet you! 
  </block> 
</form> 
<vxml/> 

Now, lets go through a sample of what the caller will hear:

Code: Select all

*Connected*
vxml:  "Get Ready, you are going on a trip!"
*slight pause*
vxml: "Hello Matthew T. Silverman, nice to meet you!"
*call ends, vxml terminates call*
Last edited by support on Thu Feb 25, 2010 5:49 pm, edited 6 times in total.

shoeman
Posts: 12
Joined: Fri Oct 17, 2003 2:46 pm

Post by shoeman »

This response really frustrates me. You make the big mistake of assuming that I don't know what you are talking about. I know how valuable the Plum reference manual is and I have looked at several other online manuals as well. Many of them allow much richer behavior inside the <prompt> tags such as <submit> and <script>. I also am familar with the FIA and how VXML flow of control works. I also am an object-oriented programmer with over 5 years of exerience. I am asking a specific questions about Plum. How do I solve the problem I orginally asked. Let me put to it clearly. If you were asked to play a different audio file for each digit of a number stored in vxml back to the user how would you do it? That is the only thing I am interested in. Please stay on track and help me with my specific problem so I will tell others how great your product and support is. And please be clear about what parts of the VXML 2.0 spec Plum supports. Or we are going to be forced to find another vendor.

shoeman
Posts: 12
Joined: Fri Oct 17, 2003 2:46 pm

Post by shoeman »

I finally found out the answer to this by calling Plum support. The simple answer is to subdialog out to a JSP or PHP script or something that generates a form with a block with a prompt and inside the prompt you can dynamically generate the audio tags. The mistake I was making was not realizing that I could generate the audio tags in a different form and then transfer control back to another form or menu. I was trying to dynamically write vxml using Javascript or some solution like that.

Post Reply