我可以使用curl来使用Google Cloud Storage中的.json发出语音:识别(Google Cloud语音到文本)请求吗?

时间:2019-02-28 17:52:11

标签: google-cloud-platform google-speech-api

我希望能够发表演讲:通过自己的云端托管资源来识别请求,因此我可以简单地登录Google Cloud Platform控制台,在Cloud Shell中运行命令,然后查看结果。类似于https://cloud.google.com/speech-to-text/docs/quickstart-protocol,但不使用本地任何内容。

不确定要共享哪些其他重要信息,但是我云中的.json和.flac文件具有公共读取权限。

我该如何实现?

我的请求

curl -H "Content-Type: application/json" https://speech.googleapis.com/v1/speech:recognize?key=[my-api-key] -d @https://storage.googleapis.com/[bucket]/[json-request-filename].json

响应:

Warning: Couldn't read data from file
Warning: "https://storage.googleapis.com/[bucket]/[json-request-filename].json",
Warning: this makes an empty POST.
{
  "error": {
    "code": 400,
    "message": "RecognitionAudio not set.",
    "status": "INVALID_ARGUMENT"
  }
}

这是托管在Google云存储中的.json:

{
  "config": {
      "encoding":"FLAC",
      "sampleRateHertz": 16000,
      "languageCode": "en-US",
      "enableWordTimeOffsets": false
  },
  "audio": {
      "uri":"gs://[bucket]/[audio-filename].flac"
  }
}

没有新信息,但这是Google Cloud Platform Shell的外观:

[my-account]@cloudshell:~ ([my-project])$ curl -H "Content-Type: application/json" https://speech.googleapis.com/v1/speech:recognize?key=[my-api-key] -d @https://storage.googleapis.com/[bucket]/[json-request-filename].json
Warning: Couldn't read data from file
Warning: "https://storage.googleapis.com/[bucket]/[json-request-filename].json",
Warning: this makes an empty POST.
{
  "error": {
    "code": 400,
    "message": "RecognitionAudio not set.",
    "status": "INVALID_ARGUMENT"
  }
}

1 个答案:

答案 0 :(得分:0)

curl命令中的-d标志告诉curl在文件名后立即读取数据,并将该数据用作请求的正文。 curl无法将网络URL识别为有效文件。 curl无法读取该JSON文件,因此它的行为就好像是一个空文件一样,并使用一个空的主体构建一个请求。发送到API的请求没有有关该JSON文件的任何信息。

语音API接收到的请求正文为空,因此无法执行任何操作。该API甚至都不知道您在curl命令中指定了Google Cloud对象。

语音:识别方法记录在https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/speech/recognize中。除了从请求主体中之外,它没有任何方法来获取所需的参数。您无法告诉它从其他地方读取这些参数,例如URL或Google Cloud对象。您必须将它们包括在请求中,因此构建请求的程序需要知道它们。