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

# Text-to-Speech Stream

> Convert text to speech and stream audio response

Convert text to speech and stream the audio response. This endpoint processes text by replacing code blocks with "Code block" and inline code with "Inline code" before generating speech.

<RequestExample>
  ````bash cURL theme={null}
  curl --request POST \
    --url https://api.gurubase.io/api/v1/{guru_slug}/text-to-speech/stream/ \
    --header 'x-api-key: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
      "text": "Hello, this is a test message with some code: `console.log(\"hello\")` and a code block:\n```python\ndef hello():\n    print(\"hello\")\n```"
    }'
  ````
</RequestExample>

## Path Parameters

<ParamField path="guru_type" type="string" required>
  The guru type identifier for the text-to-speech request
</ParamField>

## Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication. You can obtain your API key from the [Gurubase dashboard](https://app.gurubase.io/api-keys).
</ParamField>

### Body Parameters

<ParamField body="text" type="string" required>
  The text to convert to speech. Code blocks and inline code will be processed and replaced with "Code block" and "Inline code" respectively.
</ParamField>

### Response

The response is a streaming audio file in MP3 format.

<ResponseField name="audio_stream" type="audio/mpeg">
  Streaming audio response in MP3 format
</ResponseField>

<ResponseExample>
  ```json 400 theme={null}
  {
    "msg": "No text provided"
  }
  ```

  ```json 401 theme={null}
  {
    "error": "Invalid API key"
  }
  ```

  ```json 403 theme={null}
  {
    "msg": "Text-to-speech is not enabled for this guru type"
  }
  ```

  ```json 429 theme={null}
  {
    "error": "Rate limit exceeded"
  }
  ```

  ```json 500 theme={null}
  {
    "msg": "Error generating speech stream"
  }
  ```
</ResponseExample>

## Text Processing

The endpoint automatically processes text before converting to speech:

* **Code blocks**: Any text wrapped in triple backticks (\`\`\`) is replaced with "Code block"
* **Inline code**: Any text wrapped in single backticks (\`) is replaced with "Inline code"

This ensures that code syntax doesn't interfere with speech generation and provides a better listening experience.

## Streaming Response

The endpoint returns a streaming audio response with the following headers:

* `Content-Type: audio/mpeg`
* `Cache-Control: no-cache`
* `X-Accel-Buffering: no` (disables nginx buffering for real-time streaming)
