我正在尝试使用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}
答案 0 :(得分:0)
我成功执行了以下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
希望有帮助。