【发布时间】:2022-01-17 14:09:29
【问题描述】:
我想翻译多个 .pptx 文件。我正在尝试使用Google translate API
我的请求json文件如下。
{
"source_language_code": "ja",
"target_language_codes": ["en"],
"input_configs": {
"gcsSource": {
"inputUri": "gs://project_name/1.pptx"
},
"gcsSource": {
"inputUri": "gs://project_name/2.pptx"
}
},
"output_config": {
"gcsDestination": {
"outputUriPrefix": "gs://project_name/ja-en/"
}
}
}
我在请求翻译 API 时收到此错误。
"description": "Invalid value at 'input_configs' (oneof), oneof field 'source' is already set. Cannot set 'gcsSource'"
然后我将第二个gcsSource 更改为gcsSource1
{
"source_language_code": "ja",
"target_language_codes": ["en"],
"input_configs": {
"gcsSource": {
"inputUri": "gs://project_name/1.pptx"
},
"gcsSource1": {
"inputUri": "gs://project_name/2.pptx"
}
},
"output_config": {
"gcsDestination": {
"outputUriPrefix": "gs://project_name/ja-en/"
}
}
}
结果如下。
"description": "Invalid JSON payload received. Unknown name \"gcsSource1\" at 'input_configs': Cannot find field."
gcsSource1在the document中被使用了2次
我应该如何更改请求 json 文件,以便通过翻译 API 翻译多个文件?
终点是这个。 "https://translation.googleapis.com/v3/projects/project_name/locations/us-central1:batchTranslateDocument"
注意
单文件翻译工作正常。
{
"source_language_code": "ja",
"target_language_codes": ["en"],
"input_configs": {
"gcsSource": {
"inputUri": "gs://project_name/1.pptx"
},
},
"output_config": {
"gcsDestination": {
"outputUriPrefix": "gs://project_name/ja-en/"
}
}
}
【问题讨论】:
-
您使用的是正确的 API 端点吗?批处理请求的端点与documentation 不同。
-
是的。我的端点是批量请求。 "translation.googleapis.com/v3/projects/project_name/locations/…"
-
您在 input_configs 中使用了花括号,因为在您的情况下它有多个值,所以它是一个方括号,因为它是一个数组。
-
嗨@Nori,我很高兴它成功了,我打算发布与答案相同的内容,如果你能接受/支持它。
-
是的!没关系!我会在你发帖后删除我的答案。