调用语言转换器API时出现JSON错误

wlp8pajw  于 2023-07-01  发布在  其他
关注(0)|答案(1)|浏览(99)

我在PowerApps中有一个自定义连接器,它使用语言翻译器API,
下面是我在连接器中发送的请求。

{
"pipelineTasks": [
    {
        "taskType": "asr",
        "config": {
            "language": {
                "sourceLanguage": "hi"
            },
            "serviceId": "",
            "audioFormat": "flac",
            "samplingRate": 8000
        }
    },
    {
        "taskType": "translation",
        "config": {
            "language": {
                "sourceLanguage": "hi",
                "targetLanguage": "en"
            },
            "serviceId": ""
        }
    },
    {
        "taskType": "tts",
        "config": {
            "language": {
                "sourceLanguage": "en"
            },
            "serviceId": "",
            "gender": "female",
            "samplingRate": 8000
        }
    }
],
"inputData": {
    "audio": [
        {
            "audioContent": //base64 string           }
    ]
}

}
这是我在连接器中收到的输出,正如预期的那样。请注意,响应中的输出对象是一个数组。

{
 "pipelineResponse": [
   {
     "taskType": "asr",
     "config": {
       "serviceId": "",
       "language": {
         "sourceLanguage": "hi",
         "sourceScriptCode": ""
       },
       "audioFormat": "flac",
       "encoding": null,
       "samplingRate": 8000,
       "postProcessors": null
     },
     "output": [
       {
         "source": "मेरा नाम महीर है और मैं भाषा वर्ष यूज़ कर रहा हूँ"
       }
     ],
     "audio": null
   },
   {
     "taskType": "translation",
     "config": null,
     "output": [
       {
         "source": "मेरा नाम महीर है और मैं भाषा वर्ष यूज़ कर रहा हूँ",
         "target": "My name is Maher and I'm using the language Year"
       }
     ],
     "audio": null
   },
   {
     "taskType": "tts",
     "config": {
       "language": {
         "sourceLanguage": "en",
         "sourceScriptCode": ""
       },
       "audioFormat": "wav",
       "encoding": "base64",
       "samplingRate": 8000,
       "postProcessors": null
     },
     "output": null,
     "audio": [
       {
         "audioContent": //base64 ,

        "audioUri": null
       }
     ]
   }
 ]
}

但是,当我尝试在PowerApps中调用自定义连接器时,我最终会出现错误。
“JSON分析错误,需要'string',但得到'array'。”请参考下面的图像..

有人能帮帮忙吗?我不知道哪里出了问题。
我还添加了swagger的定义。

swagger: '2.0'
info:
  title: ASR_NMT_TTS
  description: ''
  version: '1.0'
host: xxx.co.in
basePath: /
schemes:
  - https
consumes: []
produces: []
paths:
  /services/inference/pipeline:
    post:
      responses:
        default:
          description: default
          schema:
            type: object
            properties:
              pipelineResponse:
                type: array
                items:
                  type: object
                  properties:
                    taskType:
                      type: string
                      description: taskType
                    config:
                      type: object
                      properties:
                        language:
                          type: object
                          properties:
                            sourceLanguage:
                              type: string
                              description: sourceLanguage
                            sourceScriptCode:
                              type: string
                              description: sourceScriptCode
                          description: language
                        audioFormat:
                          type: string
                          description: audioFormat
                        encoding:
                          type: string
                          description: encoding
                        samplingRate:
                          type: integer
                          format: int32
                          description: samplingRate
                        postProcessors:
                          type: string
                          description: postProcessors
                      description: config
                    output:
                      type: string
                      description: output
                    audio:
                      type: array
                      items:
                        type: object
                        properties:
                          audioContent:
                            type: string
                            description: audioContent
                          audioUri:
                            type: string
                            description: audioUri
                      description: audio
                description: pipelineResponse
      summary: ASR_NMT_TTS
      description: ASR_NMT_TTS
      operationId: Pipeline
      parameters:
        - name: Content-Type
          in: header
          required: false
          type: string
        - name: body
          in: body
          required: false
          schema:
            type: object
            properties:
              pipelineTasks:
                type: array
                items:
                  type: object
                  properties:
                    taskType:
                      type: string
                      description: taskType
                    config:
                      type: object
                      properties:
                        language:
                          type: object
                          properties:
                            sourceLanguage:
                              type: string
                              description: sourceLanguage
                            targetLanguage:
                              type: string
                              description: targetLanguage
                          description: language
                        serviceId:
                          type: string
                          description: serviceId
                        audioFormat:
                          type: string
                          description: audioFormat
                        samplingRate:
                          type: integer
                          format: int32
                          description: samplingRate
                        gender:
                          type: string
                          description: gender
                      description: config
                description: pipelineTasks
              inputData:
                type: object
                properties:
                  audio:
                    type: array
                    items:
                      type: object
                      properties:
                        audioContent:
                          type: string
                          description: audioContent
                    description: audio
                description: inputData
definitions: {}
parameters: {}
responses: {}
securityDefinitions:
  API Key:
    type: apiKey
    in: header
    name: Authorization
security:
  - API Key: []
tags: []
inkz8wg9

inkz8wg91#

您的连接器swagger指定'pipelineResponse'数组的'output'字段的类型为'string':

pipelineResponse:
    type: array
    items:
      type: object
      properties:
        taskType:
          type: string
          description: taskType
        config:
          type: object
          ...
        output:
          type: string
          description: output
        audio:
          type: array
          ...
    description: pipelineResponse

但是在你的响应中,你实际上有一个'array',它有两个属性:

"output": [
   {
     "source": "मेरा नाम महीर है और मैं भाषा वर्ष यूज़ कर रहा हूँ",
     "target": "My name is Maher and I'm using the language Year"
   }
 ],

您应该更新swagger以正确地输入输出字段,或者更新连接器的响应以匹配swagger指定的预期。

相关问题