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

# AI Voice Assistant

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

## 🎙️ Real-Time AI Voice & Response Generation

Use this API to interact with our AI voice assistant in real time. Simply provide your `userId` and `speech_url` to receive an AI-generated voice response as a streamed audio file.

***

#### **Core Parameters**

> 🛈 The parameters below define the request body for this API.

| Parameter    | Type     | Required?  | Description                          |
| ------------ | -------- | ---------- | ------------------------------------ |
| `speech_url` | `string` | ✅ Required | URL pointing to the input audio file |

***

#### **Request Body**

<div style={{ backgroundColor: "#e9ecef", padding: "0.75rem", borderRadius: "0.3rem" }}>
  ```
  Request body: 
  {
    "speech_url": "https://example.com/your_audio.mp3"
  }
  ```
</div>

#### Code Samples

<Tabs>
  <Tab title="HTML & JS">
    ```python theme={null}

          <input type="text" id="userId" value="user-123">
          <input type="text" id="speechUrl" value="https://example.com/speech.mp3">
          <button id="playButton">Play Voice</button>
          <audio id="audioPlayer" controls></audio>

          <script>
          async function getVoiceAudio() {
              const userId = document.getElementById("userId").value;
              const speechUrl = document.getElementById("speechUrl").value;

              const response = await fetch("https://api.soundverse.ai/v1/assistant/voice", {
              method: "POST",
              headers: {
                  "Content-Type": "application/json",
                  "Authorization": "Bearer your_api_key_here"
              },
              body: JSON.stringify({ speech_url: speechUrl }),
              });

              if (!response.ok || !response.body) {
              throw new Error("Failed to fetch audio");
              }

              const reader = response.body.getReader();
              const chunks = [];

              while (true) {
              const { done, value } = await reader.read();
              if (done) break;
              chunks.push(value);
              }

              const blob = new Blob(chunks, { type: "audio/mpeg" });
              const url = URL.createObjectURL(blob);

              const audio = document.getElementById("audioPlayer");
              audio.src = url;
              audio.play();
          }

          document.getElementById("playButton").addEventListener("click", getVoiceAudio);
          </script>
    ```
  </Tab>

  <Tab title="cURL">
    ```sh theme={null}
      curl -X POST "https://api.soundverse.ai/v1/assistant/voice" \
      -H "Authorization: Bearer your_api_key_here" \
      -H "Content-Type: application/json" \
      -d '{
      "speech_url": "https://example.com/your_audio.mp3"
      }'
    ```
  </Tab>
</Tabs>

#### Response

If the request is valid, you'll receive an audio data in chunks.

#### Response

<Tabs>
  <Tab title="200 OK">
    ```sh theme={null}
    HTTP/1.1 200 OK
    Content-Type: audio/mpeg

    ```
  </Tab>

  <Tab title="400 Bad Request">
    ```sh theme={null}
      {
        "success": false,
        "message": "Invalid request body"
      }
    ```
  </Tab>
</Tabs>

#### Possible Errors :

* Internal Server Error -
  `500 status code `
