> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# إنشاء صوت من فيديو Kling

> حوّل فيديوهات Kling إلى صوت عالي الجودة عبر نقطة نهاية Video to Audio من CometAPI، مع إمكانية ضبط تنسيق الإخراج والمدة والتحكم عبر Prompt.

استخدم نقطة النهاية هذه لإنشاء ناتج صوتي من فيديو مصدر.

## قبل استدعائها

* أرسل إما `video_id` أو `video_url`، ولكن ليس كليهما
* استخدم `video_url` عندما لا يكون المقطع المصدر قد أتى من Kling في الأصل
* اترك `callback_url` و`external_task_id` كخيارين اختياريين ما لم يكن تكاملك يحتاج إليهما

## تدفق المهمة

<Steps>
  <Step title="إرسال الفيديو المصدر">
    أرسل إما `video_id` الخاص بـ Kling أو `video_url` يمكن الوصول إليه، ثم احفظ معرّف المهمة الذي يتم إرجاعه.
  </Step>

  <Step title="استطلاع المهمة">
    تابع باستخدام [الحصول على مهمة Kling](./individual-queries) عبر مسار استعلام صوت Kling حتى تصل المهمة إلى حالة نهائية.
  </Step>

  <Step title="حفظ المخرجات">
    خزّن الأصل الصوتي النهائي إذا كنت بحاجة إلى احتفاظ ثابت أو معالجة لاحقة.
  </Step>
</Steps>

<Tip>
  للاطلاع على المرجع الكامل للمعلمات، راجع [وثائق Kling الرسمية](https://app.klingai.com/global/dev/document-api/apiReference/model/videoToAudio).
</Tip>


## OpenAPI

````yaml api/openapi/video/kling/post-video-to-audio.openapi.json POST /kling/v1/audio/video-to-audio
openapi: 3.1.0
info:
  title: Video to Audio API
  version: 1.0.0
  description: Create a Kling audio-generation task from a source video.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/audio/video-to-audio:
    post:
      summary: Create a Kling video-to-audio task
      description: >-
        Submit either a Kling `video_id` or an accessible `video_url`, then poll
        the returned task id through the generic Kling query route.
      operationId: video_to_audio
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              oneOf:
                - required:
                    - video_id
                - required:
                    - video_url
              properties:
                external_task_id:
                  type: string
                  description: >-
                    Optional user-defined task ID for your own tracking. Does
                    not replace the system-generated task ID. Must be unique per
                    account.
                callback_url:
                  type: string
                  description: >-
                    Webhook URL for task status notifications. The server sends
                    a callback when the task status changes.
                video_id:
                  type: string
                  description: >-
                    ID of a Kling-generated video. Only videos created within
                    the last 30 days with a duration of 3–20 seconds are
                    supported. Mutually exclusive with `video_url` — exactly one
                    must be provided.
                video_url:
                  type: string
                  description: >-
                    Accessible URL of the source video. Accepted formats: MP4,
                    MOV. Max 100 MB, 720p or 1080p resolution, duration 3–20
                    seconds. Mutually exclusive with `video_id` — exactly one
                    must be provided.
              default:
                video_url: https://your-video-host/source.mp4
            examples:
              Default:
                summary: Default
                value:
                  video_url: https://xxxxx.mp4
      responses:
        '200':
          description: Task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: integer
                    description: |
                      Error code; specific error code definition
                  message:
                    type: string
                    description: |
                      Error message
                  data:
                    type: object
                    required:
                      - task_id
                      - task_status
                      - created_at
                      - updated_at
                    properties:
                      task_id:
                        type: string
                        description: |
                          Task ID, system-generated
                      task_status:
                        type: string
                        description: >
                          Task status, enum values: submitted, processing,
                          succeed, failed
                      created_at:
                        type: integer
                        description: |+
                          Task creation time, Unix timestamp, in ms

                      updated_at:
                        type: integer
                        description: |
                          Task update time, Unix timestamp, in ms
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/kling/v1/audio/video-to-audio \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "video_url": "https://xxxxx.mp4"
                }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/kling/v1/audio/video-to-audio",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                        "video_url": "https://xxxxx.mp4"
                },
            )


            result = response.json()

            print(result["code"], result.get("data", {}).get("task_id"))  # code
            0 means submitted; poll the matching query endpoint until
            task_status is succeed
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/kling/v1/audio/video-to-audio", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                        "video_url": "https://xxxxx.mp4"
                    }),
            });


            const result = await response.json();

            console.log(result.code, result.data?.task_id); // code 0 means
            submitted; poll the matching query endpoint until task_status is
            succeed
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````