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.
- 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>)[source]
Bases:
TTSSettingsSettings for the Together AI TTS service.
- Parameters:
max_partial_length – Maximum partial text length for streaming.
- max_partial_length: int | None | _NotGiven
- 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:
WebsocketTTSServiceTogether 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.
- 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 language code string, or None if not supported.
- async start(frame: StartFrame)[source]
Start the Together AI TTS service.
- Parameters:
frame – The start frame containing initialization 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.
- async setup(setup: FrameProcessorSetup)
Set up the processor with required components.
- Parameters:
setup – Configuration object containing setup parameters.