1
votes

I am using the java speech recognition API - Jarvis located at https://github.com/lkuza2/java-speech-api

However when I run my application, I get an error : Server returned HTTP response code: 400 for URL: https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US&maxresults=1 (This is the URL that this api uses to get response from Google)

I also created a API key as mentioned in the earlier posts and tried to use the url (this is version 2 API): www.google.com/speech-api/v2/recognize?output=json&lang=en-US&key=MYKey". But in this case I get a null response from Google.

Can anybody please tell me how to get around this?

1
400 is a bad request. Be sure what you're sending across is correct with respect to the API.Makoto
@Makoto This is the URL that the API uses. I also tried using the V2 URL (google.com/speech-api/v2/…). I can see that there were 31 requests for the Google speech API from my Google Developer Console. But I get a null response. My question is "Does this API actually work?"Sudatta
BTW I am using the example listed at linkSudatta
I've never used jarvis but I do use google speech URL directly. V1 has stopped working a few months ago, but V2 is working like a charm if you provide an API key and parse the result correctly.Florent

1 Answers

1
votes

I change some things from the Recognizer class:

I change the GOOGLE_RECOGNIZER_URL constant to:

    private static final String GOOGLE_RECOGNIZER_URL = "https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=YOUR_KEY";

Then I changed this method because the response data have 2 lines

   private String rawRequest(File inputFile, int maxResults, int sampleRate) throws IOException

The first line (the one that is read and sent) is null (i don¡t really know why) and the second line has the response of the speech recognized. For this you must read the second line (don't know if there is a nicer way):

    String response = br.readLine();
    response = br.readLine();
    br.close();
    return response;

Then I change this method, I think it was using the v1 URL response or something because this method looks for utterance in the json response and there is none utterance key.

    private void parseResponse(String rawResponse, GoogleResponse googleResponse)
    if (rawResponse == null)
        return;

    JSONObject jsonObject = new JSONObject(rawResponse);
    JSONArray jsonArray= (JSONArray) jsonObject.get("result");
    JSONArray jsonArrayResult = (JSONArray) jsonArray.getJSONObject(0).get("alternative");
    googleResponse.setResponse(jsonArrayResult.getJSONObject(0).get("transcript").toString());
    googleResponse.setConfidence(jsonArrayResult.getJSONObject(0).get("confidence").toString());

I'm new with the json library so it might be a better and shorter way but this worked for me!