【问题标题】:Google Cloud Text-to-Speech returns "INVALID_ARGUMENT"Google Cloud Text-to-Speech 返回“INVALID_ARGUMENT”
【发布时间】:2019-03-21 22:30:32
【问题描述】:

我正在尝试使用 REST 的 Google Cloud 文本转语音。 使用Google's API explorer 时效果很好。

但是当我尝试进行 post 调用时,它返回以下错误(我使用的 API 密钥没有限制):

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"{\r\n \"audioConfig\": {\r\n  \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n  \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n  \"languageCode\": \"en-US\",\r\n  \"name\": \"en-US-Standard-B\"\r\n }\r\n}\": Cannot bind query parameter. Field '{\r\n \"audioConfig\": {\r\n  \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n  \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n  \"languageCode\": \"en-US\",\r\n  \"name\": \"en-US-Standard-B\"\r\n }\r\n}' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"{\r\n \"audioConfig\": {\r\n  \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n  \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n  \"languageCode\": \"en-US\",\r\n  \"name\": \"en-US-Standard-B\"\r\n }\r\n}\": Cannot bind query parameter. Field '{\r\n \"audioConfig\": {\r\n  \"audioEncoding\": \"MP3\"\r\n },\r\n \"input\": {\r\n  \"text\": \"This is a text to speak\"\r\n },\r\n \"voice\": {\r\n  \"languageCode\": \"en-US\",\r\n  \"name\": \"en-US-Standard-B\"\r\n }\r\n}' could not be found in request message."
          }
        ]
      }
    ]
  }
}

请求正文:

{
 "audioConfig": {
  "audioEncoding": "MP3"
 },
 "input": {
  "text": "This is a text to speak"
 },
 "voice": {
  "languageCode": "en-US",
  "name": "en-US-Standard-B"
 }
}

发布链接:https://texttospeech.googleapis.com/v1beta1/text:synthesize?fields=audioContent&key={MY_API_KEY}

【问题讨论】:

    标签: json rest api google-cloud-platform google-text-to-speech


    【解决方案1】:

    基于此Text-to-Speech Quickstart

    我成功完成了以下 POST 请求:

    curl -X POST \
      -H "Content-Type: application/json; charset=utf-8" \
      --data "{
        'input':{
          'text':'This is a text to speak'
        },
        'voice':{
          'languageCode':'en-US',
          'name':'en-US-Standard-B'
        },
        'audioConfig':{
          'audioEncoding':'MP3'
        }
      }" "https://texttospeech.googleapis.com/v1/text:synthesize?key=MY_KEY" > synthesize-text.txt
    

    希望对你有帮助。

    【讨论】:

    • 我在设置标题时出错。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    相关资源
    最近更新 更多