> ## 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"]` and specifying a voice and format in the `audio` parameter. The response includes both the text transcript and base64-encoded audio data.

### Audio configuration

| Parameter | Options                               | Default |
| --------- | ------------------------------------- | ------- |
| `voice`   | `alloy` and other voice profiles      | `alloy` |
| `format`  | `wav`, `mp3`, `flac`, `opus`, `pcm16` | `wav`   |

Audio is synthesized at 24 kHz, 16-bit mono.

<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'],
      audio: { voice: 'alloy', format: 'wav' },
    },
  });

  // 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'],
    audio: { voice: 'alloy', format: 'wav' },
    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"],
      audio={"voice": "alloy", "format": "wav"},
  )

  # 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,
      },
      Audio = new Audio()
      {
          Voice = "alloy",
          Format = ResponsesCreateRequestFormat.Wav,
      },
  });

  // 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"],
      "audio": { "voice": "alloy", "format": "wav" }
    }'
  ```

  ```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"],
      "audio": { "voice": "alloy", "format": "wav" }
    }'
  ```
</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": "Hi there!",
      "status": "completed"
    }
  ]
}
```

The `data` field contains the full audio file (268 KB in this example). The `transcript` field contains the text the model chose to speak — which may differ slightly from the text output.

### 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'],
      audio: { voice: 'alloy', format: 'mp3' },
    },
  }) 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.mp3', 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'],
    audio: { voice: 'alloy', format: 'mp3' },
    stream: false,
  } });

  const audioItem = response.output.find((item) => item.type === 'output_audio');
  if (audioItem?.data) {
    const audioBuffer = Buffer.from(audioItem.data, 'base64');
    writeFileSync('output.mp3', 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"],
      audio={"voice": "alloy", "format": "mp3"},
  )

  # 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.mp3", "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,
      },
      Audio = new Audio()
      {
          Voice = "alloy",
          Format = ResponsesCreateRequestFormat.Mp3,
      },
  });

  // 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"],
      "audio": { "voice": "alloy", "format": "mp3" }
    }' \
    --output-format json \
    --jq '.output[] | select(.type == "output_audio") | .data' | base64 -d > output.mp3
  ```

  ```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"],
      "audio": { "voice": "alloy", "format": "mp3" }
    }' | jq -r '.output[] | select(.type == "output_audio") | .data' | base64 -d > output.mp3
  ```
</CodeGroup>

### Supported languages

Audio output supports automatic language detection and 20+ languages including English, Chinese, Hindi, Spanish, Arabic, Bengali, Portuguese, Russian, Japanese, Punjabi, German, Korean, French, Turkish, Italian, Thai, Polish, Dutch, Indonesian, Vietnamese, and Urdu.

For dedicated speech synthesis, see [Text to speech](/docs/text-to-speech).
