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

# Audio

> Text-to-speech synthesis, speech-to-text transcription, and listing available voices.

## Text to speech

`audio.synthesize` returns raw audio bytes.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from meshapi import MeshAPI, SpeechParams

    client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")

    audio_bytes = client.audio.synthesize(
        SpeechParams(
            input="Hello from MeshAPI audio test.",
            model="sarvam/bulbul:v2",
        )
    )

    # audio_bytes is a bytes object
    with open("output.wav", "wb") as f:
        f.write(audio_bytes)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const audio = await client.audio.synthesize({
      input: "Hello from MeshAPI audio test.",
      model: "sarvam/bulbul:v2",
    });

    // audio is a Uint8Array
    import { writeFileSync } from "fs";
    writeFileSync("output.wav", audio);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    model := "sarvam/bulbul:v2"

    audioBytes, err := client.Audio.Synthesize(ctx, meshapi.SpeechParams{
        Input: "Hello from MeshAPI audio test.",
        Model: &model,
    })
    if err != nil {
        log.Fatal(err)
    }

    os.WriteFile("output.wav", audioBytes, 0644)
    ```
  </Tab>
</Tabs>

## Speech to text

`audio.transcribe` accepts raw audio bytes plus a filename hint for format detection.

<Info>
  **Argument order differs by language:**

  * Python: `transcribe(bytes, TranscriptionParams, filename=)`
  * Node.js: `transcribe(audio, { model }, { filename })`
  * Go: `Transcribe(ctx, bytes, filename, TranscriptionParams)`
</Info>

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from meshapi import MeshAPI, SpeechParams, TranscriptionParams

    # Generate audio first, then transcribe it
    audio_bytes = client.audio.synthesize(
        SpeechParams(input="Hello from MeshAPI.", model="sarvam/bulbul:v2")
    )

    result = client.audio.transcribe(
        audio_bytes,
        TranscriptionParams(model="sarvam/saaras:v3"),
        filename="tts_output.wav",
    )

    print(result.text)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const audio = await client.audio.synthesize({
      input: "Hello from MeshAPI.",
      model: "sarvam/bulbul:v2",
    });

    const result = await client.audio.transcribe(
      audio,
      { model: "sarvam/saaras:v3" },
      { filename: "tts_output.wav" },
    );

    console.log(result.text);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    model := "sarvam/bulbul:v2"
    audioBytes, _ := client.Audio.Synthesize(ctx, meshapi.SpeechParams{
        Input: "Hello from MeshAPI.",
        Model: &model,
    })

    result, err := client.Audio.Transcribe(ctx, audioBytes, "tts_output.wav", meshapi.TranscriptionParams{
        Model: "sarvam/saaras:v3",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(result.Text)
    ```
  </Tab>
</Tabs>

## Translate audio to English

`POST /v1/audio/translations` transcribes audio in any language and returns the text **translated to English**. It returns the same `TranscriptionResponse` (with a `.text` field) as transcription.

<Info>
  This is a distinct endpoint from the transcribe-and-translate helper (`POST /v1/audio/transcriptions/translate`). Use a speech model that supports translation — see the [Models](/sdk/models) list. `model` is required.
</Info>

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from meshapi import MeshAPI, AudioTranslationsParams

    client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")

    with open("french_audio.mp3", "rb") as f:
        audio_bytes = f.read()

    result = client.audio.audio_translate(
        audio_bytes,
        AudioTranslationsParams(model="openai/whisper-large-v3"),
        filename="french_audio.mp3",
    )

    print(result.text)  # English translation
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import { readFileSync } from "fs";

    const audio = readFileSync("french_audio.mp3");

    const result = await client.audio.translations(
      audio,
      { model: "openai/whisper-large-v3" },
      { filename: "french_audio.mp3" },
    );

    console.log(result.text); // English translation
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    audioBytes, _ := os.ReadFile("french_audio.mp3")

    result, err := client.Audio.Translations(ctx, audioBytes, "french_audio.mp3", meshapi.AudioTranslationParams{
        Model: "openai/whisper-large-v3",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(result.Text) // English translation
    ```
  </Tab>
</Tabs>

Optional parameters: `prompt` (context hint), `response_format` (`json`, `text`, or `verbose_json`), and `temperature` (0–2).

## List voices

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from meshapi import MeshAPI, ListVoicesParams

    voices = client.audio.list_voices(ListVoicesParams(page_size=5))
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const voices = await client.audio.listVoices({ page_size: 5 });
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    pageSize := 5
    voices, err := client.Audio.ListVoices(ctx, &meshapi.ListVoicesParams{
        PageSize: &pageSize,
    })
    ```
  </Tab>
</Tabs>

### `ListVoicesParams` fields

| Field             | Type    | Notes                                        |
| ----------------- | ------- | -------------------------------------------- |
| `page_size`       | integer | Results per page                             |
| `next_page_token` | string  | Pagination cursor from the previous response |
| `search`          | string  | Filter by name                               |
| `voice_type`      | string  | `standard`, `cloned`, and so on              |
| `category`        | string  | Voice category filter                        |

## Get a voice

Fetch a single voice by ID — `GET /v1/audio/voices/{voice_id}`.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    voice = client.audio.get_voice("voice-id")
    print(voice)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const voice = await client.audio.getVoice("voice-id");
    console.log(voice);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    voice, err := client.Audio.GetVoice(ctx, "voice-id")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(voice)
    ```
  </Tab>
</Tabs>

## Parameter reference

### `SpeechParams` (text to speech)

| Field             | Type   | Notes                                        |
| ----------------- | ------ | -------------------------------------------- |
| `input`           | string | **Required.** Text to synthesize.            |
| `model`           | string | **Required.** e.g. `sarvam/bulbul:v3`        |
| `voice`           | string | Voice ID or name                             |
| `response_format` | string | Audio format, e.g. `wav`, `mp3`, `pcm_24000` |
| `speed`           | number | Playback speed multiplier                    |

### `AudioTranslationsParams` (translate to English)

| Field             | Type   | Notes                                   |
| ----------------- | ------ | --------------------------------------- |
| `model`           | string | **Required.** Translation-capable model |
| `prompt`          | string | Context hint for the model              |
| `response_format` | string | `json`, `text`, or `verbose_json`       |
| `temperature`     | number | 0–2                                     |
