By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,542 Members | 1,434 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,542 IT Pros & Developers. It's quick & easy.

Trying to add audio content to an non-audio container.

li0pxh0
P: 2
Does anyone know how to fix this error?
ERROR error.badfetch: Trying to add audio content <prompt> to non-audio container <form>

Below is my code:
Expand|Select|Wrap|Line Numbers
  1. use CGI;
  2. use Cwd;
  3. use File::Basename;
  4. use Time::localtime;
  5.  
  6. # ---------------------------------------------------------------------
  7. # These are here for debugging, in case you need more information
  8. # about exactly how the parameters were passed in.
  9.  
  10. if (defined($ENV{'REQUEST_METHOD'}))
  11. {
  12.     $method = $ENV{'REQUEST_METHOD'};
  13. }
  14.  
  15. if (defined($ENV{'CONTENT_TYPE'}))
  16. {
  17.     $content_type = $ENV{'CONTENT_TYPE'};
  18. }
  19.  
  20. if (defined($ENV{'CONTENT_LENGTH'}))
  21. {
  22.     $content_length = $ENV{'CONTENT_LENGTH'};
  23. }
  24.  
  25.  
  26. # Go ahead and print the HTTP headers here,
  27. # because we need them no matter what happens
  28. print "Content-type: application/voicexml+xml\n";
  29. print "\n";
  30. print "<?xml version='1.0'?>\n";
  31. print "<!DOCTYPE vxml PUBLIC \"-//BeVocal Inc//VoiceXML 2.0//EN\"\n";
  32. print "                      \"http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd\">\n";
  33. print "<vxml version='2.0' xmlns='http://www.w3.org/2001/vxml'>\n";
  34. print "  <form id='foo'>\n";
  35.  
  36.  
  37.  
  38. #print "Method is $method\n";
  39. #exit;
  40.  
  41. # Ask the CGI module to read the request
  42. my $q = new CGI;
  43.  
  44. # Find the "greeting" parameter, which has the recorded data in it
  45. my $audiodata = $q->param('voiceMessage');
  46.  
  47. # Figure out what directory this script lives in.
  48. # That's where we want to save the recorded file.
  49. # I'm not totally sure why the fileparse_set_fstype is necessary, but it is
  50. fileparse_set_fstype("MSDOS");
  51. my ($scriptName, $scriptDir, $scriptSuffix) = fileparse($0, (".pl"));
  52. print "<block><log>\$0 = $0</log></block>\n";
  53. print "<block><log>scriptDir = $scriptDir</log></block>\n";
  54. print "<block><log>scriptName = $scriptName</log></block>\n";
  55. print "<block><log>scriptSuffix = $scriptSuffix</log></block>\n";
  56.  
  57. if ($method eq "POST") {
  58.  
  59.     my $filename = "greeting.wav";
  60.  
  61.     print "<block><log>Content-Type = $content_type</log></block>\n";
  62.  
  63.     if ($content_type =~ /^multipart\/form-data;/) {
  64.         # For a multipart/form-data POST request, "greeting" has two meanings:
  65.         #  In a scalar context, it is the file name sent by the VXML Interpreter
  66.         #  In a filehandle context, it's a read-only filehandle for reading the data
  67.  
  68.         open(LOCAL, ">/$scriptDir/$filename"); 
  69.  
  70.         while (<$audiodata>) {
  71.             print LOCAL $_;
  72.         }
  73.         close LOCAL;
  74.     }
  75.     else {
  76.         # application/x-www-form-urlencoded
  77.         # The binary recorded data is in the "greeting" variable.
  78.  
  79.         open(LOCAL, ">/$scriptDir/$filename");
  80.         print LOCAL $audiodata;
  81.         close LOCAL;
  82.     }
  83.  
  84.  
  85. } else {
  86.      ("Not a POST request.");
  87. }
  88.  
  89.  
  90. # -------------------------------------------------------------------------
  91. # Now, let's return a nicely formed VXML file.
  92.  
  93. print "  <prompt>Do you want to quit?</prompt>\n";
  94.  
  95. print "  <help>Please say yes or no.</help>\n";
  96. print "  <filled>\n";
  97. print "    <if cond=\"hello=='yes'\">\n";
  98. print "      <prompt>OK. Goodbye.</prompt>\n";
  99. print "      <exit/>\n";
  100. print "    <else/>\n";
  101.  
  102. # Edit this next line, to point at the original record.vxml file.
  103. print "      <goto next=\"contact_post.vxml\"/>\n";
  104.  
  105. print "    </if>\n";
  106. print "  </filled>\n";
  107. print "  </field>\n";
  108.  
  109. print_footer();
  110.  
  111.  
  112. sub print_footer {
  113.     print "</form>\n";
  114.     print "</vxml>\n";
  115. }
  116.  
  117. sub error($) {
  118.     my ($error) = @_;
  119.     print "    <block>Error.  $error</block>\n";
  120.     print_footer();
  121.     exit 0;
  122. }
Jun 19 '09 #1
Share this Question
Share on Google+
3 Replies


eWish
Expert 100+
P: 971
Moved from insights to answers forum.
Jul 2 '09 #2

li0pxh0
P: 2
eWish,
Thanks for your help. I'll use the code tags and let you know how things work out.
Jul 3 '09 #3

KevinADC
Expert 2.5K+
P: 4,059
To me that error looks like it is not coming from perl. Recreate your page as a regular HTML/XML document and see if it produces the same error.
Jul 3 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.