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

# Speech

Speech models connect audio and text input/output forms. They support both automatic speech recognition (ASR) and text-to-speech (TTS). Both are called through the standard Chat Completions interface, making them easy to integrate into transcription workflows, voice assistants, and accessibility tools.

Representative models include:

* `bosonai/asr`: Speech-to-text.
* `bosonai/tts`: Text-to-speech.

For the full model list and pricing, refer to [Models](https://console.scitix.ai/model-inference/models).

## Use Cases

* **Transcription**: Convert meetings, calls, lectures, or voice notes into searchable text.
* **Voice assistants**: Combine ASR, an LLM, and TTS to build conversational voice experiences.
* **Subtitles and captions**: Generate captions and subtitles for video and audio content.
* **Accessibility**: Read content aloud, or let users interact by voice instead of typing.

## Usage

Both types of models are called through the `/chat/completions` endpoint and the `messages` array, similar to chat models. The main difference is the input and output content.

* **Text-to-speech (TTS)**: Send the text to be spoken as a normal user message. The generated audio appears in `choices[0].message.audio.data` as base64-encoded WAV. Decode it and write it to a file to play it.
* **Speech-to-text (ASR)**: Send audio as a content part of type `input_audio`, including the base64 data and `format` information such as `wav`. The transcription result is returned as plain text in `choices[0].message.content`.

## Key Parameters

* **TTS**:
  * `model`: `bosonai/tts`.
  * `messages`: The `role` is `user`, and `content` is the text to be spoken.
* **ASR**:
  * `model`: `bosonai/asr`.
  * `messages`: The `role` is `user`, and `content` is an array containing `{"type": "input_audio", "input_audio": {"data": "<base64>", "format": "wav"}}`.

## Notes

* Supported audio formats and maximum file size or duration vary by model. For details, refer to the model details in [Models](https://console.scitix.ai/model-inference/models).
* For long audio, splitting it into shorter segments helps stay within limits and reduces timeout risk.

## Billing

* **Pricing unit**: Speech models are typically billed by audio duration or by the number of characters/tokens processed, depending on the model. Check the model details in [Models](https://console.scitix.ai/model-inference/models) for the exact pricing unit.
* **Recommendation**: For longer recordings, split the audio into multiple segments and process them separately to reduce timeout and retry costs.

## Examples

The examples read the API key from an environment variable to avoid writing secrets into code.

```bash theme={null}
export API_KEY="YOUR_API_KEY"
```

### Text-to-Speech (TTS)

```python theme={null}
import os
import base64
import requests

api_key = os.environ["API_KEY"]
api_url = "https://api.scitix.ai/model-api/chat/completions"

response = requests.post(
    api_url,
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json={
        "model": "bosonai/tts",
        "messages": [
            {"role": "user", "content": "Welcome to the ScitiX Model Inference API."}
        ],
    },
)

audio_b64 = response.json()["choices"][0]["message"]["audio"]["data"]
with open("welcome.wav", "wb") as f:
    f.write(base64.b64decode(audio_b64))
print("Saved welcome.wav")
```

### Speech-to-Text (ASR)

```python theme={null}
import os
import base64
import requests

api_key = os.environ["API_KEY"]
api_url = "https://api.scitix.ai/model-api/chat/completions"

with open("welcome.wav", "rb") as f:
    audio_b64 = base64.b64encode(f.read()).decode()

response = requests.post(
    api_url,
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json={
        "model": "bosonai/asr",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_audio",
                        "input_audio": {"data": audio_b64, "format": "wav"},
                    }
                ],
            }
        ],
    },
)

print(response.json()["choices"][0]["message"]["content"])
```
