> ## 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.

# 음성 생성

> CometAPI POST /v1/audio/speech를 사용해 선택한 text-to-speech 모델과 출력 형식으로 텍스트를 오디오로 변환합니다.

이 엔드포인트를 사용하면 OpenAI 호환 오디오 API를 통해 텍스트를 오디오 파일로 변환할 수 있습니다. 내레이션, 짧은 음성 프롬프트, 읽어주기 기능, 그리고 앱에 이미 텍스트가 있고 음성 출력을 필요로 하는 기타 워크플로에 적합합니다.

## 첫 번째 요청

`model`, `input`, `voice`의 세 필드로 시작하세요. 속도나 출력 형식을 조정하기 전에 인증, 오디오 형식, 파일 처리를 확인할 수 있도록 첫 번째 요청은 짧게 유지하세요.

## 응답 읽기

응답은 JSON이 아니라 바이너리 오디오입니다. SDK 예제에서는 응답을 `output.mp3` 같은 파일에 기록하세요. 직접 HTTP 클라이언트를 사용하는 경우 응답 본문을 저장하고, 요청한 `response_format`에 맞게 파일 확장자를 설정하세요.

## 다음 단계

* 음성을 다시 텍스트로 변환해야 할 때는 [음성 전사](/api/audio/create-transcription)를 사용하세요.
* 영어가 아닌 오디오에서 영어 텍스트가 필요할 때는 [번역](/api/audio/create-translation)를 사용하세요.


## OpenAPI

````yaml api/openapi/audio/post-create-speech.openapi.json POST /v1/audio/speech
openapi: 3.1.0
info:
  title: Create speech API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /v1/audio/speech:
    post:
      summary: Create speech
      operationId: create_speech
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
                - voice
              properties:
                model:
                  type: string
                  description: >-
                    The TTS model to use. Choose a current speech model from the
                    [Models page](/overview/models).
                  default: tts-1
                input:
                  type: string
                  description: >-
                    The text to generate audio for. Maximum length is 4096
                    characters.
                  maxLength: 4096
                voice:
                  type: string
                  description: The voice to use for speech synthesis.
                  enum:
                    - alloy
                    - ash
                    - ballad
                    - coral
                    - echo
                    - fable
                    - onyx
                    - nova
                    - sage
                    - shimmer
                  default: alloy
                response_format:
                  type: string
                  description: The audio output format.
                  enum:
                    - mp3
                    - opus
                    - aac
                    - flac
                    - wav
                    - pcm
                  default: mp3
                speed:
                  type: number
                  description: >-
                    The speed of the generated audio. Select a value between
                    0.25 and 4.0.
                  minimum: 0.25
                  maximum: 4
                  default: 1
            examples:
              Default:
                summary: Standard TTS (tts-1)
                value:
                  model: tts-1
                  input: The quick brown fox jumped over the lazy dog.
                  voice: alloy
              gpt_4o_mini_tts:
                summary: GPT-4o mini TTS (gpt-4o-mini-tts)
                value:
                  model: gpt-4o-mini-tts
                  input: The quick brown fox jumped over the lazy dog.
                  voice: alloy
      responses:
        '200':
          description: The audio file content.
          content:
            audio/mpeg:
              schema:
                type: string
                format: binary
      x-codeSamples:
        - lang: python
          label: Create speech
          source: |-
            import os
            from openai import OpenAI

            client = OpenAI(
                api_key=os.environ["COMETAPI_KEY"],
                base_url="https://api.cometapi.com/v1"
            )

            response = client.audio.speech.create(
                model="tts-1",
                voice="alloy",
                input="The quick brown fox jumped over the lazy dog."
            )

            response.stream_to_file("output.mp3")
        - lang: javascript
          label: Create speech
          source: |-
            import OpenAI from "openai";
            import fs from "fs";

            const client = new OpenAI({
              apiKey: process.env.COMETAPI_KEY,
              baseURL: "https://api.cometapi.com/v1"
            });

            const response = await client.audio.speech.create({
              model: "tts-1",
              voice: "alloy",
              input: "The quick brown fox jumped over the lazy dog."
            });

            const buffer = Buffer.from(await response.arrayBuffer());
            fs.writeFileSync("output.mp3", buffer);
        - lang: shell
          label: Create speech
          source: |-
            curl -X POST https://api.cometapi.com/v1/audio/speech \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "model": "tts-1",
                "input": "The quick brown fox jumped over the lazy dog.",
                "voice": "alloy"
              }' \
              --output output.mp3
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````