0

I'm trying to use the speech recognition REST API service from wit.ai

I have used Volley to send a POST request to the URL https://api.wit.ai/speech

This is what I have currently done:

void makeApiCall(){
    StringRequest request =  new StringRequest(Request.Method.POST, "https://api.wit.ai/speech", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("wit_response",response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("wit_response",error.toString());
        }
    }){
        @Override
        protected Map<String,String> getParams() throws AuthFailureError{
            Map<String,String> params = new HashMap<>();
            params.put("Authorization","Bearer XXXXXX"); //hidden my token
            params.put("Content-Type","audio/mpeg3");
            return params;
        }
        @Override
        public byte[] getBody() throws AuthFailureError {

            return sendToByte();
        }
    };



    RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
    queue.add(request);
}

I am receiving an error of com.android.volley.ClientError on the wit_response log key inside onErrorResponse() method

I have not missed the content type and authorization header, and my sendToByte function is succesfully returning an mp3 file converted to byte array.

What is the issue?

Fahad Saleem
  • 413
  • 2
  • 13
  • Have you tried making that same Post call in a separate Rest client like Postman or Restlet? – D Ta Jan 25 '19 at 17:51

1 Answers1

0

I had to use this link https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594

And use MultiPartRequest class as described in this to upload my file.

Please comment here if you need any assistance (for all future folks)

Fahad Saleem
  • 413
  • 2
  • 13