tts

Together AI text-to-speech service implementation.

This module provides a TTS service using Together AI’s WebSocket API:

  • TogetherTTSService: WebSocket-based real-time TTS with streaming audio output.

pipecat.services.together.tts.language_to_together_language(language: Language) → str[source]

Convert a Language enum to a Together AI language code.

Together accepts ISO 639-1 codes and lowercase locale codes (zh-hk). Regional variants without a verified locale code fall back to their base language code.

Parameters:

language – The Language enum value to convert.

Returns:

The corresponding Together AI language code.

class pipecat.services.together.tts.TogetherTTSSettings(model: str | None | NotGiven = <factory>, extra: dict[str, ~typing.Any]=<factory>, voice: str | None | NotGiven = <factory>, language: Language | str | None | NotGiven = <factory>, max_partial_length: int | None | NotGiven = <factory>, extra_params: dict[str, ~typing.Any] | None | ~pipecat.utils.types.NotGiven=<factory>)[source]

Bases: TTSSettings

Settings for the Together AI TTS service.

Parameters:
  • max_partial_length – Maximum partial text length for streaming.

  • extra_params –

    Model-specific synthesis options sent in the session update, such as pronunciation_dict, a list of "<source>/<replacement>" entries.

    Another way to guide pronunciation, besides pronunciation_dict, is to pass replace_text() find-and-replace rules through the text_transforms parameter. Pipecat applies them before the text reaches the provider, so the same rules can work across TTS services and depend less on what each provider supports. They’re worth trying if pronunciation_dict isn’t giving you the results you want.

class pipecat.services.together.tts.TogetherTTSService(*, api_key: str, url: str = 'wss://api.together.ai/v1/audio/speech/websocket', sample_rate: int | None = 24000, settings: TogetherTTSSettings | None = None, **kwargs)[source]

Bases: WebsocketTTSService

Together AI TTS service with WebSocket streaming.

Provides text-to-speech using Together AI’s realtime WebSocket API. Supports streaming synthesis with configurable voice and model options.

Example:

tts = TogetherTTSService(
    api_key="your-api-key",
    settings=TogetherTTSService.Settings(
        voice="tara",
        model="canopylabs/orpheus-3b-0.1-ft",
    ),
)
Settings

alias of TogetherTTSSettings

__init__(*, api_key: str, url: str = 'wss://api.together.ai/v1/audio/speech/websocket', sample_rate: int | None = 24000, settings: TogetherTTSSettings | None = None, **kwargs)[source]

Initialize the Together AI TTS service.

Parameters:
  • api_key – Together AI API key for authentication.

  • url – WebSocket URL for Together AI TTS API.

  • sample_rate – Output sample rate for emitted PCM frames. Defaults to 24000; Together streams at 24 kHz and does not support other rates.

  • settings – Runtime-updatable settings for the TTS service.

  • **kwargs – Additional arguments passed to WebsocketTTSService.

can_generate_metrics() → bool[source]

Check if this service can generate processing metrics.

language_to_service_language(language: Language) → str | None[source]

Convert a Language enum to Together AI language format.

Parameters:

language – The language to convert.

Returns:

The Together AI language code.

async setup(setup: FrameProcessorSetup)[source]

Set up the service and connect.

Parameters:

setup – Configuration object containing setup parameters.

async stop(frame: EndFrame)[source]

Stop the Together AI TTS service.

Parameters:

frame – The end frame.

async cancel(frame: CancelFrame)[source]

Cancel the Together AI TTS service.

Parameters:

frame – The cancel frame.

async flush_audio(context_id: str | None = None)[source]

Flush any pending audio by committing the text buffer.

async on_audio_context_interrupted(context_id: str)[source]

Clear the Together AI text buffer when the bot is interrupted.

Parameters:

context_id – The ID of the audio context that was interrupted.

async run_tts(text: str, context_id: str) → AsyncGenerator[Frame | None, None][source]

Generate speech from text using Together AI’s streaming API.

Parameters:
  • text – The text to synthesize into speech.

  • context_id – The context ID for tracking audio frames.

Yields:

Frame – Audio arrives via the WebSocket receive task.