Page 1 of 1

recording handover and PHP5

Posted: Wed Dec 19, 2007 10:30 am
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>";
?>

IVR code for file uploads in PHP

Posted: Wed Dec 19, 2007 11:47 am
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

Posted: Thu Dec 20, 2007 5:00 am
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?

IVR script change to play audio

Posted: Thu Dec 20, 2007 10:53 am
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

Posted: Fri Dec 21, 2007 5:58 am
by uncleunvoid
very good that worked,

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