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

# Generate speech

> Generates natural-sounding speech



## OpenAPI

````yaml POST /v1/generate_speech
openapi: 3.1.0
info:
  title: OpenAPI Contextlm
  description: ContextLM API endpoints
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.contextlm.ai
security:
  - ApiKeyAuth: []
paths:
  /v1/generate_speech:
    post:
      description: Generates natural-sounding speech
      requestBody:
        description: Speech synthesis parameters
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateSpeech'
        required: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateSpeechResponse'
        '400':
          description: Bad request. Occurs when parameters are invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateSpeechError'
        '401':
          description: Unauthorized. Occurs when API key is missing
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateSpeechError'
        '403':
          description: >-
            Forbidden. Occurs when API key is valid but user does not have
            permission
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateSpeechError'
        '404':
          description: Not found. Occurs when requested resource does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateSpeechError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateSpeechError'
components:
  schemas:
    GenerateSpeech:
      allOf:
        - required:
            - text
            - voice_id
          type: object
          properties:
            text:
              description: >-
                The text input to be converted to speech. Tags including [pause
                short], [pause] and [long pause] can be added to text to control
                the pause in speech. Only supported in vivid model.
              type: string
              example: Hello, how are you? [pause] I'm fine, thank you.
            voice_id:
              description: The voice id to use in speech synthesis
              type: string
              example: en-US-Phoenix-F-HD
            model_id:
              description: The model id to use in speech synthesis.
              type: string
              default: vivid
              enum:
                - vivid
                - flow
            custom_prompt:
              description: >-
                The custom prompt to use in speech synthesis. Only supported in
                vivid model.
              type: string
            pitch:
              description: >-
                Speaking pitch, in the range [-20.0, 20.0]. 20 means increase 20
                semitones from the original pitch. -20 means decrease 20
                semitones from the original pitch. Pitch is not fully supported
                in vivid model, mixed results may occur.
              type: number
              default: 0
              minimum: -20
              maximum: 20
            speaking_rate:
              description: >-
                Speaking rate/speed, in the range [0.25, 4.0]. 1.0 is the normal
                native speed supported by the specific voice. 2.0 is twice as
                fast, and 0.5 is half as fast. Any other values < 0.25 or > 4.0
                will return an error. Speaking rate is not fully supported in
                vivid model, mixed results may occur.
              type: number
              default: 1
              minimum: 0.25
              maximum: 4
            output_format:
              description: >-
                The format of the audio byte stream. LINEAR16 a.k.a WAV is the
                best for audio quality.
              type: string
              default: LINEAR16
              enum:
                - LINEAR16
                - MP3
                - OGG_OPUS
                - MULAW
    GenerateSpeechResponse:
      type: object
      properties:
        audiobytes:
          type: string
          format: binary
    GenerateSpeechError:
      type: object
      properties:
        error:
          type: integer
          format: int32
        detail:
          type: string
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````