|
| 1 | +--- |
| 2 | +title: "Together AI" |
| 3 | +description: "Text-to-speech service using Together AI's real-time WebSocket API" |
| 4 | +--- |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +`TogetherTTSService` provides real-time text-to-speech using Together AI's WebSocket API. It supports streaming synthesis with configurable voice and model options, interruption handling, and automatic reconnection. |
| 9 | + |
| 10 | +<CardGroup cols={2}> |
| 11 | + <Card |
| 12 | + title="Together AI TTS API Reference" |
| 13 | + icon="code" |
| 14 | + href="https://reference-server.pipecat.ai/en/latest/api/pipecat.services.together.tts.html" |
| 15 | + > |
| 16 | + Pipecat's API methods for Together AI TTS |
| 17 | + </Card> |
| 18 | + <Card |
| 19 | + title="Example Implementation" |
| 20 | + icon="play" |
| 21 | + href="https://github.com/pipecat-ai/pipecat/blob/main/examples/voice/voice-together.py" |
| 22 | + > |
| 23 | + Complete voice bot example |
| 24 | + </Card> |
| 25 | + <Card |
| 26 | + title="Together AI Documentation" |
| 27 | + icon="book" |
| 28 | + href="https://docs.together.ai/reference/audio-speech-websocket" |
| 29 | + > |
| 30 | + Official Together AI TTS WebSocket API documentation |
| 31 | + </Card> |
| 32 | + <Card |
| 33 | + title="Together AI Platform" |
| 34 | + icon="microphone" |
| 35 | + href="https://together.ai/" |
| 36 | + > |
| 37 | + Access models and manage API keys |
| 38 | + </Card> |
| 39 | +</CardGroup> |
| 40 | + |
| 41 | +## Installation |
| 42 | + |
| 43 | +To use Together AI TTS services, install the required dependencies: |
| 44 | + |
| 45 | +```bash |
| 46 | +uv add "pipecat-ai[together]" |
| 47 | +``` |
| 48 | + |
| 49 | +## Prerequisites |
| 50 | + |
| 51 | +### Together AI Account Setup |
| 52 | + |
| 53 | +Before using Together AI TTS services, you need: |
| 54 | + |
| 55 | +1. **Together AI Account**: Sign up at [Together AI](https://together.ai/) |
| 56 | +2. **API Key**: Generate an API key from your account dashboard |
| 57 | +3. **Model Selection**: Choose from available TTS models and voices |
| 58 | + |
| 59 | +### Required Environment Variables |
| 60 | + |
| 61 | +- `TOGETHER_API_KEY`: Your Together AI API key for authentication |
| 62 | + |
| 63 | +## Configuration |
| 64 | + |
| 65 | +<ParamField path="api_key" type="str" required> |
| 66 | + Together AI API key for authentication. |
| 67 | +</ParamField> |
| 68 | + |
| 69 | +<ParamField |
| 70 | + path="url" |
| 71 | + type="str" |
| 72 | + default="wss://api.together.ai/v1/audio/speech/websocket" |
| 73 | +> |
| 74 | + WebSocket URL for Together AI TTS API. |
| 75 | +</ParamField> |
| 76 | + |
| 77 | +<ParamField path="sample_rate" type="int" default="24000"> |
| 78 | + Output sample rate for emitted PCM frames. Together AI streams at 24 kHz and |
| 79 | + does not support other rates. |
| 80 | +</ParamField> |
| 81 | + |
| 82 | +<ParamField path="settings" type="TogetherTTSService.Settings" default="None"> |
| 83 | + Runtime-configurable settings. See [Settings](#settings) below. |
| 84 | +</ParamField> |
| 85 | + |
| 86 | +### Settings |
| 87 | + |
| 88 | +Runtime-configurable settings passed via the `settings` constructor argument using `TogetherTTSService.Settings(...)`. These can be updated mid-conversation with `TTSUpdateSettingsFrame`. See [Service Settings](/pipecat/fundamentals/service-settings) for details. |
| 89 | + |
| 90 | +| Parameter | Type | Default | Description | |
| 91 | +| -------------------- | ----------------- | ---------------------- | ------------------------------------------------------------- | |
| 92 | +| `model` | `str` | `"hexgrad/Kokoro-82M"` | Model identifier. _(Inherited.)_ | |
| 93 | +| `voice` | `str` | `"af_heart"` | Voice identifier. _(Inherited.)_ | |
| 94 | +| `language` | `Language \| str` | `Language.EN` | Language for synthesis. _(Inherited.)_ | |
| 95 | +| `max_partial_length` | `int \| None` | `None` | Maximum partial text length for streaming. `None` for no cap. | |
| 96 | + |
| 97 | +## Usage |
| 98 | + |
| 99 | +### Basic Setup |
| 100 | + |
| 101 | +```python |
| 102 | +import os |
| 103 | +from pipecat.services.together import TogetherTTSService |
| 104 | + |
| 105 | +tts = TogetherTTSService( |
| 106 | + api_key=os.getenv("TOGETHER_API_KEY"), |
| 107 | +) |
| 108 | +``` |
| 109 | + |
| 110 | +### With Custom Settings |
| 111 | + |
| 112 | +```python |
| 113 | +from pipecat.services.together import TogetherTTSService |
| 114 | +from pipecat.transcriptions.language import Language |
| 115 | + |
| 116 | +tts = TogetherTTSService( |
| 117 | + api_key=os.getenv("TOGETHER_API_KEY"), |
| 118 | + settings=TogetherTTSService.Settings( |
| 119 | + model="hexgrad/Kokoro-82M", |
| 120 | + voice="af_heart", |
| 121 | + language=Language.EN, |
| 122 | + ), |
| 123 | +) |
| 124 | +``` |
| 125 | + |
| 126 | +### In a Voice Pipeline |
| 127 | + |
| 128 | +```python |
| 129 | +from pipecat.pipeline.pipeline import Pipeline |
| 130 | +from pipecat.services.together import TogetherTTSService |
| 131 | + |
| 132 | +tts = TogetherTTSService( |
| 133 | + api_key=os.getenv("TOGETHER_API_KEY"), |
| 134 | + settings=TogetherTTSService.Settings( |
| 135 | + voice="af_heart", |
| 136 | + model="hexgrad/Kokoro-82M", |
| 137 | + ), |
| 138 | +) |
| 139 | + |
| 140 | +pipeline = Pipeline([ |
| 141 | + # ... upstream processors |
| 142 | + llm, |
| 143 | + tts, |
| 144 | + transport.output(), |
| 145 | +]) |
| 146 | +``` |
| 147 | + |
| 148 | +## Notes |
| 149 | + |
| 150 | +- Together AI TTS streams audio at 24 kHz. The service outputs 24 kHz signed 16-bit mono PCM; the transport layer resamples to the pipeline's configured rate if needed. |
| 151 | +- The service supports interruption handling and automatically clears the text buffer when interrupted. |
| 152 | +- Audio is streamed incrementally via WebSocket deltas for low-latency synthesis. |
0 commit comments