ERROR error.badfetch: Trying to add audio content <prompt> to non-audio container <form>
Below is my code:
Expand|Select|Wrap|Line Numbers
- use CGI;
- use Cwd;
- use File::Basename;
- use Time::localtime;
- # ---------------------------------------------------------------------
- # These are here for debugging, in case you need more information
- # about exactly how the parameters were passed in.
- if (defined($ENV{'REQUEST_METHOD'}))
- {
- $method = $ENV{'REQUEST_METHOD'};
- }
- if (defined($ENV{'CONTENT_TYPE'}))
- {
- $content_type = $ENV{'CONTENT_TYPE'};
- }
- if (defined($ENV{'CONTENT_LENGTH'}))
- {
- $content_length = $ENV{'CONTENT_LENGTH'};
- }
- # Go ahead and print the HTTP headers here,
- # because we need them no matter what happens
- print "Content-type: application/voicexml+xml\n";
- print "\n";
- print "<?xml version='1.0'?>\n";
- print "<!DOCTYPE vxml PUBLIC \"-//BeVocal Inc//VoiceXML 2.0//EN\"\n";
- print " \"http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd\">\n";
- print "<vxml version='2.0' xmlns='http://www.w3.org/2001/vxml'>\n";
- print " <form id='foo'>\n";
- #print "Method is $method\n";
- #exit;
- # Ask the CGI module to read the request
- my $q = new CGI;
- # Find the "greeting" parameter, which has the recorded data in it
- my $audiodata = $q->param('voiceMessage');
- # Figure out what directory this script lives in.
- # That's where we want to save the recorded file.
- # I'm not totally sure why the fileparse_set_fstype is necessary, but it is
- fileparse_set_fstype("MSDOS");
- my ($scriptName, $scriptDir, $scriptSuffix) = fileparse($0, (".pl"));
- print "<block><log>\$0 = $0</log></block>\n";
- print "<block><log>scriptDir = $scriptDir</log></block>\n";
- print "<block><log>scriptName = $scriptName</log></block>\n";
- print "<block><log>scriptSuffix = $scriptSuffix</log></block>\n";
- if ($method eq "POST") {
- my $filename = "greeting.wav";
- print "<block><log>Content-Type = $content_type</log></block>\n";
- if ($content_type =~ /^multipart\/form-data;/) {
- # For a multipart/form-data POST request, "greeting" has two meanings:
- # In a scalar context, it is the file name sent by the VXML Interpreter
- # In a filehandle context, it's a read-only filehandle for reading the data
- open(LOCAL, ">/$scriptDir/$filename");
- while (<$audiodata>) {
- print LOCAL $_;
- }
- close LOCAL;
- }
- else {
- # application/x-www-form-urlencoded
- # The binary recorded data is in the "greeting" variable.
- open(LOCAL, ">/$scriptDir/$filename");
- print LOCAL $audiodata;
- close LOCAL;
- }
- } else {
- ("Not a POST request.");
- }
- # -------------------------------------------------------------------------
- # Now, let's return a nicely formed VXML file.
- print " <prompt>Do you want to quit?</prompt>\n";
- print " <help>Please say yes or no.</help>\n";
- print " <filled>\n";
- print " <if cond=\"hello=='yes'\">\n";
- print " <prompt>OK. Goodbye.</prompt>\n";
- print " <exit/>\n";
- print " <else/>\n";
- # Edit this next line, to point at the original record.vxml file.
- print " <goto next=\"contact_post.vxml\"/>\n";
- print " </if>\n";
- print " </filled>\n";
- print " </field>\n";
- print_footer();
- sub print_footer {
- print "</form>\n";
- print "</vxml>\n";
- }
- sub error($) {
- my ($error) = @_;
- print " <block>Error. $error</block>\n";
- print_footer();
- exit 0;
- }