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

recording handover and PHP5

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
uncleunvoid
Posts: 16
Joined: Mon Dec 10, 2007 6:33 am

recording handover and PHP5

Post by uncleunvoid »

little problem here.
it seems everything executes fine apart from the fact that the variable used to store the file seems to be empty.

where did this go wrong?


VXML:
<?xml version="1.0"?>
<vxml version="2.0">
<form>
<record name="myrecording" beep="true">
<prompt>
Please record a message after the beep.
</prompt>
<filled>
You just recorded the following message:
<value expr="myrecording"/>
Lets save this.
<submit next="upload.php" method="post" namelist="myrecording"/>
</filled>
</record>
</form>
</vxml>


PHP (5):
<?
header('Cache-Control: no-cache');

// Post variables
$myrecording = $_POST[myrecording];
file_put_contents("test.wav" ,$myrecording);
//
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
echo "<vxml version=\"2.0\">";
echo "<form id=\"main\">";
echo "<block>";
echo "Thank you";
echo "</block>";
echo "</form>";
echo "</vxml>";
?>

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

IVR code for file uploads in PHP

Post by support »

Hi,

You shouldn't use file_put_contents to do file uploads in PHP. Your PHP file should look more like this IVR code example. Note what's inside of the IVR <block> tags:

Code: Select all

<?php
echo "<?xml version=\"1.0\" encoding=\"latin-1\"?>";
?>
<vxml version="2.0">
    <form>
        <block>
<?php
	if (isset($_FILES['myrecording']) && is_uploaded_file($_FILES['myrecording']['tmp_name'])) {
		move_uploaded_file($_FILES['myrecording']['tmp_name'],"myrecording.wav");
		unlink("temp.ul");
		echo "<prompt bargein=\"false\">Audio file saved.</prompt>\n";
	} else {
		echo "<prompt bargein=\"false\">Audio not saved.</prompt>\n";
	}
?>
        </block>
    </form>
</vxml>
Keep in mind that the default media format of the file is "audio/basic", which means it's going to be a raw u-law media file. If you want to make your recorded file a .wav file, you should update your VXML to do so.

Hope this helps.

Regards,
Plum Support
Last edited by support on Fri Feb 19, 2010 12:29 pm, edited 4 times in total.

uncleunvoid
Posts: 16
Joined: Mon Dec 10, 2007 6:33 am

Post by uncleunvoid »

Ok I see,

the php file works in parts. I had to remove the 'unlink' line as it caused an error.

Still yet, even though I have a file now saved, the file wont play. Media Player, iTunes, Flash all say it's a wrong format or corrupted file.

Why would that be?

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

IVR script change to play audio

Post by support »

Hi,

You need to format your audio file to be able to properly play it. In your VXML script, you would want to change this line of IVR code for the <record> tag:

Code: Select all

<record name="myrecording" beep="true"> 
to include this:

Code: Select all

<record name="myrecording" beep="true" type="audio/x-wav"> 
This will set the media format of the file to a .wav format instead of u-law raw format.

Hope this helps.

Regards,
Plum Support
Last edited by support on Wed Jan 13, 2010 12:20 pm, edited 4 times in total.

uncleunvoid
Posts: 16
Joined: Mon Dec 10, 2007 6:33 am

Post by uncleunvoid »

very good that worked,

funny that in most code examples i found, the type is not set for the recording.

Post Reply