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

# Audio responses

> Generate spoken output alongside a Responses API reply.

Use this guide for spoken output from a [Response](/docs/responses). To synthesize supplied text directly, see [Text to speech](/docs/text-to-speech).

The OpenAI examples use its custom-request method for MKA1 extensions that are not part of the OpenAI Responses types.

## Generate audio (text-to-speech)

Request audio output by setting `modalities` to `["text", "audio"]`. The response includes the text reply and a base64-encoded recording of it.

### Audio configuration

Audio output is always a WAV file: 24 kHz, 16-bit mono. The voice follows the language of the reply, which the API detects from the text (see [Supported languages](#supported-languages)). The request's `audio` object (`voice` and `format`) is accepted but has no effect, so the examples omit it.

<CodeGroup>
  ```ts TypeScript SDK theme={null}
  import { SDK } from '@meetkai/mka1';
  import { writeFileSync } from 'fs';
  import type { ResponseObject } from '@meetkai/mka1/models/components';

  const sdk = new SDK({ bearerAuth: 'Bearer <mka1-api-key>' });

  const result = await sdk.llm.responses.create({
    xOnBehalfOf: '<end-user-id>', // optional — attribute the request to one of your end users
    responsesCreateRequest: {
      model: 'auto',
      input: 'Say hello in a friendly way. Keep it very short.',
      modalities: ['text', 'audio'],
    },
  });

  // The output includes an output_audio item with base64 data and a transcript
  ```

  ```ts OpenAI SDK theme={null}
  import OpenAI from 'openai';
  import { writeFileSync } from 'fs';

  const openai = new OpenAI({
    apiKey: '<mka1-api-key>',
    baseURL: 'https://apigw.mka1.com/api/v1/llm/',
    defaultHeaders: { 'X-On-Behalf-Of': '<end-user-id>' },
  });

  const response = await openai.post<{ output: Array<{ type: string; data?: string; transcript?: string }> }>('/responses', { body: {
    model: 'auto',
    input: 'Say hello in a friendly way. Keep it very short.',
    modalities: ['text', 'audio'],
    stream: false,
  } });

  // Find the audio output
  const audioItem = response.output.find((item) => item.type === 'output_audio');
  // audioItem.data contains base64-encoded WAV
  // audioItem.transcript contains the spoken text
  ```

  ```python Python SDK theme={null}
  from meetkai_mka1 import SDK
  import base64

  sdk = SDK(bearer_auth="Bearer <mka1-api-key>")

  result = sdk.llm.responses.create(
      model="auto",
      input="Say hello in a friendly way. Keep it very short.",
      modalities=["text", "audio"],
  )

  # The output includes an output_audio item with base64 data and a transcript
  ```

  ```csharp C# SDK theme={null}
  using MeetKai.MKA1;
  using MeetKai.MKA1.Types.Components;
  using MeetKai.MKA1.Types.Requests;

  var sdk = new SDK(bearerAuth: "Bearer <mka1-api-key>");

  var result = await sdk.Llm.Responses.CreateAsync(new ResponsesCreateRequest()
  {
      Model = "auto",
      Input = ResponsesCreateRequestInput.CreateStr("Say hello in a friendly way. Keep it very short."),
      Modalities = new List<ResponsesCreateRequestModality>
      {
          ResponsesCreateRequestModality.Text,
          ResponsesCreateRequestModality.Audio,
      },
  });

  // The output includes an output_audio item with base64 data and a transcript
  ```

  ```bash CLI theme={null}
  mka1 llm responses create \
    -H 'X-On-Behalf-Of: <end-user-id>' \
    --body '{
      "model": "auto",
      "input": "Say hello in a friendly way. Keep it very short.",
      "modalities": ["text", "audio"]
    }'
  ```

  ```bash Bash theme={null}
  curl https://apigw.mka1.com/api/v1/llm/responses \
    --request POST \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <mka1-api-key>' \
    --header 'X-On-Behalf-Of: <end-user-id>' \
    --data '{
      "model": "auto",
      "input": "Say hello in a friendly way. Keep it very short.",
      "modalities": ["text", "audio"]
    }'
  ```
</CodeGroup>

The response contains an `output_audio` item with the base64-encoded audio and a transcript of what was spoken:

```json theme={null}
{
  "status": "completed",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        { "type": "output_text", "text": "Hello!" }
      ]
    },
    {
      "type": "output_audio",
      "id": "audio_460caf1079b34fa0b4aa74448dff4ea7",
      "data": "<Base64-encoded WAV audio data>",
      "transcript": "Hello!",
      "status": "completed"
    }
  ]
}
```

The `data` field contains the complete WAV file. The `transcript` field contains the text that was spoken, which is the reply's output text. If speech synthesis fails, the response still completes, without an `output_audio` item.

### Save audio to a file

<CodeGroup>
  ```ts TypeScript SDK theme={null}
  const result = await sdk.llm.responses.create({
    responsesCreateRequest: {
      model: 'auto',
      input: 'Read this sentence aloud: The quick brown fox jumps over the lazy dog.',
      modalities: ['text', 'audio'],
    },
  }) as ResponseObject;

  // Find the audio output in the response
  const audioItem = result.output.find((item) => item.type === 'output_audio');
  if (audioItem) {
    const audioBuffer = Buffer.from(audioItem.data, 'base64');
    writeFileSync('output.wav', audioBuffer);
  }
  ```

  ```ts OpenAI SDK theme={null}
  const response = await openai.post<{ output: Array<{ type: string; data?: string; transcript?: string }> }>('/responses', { body: {
    model: 'auto',
    input: 'Read this sentence aloud: The quick brown fox jumps over the lazy dog.',
    modalities: ['text', 'audio'],
    stream: false,
  } });

  const audioItem = response.output.find((item) => item.type === 'output_audio');
  if (audioItem?.data) {
    const audioBuffer = Buffer.from(audioItem.data, 'base64');
    writeFileSync('output.wav', audioBuffer);
  }
  ```

  ```python Python SDK theme={null}
  result = sdk.llm.responses.create(
      model="auto",
      input="Read this sentence aloud: The quick brown fox jumps over the lazy dog.",
      modalities=["text", "audio"],
  )

  # Find the audio output in the response
  for item in result.output:
      if item.type == "output_audio":
          audio_bytes = base64.b64decode(item.data)
          with open("output.wav", "wb") as f:
              f.write(audio_bytes)
  ```

  ```csharp C# SDK theme={null}
  var result = await sdk.Llm.Responses.CreateAsync(new ResponsesCreateRequest()
  {
      Model = "auto",
      Input = ResponsesCreateRequestInput.CreateStr(
          "Read this sentence aloud: The quick brown fox jumps over the lazy dog."),
      Modalities = new List<ResponsesCreateRequestModality>
      {
          ResponsesCreateRequestModality.Text,
          ResponsesCreateRequestModality.Audio,
      },
  });

  // Save the audio output to a file
  // (iterate result.Output to find the output_audio item and decode its base64 data)
  ```

  ```bash CLI theme={null}
  # Generate audio and extract the base64 data, then decode to a file
  mka1 llm responses create \
    --body '{
      "model": "auto",
      "input": "Read this sentence aloud: The quick brown fox jumps over the lazy dog.",
      "modalities": ["text", "audio"]
    }' \
    --output-format json \
    --jq '.output[] | select(.type == "output_audio") | .data' | base64 -d > output.wav
  ```

  ```bash Bash theme={null}
  # Generate audio and extract the base64 data, then decode to a file
  curl -s https://apigw.mka1.com/api/v1/llm/responses \
    --request POST \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <mka1-api-key>' \
    --data '{
      "model": "auto",
      "input": "Read this sentence aloud: The quick brown fox jumps over the lazy dog.",
      "modalities": ["text", "audio"]
    }' | jq -r '.output[] | select(.type == "output_audio") | .data' | base64 -d > output.wav
  ```
</CodeGroup>

### Supported languages

Audio responses speak the languages listed in [Text to speech](/docs/text-to-speech#supported-languages). A reply in any other language is spoken with the English voice.

To choose the language yourself, or to get MP3 instead of WAV, send the reply text to [Text to speech](/docs/text-to-speech).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.