UPDATE AFTER ANSWER: the code is now fixed and works look below for correct code
Im trying to post from a perl script (on my server) to my google app engine, and im not sure how to go about doing this on the google app engine side.
This is my perl script for testing :
my $audio = `cat audiotest.flac`;
my $url = "http://app.appspot.com/MainPage" #this is not the real url
my $ua = LWP::UserAgent->new;
my $response = $ua->post($url, Content_Type => "audio/x-flac; rate=16000", Content => $audio);
if ($response->is_success)
{
print $response->content;
}
So that is how i send the flac binary stream, but the question is how does google app engine receive it and do something with it. This is what im attempting to do in python (but the code is not correct and / or doesnt make sense)
class MainPage(webapp.RequestHandler):
def post(self):
destinationURL = "http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US"
result = urlfetch.fetch(url=destinationURL, payload= self.request.body, method=urlfetch.POST, headers={'Content-Type': 'audio/x-flac; rate=16000'})
self.response.out.write(result.content)
result is supposed to return to me the string representation of the flac audio i submitted to google’s speech to text service (also known as x-webkit-speech). Any idea what i am supposed to put in the payload for the urlfetch, and how to get the result back? Thanks!
Since you’re sending the audio file as the body of the request, not as part of a form, you can access it with
self.request.body.I’m a little confused as to why you’re sending an audio file to App Engine just so it can send it to another service, though.