title: Posting FLAC to Google Voice Recognition API from PHP
body: <p>I am quite experienced in PHP but I've always had troubles with connection between servers like <strong>"post"</strong>. I have a FLAC audio file that I need to <strong>post</strong> to Google's Speech Recognition API server. I don't know neither how to "listen" to its response. I would like a script like that, assuming that this kind of function exists :</p>
  
  <pre><code>&lt;?php
  
     $fileId = $_GET['fileId'];
     $filepath = $fileId . ".flac";
     recognize($filepath);
  
    function recognize($pathToFile) {
  
        //It's the following function that I'm looking for 
        $response = $pathToFile-&gt;post("http://www.google.com/speech-api/v1/.....&amp;client=chromium"); 
  
        //The $response would be the short JSON that Google feed back.
        echo $response;
  
    }
  
  ?&gt;
  </code></pre>
  
  <h2>EDIT</h2>
  
  <p>I've followed a tutorial to create a Shell Script that posts my FLAC file using Wget --post. I would like to post like this, but in PHP. Also, at the end of the command, there is this <code>&gt; answer.ret</code> line, so that Google's answer would be written to this file. I was wondering if there was an alternate method to it in PHP.
  Here's the command line :</p>
  
  <pre><code>wget -q -U "Mozilla/5.0" --post-file audio1.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=fr-fr&amp;client=chromium" &gt; trancription1.ret
  </code></pre>
  
  <h2>EDIT 2</h2>
  
  <p>I figured out how to do it, with @hakre 's answer and baked up a little Gist for curious people. Here it is: <a href="https://gist.github.com/chlkbumper/4969389" rel="nofollow">https://gist.github.com/chlkbumper/4969389</a>. Don't forget that the FLAC file <em>must be a 16k bitrate FLAC</em></p>