簡體   English   中英

我可以使用 curl 來使用 Google Cloud Storage 中的 .json 進行語音:識別(Google Cloud Speech-to-text)請求嗎?

[英]Can I use curl to make a speech:recognize (Google Cloud Speech-to-text) request using a .json from Google Cloud Storage?

我希望能夠發表演講:使用我自己的雲托管資源識別請求,因此我可以簡單地登錄 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"
  }
}

這是谷歌雲存儲中托管的 .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"
  }
}

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對象。 您必須將它們包括在請求中,因此構建請求的程序需要了解它們。

您可以使用以下代碼找到您的 API 密鑰,但您必須使用此鏈接https://cloud.google.com/sdk/docs/install#linux安裝 gcloud

gcloud auth application-default print-access-token
curl -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json; charset=utf-8" --data "{
  'input':{
    'text':'I\'ve added the event to your calendar.'
  },
  'voice':{
    'languageCode':'en-gb',
    'name':'en-GB-Standard-A',
    'ssmlGender':'FEMALE'
  },
  'audioConfig':{
    'audioEncoding':'MP3'
  }
}" "https://texttospeech.googleapis.com/v1/text:synthesize"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM