来自Google Speech Api的空响应

时间:2017-02-16 17:49:57

标签: java httprequest speech-to-text google-speech-api

我在网上搜索了很长时间,没有发现任何有用的信息。

我录制了5s audiofile并将其上传到Google Speech API。我得到了Google的空回复,虽然在同一回复中它表示status = ok并且给我HTTP Responsecode 200.在文档上它说如果它响应代码200就成功了 这是我构建请求的代码

String audio = Base64.encodeBase64URLSafeString((WavFile.toString().getBytes()));

    JSONObject request_cfg = new JSONObject()
            .put("audio", new JSONObject()
                    .put("content", audio))
            .put("config", new JSONObject()
                    .put("encoding", "LINEAR16")
                    .put("sampleRate", 16000)
                    .put("languageCode", "de-DE"));
    String url = "https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=" + ___YOUR_API_KEY___;

    System.out.println(request_cfg);

    HttpResponse<JsonNode> request = Unirest.post(url)
            .body(request_cfg)
            .asJson();

    JSONObject response = new JSONObject(request);
    System.out.println(response);

使用该代码,请求正文如下所示:

{"audio":"content":"QzpcVXNlcnNcQmVubmlcd29ya3NwYWNlXFBlcnNvbmFsX0FpX2RpZV96d2VpdGVccmVzXHJlY29yZGluZy53YXY"},"config":{"encoding":"LINEAR16","languageCode":"de-DE","sampleRate":16000}}

,完整的回复如下:

{"headers":{"X-Frame-Options":{"empty":false},"Transfer-Encoding":{"empty":false},"Server":{"empty":false},"Cache-Control":"empty":false},"Alt-Svc":{"empty":false},"X-Content-Type-Options":{"empty":false},"Vary":"empty":false},"X-XSS-Protection":"empty":false},"Date":{"empty":false},"Content-Type":"empty":false}},"rawBody":"java.io.ByteArrayInputStream@79ca92b9","statusText":"OK","body":{"array":{},"object":{}},"status":200}

所以我得到了statusText = ok和一个HTTP 200响应,根据Google Docs的说法,这意味着它非常有用。

我用Java录制。以下是参数:

  • 采样率是16000,我尝试了41000但是没有工作
  • Bit / s 16
  • 频道1
  • 有符号整数
  • little endian

我不知道如何从Google获得答案

谢谢

0 个答案:

没有答案