{
  "openapi": "3.1.0",
  "info": {
    "title": "TTS API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.cometapi.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/kling/v1/audio/tts": {
      "post": {
        "summary": "TTS",
        "operationId": "tts",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": false,
            "description": "Content type of the request body.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text",
                  "voice_id",
                  "voice_language"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "Text to synthesize into speech. Max 1000 characters."
                  },
                  "voice_id": {
                    "type": "string",
                    "description": "Voice preset ID. Determines the speaker voice used for synthesis. See the Kling documentation for available voice IDs and their supported languages."
                  },
                  "voice_language": {
                    "type": "string",
                    "description": "Language of the selected voice. Must match the language supported by the chosen `voice_id`. Values: `zh` (Chinese) or `en` (English)."
                  },
                  "voice_speed": {
                    "type": "number",
                    "description": "Speech rate multiplier. Range 0.8–2.0 (one decimal place). Values outside this range are clamped automatically."
                  }
                },
                "default": {
                  "text": "Welcome to CometAPI!",
                  "voice_id": "genshin_vindi2",
                  "voice_language": "zh"
                }
              },
              "examples": {
                "Example 1": {
                  "summary": "Example 1",
                  "value": {
                    "text": "Welcome to CometAPI!",
                    "voice_id": "genshin_vindi2",
                    "voice_language": "zh",
                    "voice_speed": 1.2
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "message",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "type": "integer",
                      "description": "Response code. `0` means the task request was accepted."
                    },
                    "message": {
                      "type": "string",
                      "description": "Response message."
                    },
                    "request_id": {
                      "type": "string",
                      "description": "Request identifier returned by CometAPI when present."
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "task_id",
                        "task_status",
                        "created_at",
                        "updated_at"
                      ],
                      "properties": {
                        "task_id": {
                          "type": "string",
                          "description": "Task ID generated by the system."
                        },
                        "task_status": {
                          "type": "string",
                          "description": "Task status.",
                          "enum": [
                            "submitted",
                            "processing",
                            "succeed",
                            "failed"
                          ]
                        },
                        "task_info": {
                          "type": "object",
                          "additionalProperties": true
                        },
                        "task_status_msg": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "created_at": {
                          "type": "integer",
                          "description": "Task creation time as a Unix timestamp in milliseconds."
                        },
                        "updated_at": {
                          "type": "integer",
                          "description": "Task update time as a Unix timestamp in milliseconds."
                        }
                      },
                      "additionalProperties": true
                    }
                  },
                  "additionalProperties": true,
                  "example": {
                    "code": 0,
                    "message": "SUCCEED",
                    "data": {
                      "task_id": "<task_id>",
                      "task_status": "submitted",
                      "task_info": {},
                      "task_status_msg": null,
                      "created_at": 1773366840306,
                      "updated_at": 1773366840306
                    }
                  }
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Default",
            "source": "curl https://api.cometapi.com/kling/v1/audio/tts \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n      \"text\": \"Welcome to CometAPI!\",\n      \"voice_id\": \"genshin_vindi2\",\n      \"voice_language\": \"zh\",\n      \"voice_speed\": 1.2\n    }'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/kling/v1/audio/tts\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n            \"text\": \"Welcome to CometAPI!\",\n            \"voice_id\": \"genshin_vindi2\",\n            \"voice_language\": \"zh\",\n            \"voice_speed\": 1.2\n    },\n)\n\nresult = response.json()\nprint(result[\"code\"], result.get(\"data\", {}).get(\"task_id\"))  # the route responds with the result payload directly\n"
          },
          {
            "lang": "JavaScript",
            "label": "Default",
            "source": "const response = await fetch(\"https://api.cometapi.com/kling/v1/audio/tts\", {\n    method: \"POST\",\n    headers: {\n        Authorization: `Bearer ${process.env.COMETAPI_KEY}`,\n        \"Content-Type\": \"application/json\",\n    },\n    body: JSON.stringify({\n            \"text\": \"Welcome to CometAPI!\",\n            \"voice_id\": \"genshin_vindi2\",\n            \"voice_language\": \"zh\",\n            \"voice_speed\": 1.2\n        }),\n});\n\nconst result = await response.json();\nconsole.log(result.code, result.data?.task_id); // the route responds with the result payload directly\n"
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token authentication. Use your CometAPI key."
      }
    }
  }
}