【问题标题】:INVALID_ARGUMENT error by Google speech APIGoogle 语音 API 的 INVALID_ARGUMENT 错误
【发布时间】:2017-05-29 02:43:55
【问题描述】:

我想使用 Google Speech API 的异步转录服务。我已将我的音频文件上传到 Google 存储桶中,并尝试将其与以下代码一起使用(我已从命令中删除了我的密钥和文件名,其他所有内容均已复制)。

curl -H "Content-Type: application/json" 
    --data '{"audio":{"uri":"https://storage.cloud.google.com/<mybucketname>/<filename>"},
    "config":{"encoding":"FLAC","sample_rate_hertz":"16000","language_code":"en_US"}}' 
    https://speech.googleapis.com/v1/speech:longrunningrecognize?key=<mykey>

我收到 400 INVALID_ARGUMENT 错误,告诉我“请求包含无效参数”。我在 curl 请求中做错了什么?

【问题讨论】:

    标签: json curl google-speech-api


    【解决方案1】:

    显然问题出在我的 URI 中。 Google 有一种特殊的方式来引用 Google 存储桶中的项目,以“gs:”作为前缀。

    curl -H "Content-Type: application/json" 
        --data '{"audio":{"uri":"gs://<mybucketname>/<filename>"},
        "config":{"encoding":"FLAC","sample_rate_hertz":"16000","language_code":"en_US"}}' 
        https://speech.googleapis.com/v1/speech:longrunningrecognize?key=<mykey>
    

    请注意,在切换到此方法后,我遇到了无法克服的权限错误,但我认为这与我发出 curl 请求的方式不再相关。

    【讨论】:

      【解决方案2】:

      后面应该加双引号吗?

      【讨论】:

      • 哦,这是我在这里复制命令时打错了。在问题中修复它。谢谢。
      【解决方案3】:

      检查 sample_rate_Hertz。您可能会发现这是 SYNCHRONOUS 请求的格式。

      ASYNCHRONOUS 是 sampleRateHertz。

      我刚刚开始工作,所以如果你需要,趁我还记忆犹新的时候恢复!

      【讨论】:

      • 你能发布这个的来源吗?试一试会得到 ValueError: Protocol message RecognitionConfig has no "sampleRateHertz" 字段。谢谢!
      【解决方案4】:

      我使用 Node JS 客户端和谷歌存储来存储文件。

          // The audio file's encoding, sample rate in Hertz, and BCP-47 language code
          const audio = {
              uri: 'gs://sst_bbc/',
          };
          const config = {
              enableWordTimeOffsets: true,
              encoding: 'FLAC',
              // sampleRateHertz: 16000,
              languageCode: 'en-US',
          };
          const request = {
              audio: audio,
              config: config,
          };
      
          // Detects speech in the audio file
          const [operation] = await client.longRunningRecognize(request);
          const [response] = await operation.promise();
      
          fs.writeFileSync('ted_talk.json', JSON.stringify(response), 'utf8');
      

      我犯了一个错误,没有提到确切的对象。控制台中的错误非常模棱两可。在我设置正确的路径后,它开始正常工作。

          const audio = {
              uri: 'gs://sst_bbc/ted_talk.flac',
          };
      

      如果文件位置正确,请仔细检查编码类型。I

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-11
        • 2020-01-06
        相关资源
        最近更新 更多