title: How to stream speech to wit.ai speech end point
body: <p>I'm having trouble getting a good response from wit.ai's speech end point. The response is always 400. I seem to be following the <a href="https://wit.ai/docs/http/20170307#post--speech-link" rel="nofollow noreferrer">docs</a> but something's wrong.</p>
  
  <p>Any help would be appreciated.</p>
  
  <pre><code>private string ProcessSpeechStream(Stream stream)
    {
              BinaryReader filereader = new BinaryReader(stream);
              byte[] arr = filereader.ReadBytes((Int32)stream.Length);
              filereader.Close();
  
  
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.wit.ai/speech");
              request.SendChunked = true;
              request.Method = "POST";
              request.Headers["Authorization"] = "Bearer " + APIToken;
              request.ContentType  = "chunked"; 
              request.ContentLength = arr.Length;          
              var st = request.GetRequestStream();
              st.Write(arr, 0, arr.Length);
              st.Close();
              // Process the wit.ai response
              try
              {
                  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                  if (response.StatusCode == HttpStatusCode.OK)
                  {
                      StreamReader response_stream = new StreamReader(response.GetResponseStream());
                      return response_stream.ReadToEnd();
                  }
                  else
                  {
                      Logger.AILogger.Log("Error: " + response.StatusCode.ToString());
                      return string.Empty;
  
                  }
              }
              catch (Exception ex)
              {
                  Logger.AILogger.Log("Error: " + ex.Message, ex);
                  return string.Empty;
              }
    }
  </code></pre>