Metadata-Version: 2.4
Name: livekit-plugins-satham
Version: 0.1.2
Summary: satham realtime speech-to-speech and kural-1 text to speech for LiveKit Agents
Project-URL: Homepage, https://satham.ai
Author: satham
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: livekit,livekit-agents,plugin,realtime,satham,speech-to-speech,text-to-speech,tts,voice-agent
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: livekit-agents~=1.8.12
Requires-Dist: satham~=0.1.2
Description-Content-Type: text/markdown

# livekit-plugins-satham

satham's realtime speech-to-speech model (satham-1) as a `RealtimeModel` for LiveKit Agents. Your
LiveKit agent keeps its own instructions and tools; satham hears the caller, ends turns, replies in
speech and handles barge-in, so the `AgentSession` needs no STT, LLM, TTS or VAD. The parameters
follow LiveKit's OpenAI `RealtimeModel`, so moving an agent from OpenAI to satham is mostly a one-line
change. `satham.TTS` brings kural-1, satham's text-to-speech model, to sessions with an LLM of their
own ([Text to speech](#text-to-speech)).

LiveKit Agents 1.8; Python 3.11+.

```sh
pip install livekit-plugins-satham
```

## Use

You pass your satham endpoint and API key (or set `SATHAM_URL` and `SATHAM_API_KEY`); there is no
default server.

```python
import os

from livekit.agents import (
    Agent,
    AgentServer,
    AgentSession,
    JobContext,
    RunContext,
    cli,
    function_tool,
    llm,
)
from livekit.plugins import satham


class SiteVisit(Agent):
    def __init__(self) -> None:
        # The agent's role and tools are satham's instructions and tools, as they stand.
        super().__init__(instructions="You are Asha, who books site visits for Example Homes.")

    @function_tool
    async def end_call(self, context: RunContext, reason: str = "done") -> llm.ToolResult:
        """End the call when the conversation is over. Say a short goodbye in the same turn."""
        await context.wait_for_playout()  # let the goodbye finish
        ...  # hang up, e.g. delete the room
        return llm.ToolResult("ended", reply_required=False)


server = AgentServer()


@server.rtc_session()
async def entrypoint(ctx: JobContext) -> None:
    await ctx.connect()
    session = AgentSession(
        llm=satham.RealtimeModel(  # was: openai.realtime.RealtimeModel(voice=...)
            url=os.environ["SATHAM_URL"],
            api_key=os.environ["SATHAM_API_KEY"],
            greeting="Hello, this is Asha from Example Homes. Is this a good time?",
            language="en",
            language_switch="auto",
        )
    )
    await session.start(agent=SiteVisit(), room=ctx.room)


if __name__ == "__main__":
    cli.run_app(server)
```

- **Instructions and tools.** The LiveKit agent's `instructions` become the call's instructions and
  its `@function_tool`s the call's tools, with nothing else to set. Both can change mid-call
  (`agent.update_instructions()`, `agent.update_tools()`).
- **The opening and fixed words.** With `greeting`, the agent says it first. Otherwise
  `session.generate_reply(instructions=...)` asks for a reply now (satham's `response.create`; use it in
  `on_enter` to open the call), and `session.say(text)` speaks fixed words in the call's voice
  (`response.say`) with no TTS. With neither, the caller speaks first.
- **Mid-call changes.** `model.update_options(...)` changes any control on every live call;
  `session.current_agent.realtime_llm_session.update_options(...)` changes one call.
- **Language changes** are emitted as `session_updated` (a `satham.SessionUpdated`: the language, and
  the reason `caller`, `reply` or `client`).

## From OpenAI RealtimeModel to satham

<!-- openai -->
| OpenAI `RealtimeModel` | satham `RealtimeModel` | Supported | Notes |
| --- | --- | --- | --- |
| `model` | `model` | yes | default `"satham-1"` |
| `voice` | `voice` | yes | a satham voice name, or a cloned voice's id |
| `modalities` | `modalities` | yes | `["audio", "text"]`, `["audio"]`, or `["text"]`, which hands the words to the session's TTS as OpenAI's text mode does |
| `temperature` | `temperature` | yes |  |
| `turn_detection` | `turn_detection` | yes | `server_vad` and `semantic_vad` are both satham's endpointing; `None`/`null` leaves turns to LiveKit; satham adds `barge_in`, `continue_within_ms`, ... |
| `input_audio_noise_reduction` | `input_audio_noise_reduction` | yes | `near_field` or `far_field`; `"none"` turns it off, and null keeps the server's default (on); satham adds `strength_db` and `apply_to_transcription` |
| `input_audio_transcription` | `input_audio_transcription` | partly | `enabled` and `code_mixed`; satham transcribes with its own models, so OpenAI's `model` and `prompt` are ignored |
| `max_response_output_tokens` | `max_response_output_tokens` | yes | or `"inf"` |
| `speed` | `speed` | yes |  |
| `tool_choice` | `tool_choice` | yes | preview: needs a server with tool support |
| `api_key` | `api_key` | yes | your satham key |
| `base_url` | `url` | yes | your satham endpoint |
| Agent instructions | Agent instructions | yes | can change mid-call |
| `generate_reply()` | `generate_reply()` | yes | `response.create`; `instructions` guide that reply alone |
| `session.say()` | `session.say()` | yes | `response.say`, no TTS needed (agents-js: call it on the realtime session) |
| tracing, truncation, reasoning | - | no | not applicable |
| azure_deployment, entra_token, api_version | - | no | not applicable |
| max_session_duration, conn_options | - | no | `connect_timeout` / `connectTimeoutMs` instead |
<!-- /openai -->

## Controls

Every keyword of `RealtimeModel(...)` and `update_options(...)` besides `url`, `api_key` and
`connect_timeout`. `modalities`, `turn_detection` and `input_audio_transcription` also decide what the
model tells LiveKit it does, so they are fixed for a model once made. Controls you leave out are not
sent; values are checked against these ranges, or the server's from `GET /v1/info`.

The controls marked "needs session controls" need a satham server with session controls (its
`GET /v1/info` lists `controls`, as the server does since 2026-11-16); an older server refuses them
when the call starts. `greeting` and `agent` belong to the start of a call. Setting
`input_audio_noise_reduction`'s `mode` alone resets `strength_db` to that mode's preset, so send both
to keep a custom strength; `None` leaves noise reduction at the server's default (on), and `"none"`
turns it off. `agent` is an optional
preset on the server and is not needed.

<!-- controls -->
| Option | Range | Default | OpenAI equivalent | Notes |
| --- | --- | --- | --- | --- |
| `instructions` | text, up to 16000 characters | none | - | the agent's role; from the LiveKit agent or Pipecat context in the adapters |
| `greeting` | text, up to 1000 characters | none | - | said first; without one the caller speaks first |
| `tools` | up to 128 functions | none | - | preview: needs a server with tool support |
| `tool_choice` | see notes | "auto" | `tool_choice` | "auto", "none", "required" or one function |
| `agent` | text, up to 64 characters | none | - | optional: a preset agent on the server, such as a demo's |
| `model` | text, up to 64 characters | "satham-1" | `model` | "satham-1" only today; needs session controls |
| `modalities` | list | ["audio", "text"] | `modalities` | ["audio", "text"], ["audio"], or ["text"]: words only, for your own TTS; needs session controls |
| `language` | `auto`, `hi`, `ta`, `te`, `kn`, `bn`, `pa`, `en` | "auto" | - |  |
| `language_switch` | `auto`, `off`, or `None` | "auto" | - |  |
| `voice_on_language_switch` | `keep`, `native`, or `None` | "keep" | - |  |
| `turn_detection.enabled` | `True` / `False` | true | `turn_detection=None` | false (or turn_detection=None): the client ends each turn; needs session controls |
| `turn_detection.type` | `server_vad`, `semantic_vad` | "server_vad" | `turn_detection.type` | needs session controls |
| `turn_detection.threshold` | 0.1 to 0.95 | 0.5 | `turn_detection.threshold` | the speech detector's threshold; needs session controls |
| `turn_detection.eagerness` | `auto`, `low`, `medium`, `high` | "auto" | `turn_detection.eagerness` | semantic_vad's end-of-turn wait; needs session controls |
| `turn_detection.prefix_padding_ms` | 0 to 1000 | 300 | `turn_detection.prefix_padding_ms` | needs session controls |
| `turn_detection.min_speech_ms` | 50 to 1000 | 100 | - | needs session controls |
| `turn_detection.silence_duration_ms` | 150 to 2000 | 350 | `turn_detection.silence_duration_ms` | server_vad's end-of-turn wait; needs session controls |
| `turn_detection.create_response` | `True` / `False` | true | `turn_detection.create_response` | answer each turn at once; needs session controls |
| `turn_detection.interrupt_response` | `True` / `False` | true | `turn_detection.interrupt_response` | barge-in on or off; needs session controls |
| `turn_detection.barge_in.min_speech_ms` | 0 to 2000 | 400 | - | needs session controls |
| `turn_detection.barge_in.min_probability` | 0 to 1 | 0.8 | - | needs session controls |
| `turn_detection.barge_in.min_dbfs` | -90 to 0, or `None` | -40 | - | needs session controls |
| `turn_detection.continue_within_ms` | 0 to 5000, or `None` | 2000 | - | the caller carrying on in the same turn; null: off; needs session controls |
| `turn_detection.continue_max_heard_ms` | 0 to 5000 | 1000 | - | needs session controls |
| `input_audio_noise_reduction.enabled` | `True` / `False` | true | `input_audio_noise_reduction={"type": "none"}` | false, "none" or {"type": "none"}: off; needs session controls |
| `input_audio_noise_reduction.mode` | `near_field`, `far_field` | "near_field" | `input_audio_noise_reduction.type` | resets strength_db to the mode's preset (12 or 30 dB) unless both are sent; needs session controls |
| `input_audio_noise_reduction.strength_db` | 0 to 100 | 12 | - | needs session controls |
| `input_audio_noise_reduction.apply_to_transcription` | `True` / `False` | false | - | needs session controls |
| `input_audio_transcription.enabled` | `True` / `False` | true | `input_audio_transcription=None` | transcript events to the client; needs session controls |
| `input_audio_transcription.code_mixed` | `True` / `False` | true | - | English words in Latin script, and digits; needs session controls |
| `voice` | text, up to 64 characters | the language's | `voice` |  |
| `breaths` | `True` / `False`, or `None` | off | - |  |
| `natural_pauses` | `True` / `False`, or `None` | off | - |  |
| `continuation` | `True` / `False`, or `None` | true | - | each phrase carries on from the one before; needs session controls |
| `speed` | 1 to 1 | 1.0 | `speed` | 1.0 only today; needs session controls |
| `phrasing.first_phrase_max_chars` | 1 to 120 | 120 | - | at least min_phrase_chars; needs session controls |
| `phrasing.min_phrase_chars` | 1 to 120 | 20 | - | needs session controls |
| `normalise_numbers` | `True` / `False` | true | - | numbers and amounts said as words; needs session controls |
| `pronunciations` | word to respelling | none | - | {word: respelling}, up to 200; needs session controls |
| `temperature` | 0.6 to 1.2 | 0.7 | `temperature` | needs session controls |
| `top_p` | 0.05 to 1 | 0.8 | - | needs session controls |
| `max_response_output_tokens` | 1 to 4096 | 320 | `max_response_output_tokens` | or "inf"; never above the server's; needs session controls |
| `tone` | `auto`, `conversational`, `happy`, `sad`, `excited`, `professional` | "auto" | - | "auto": the model picks; needs session controls |
| `repeat_guard` | `True` / `False` | true | - | re-asks a reply that repeats a recent one; needs session controls |
| `drift_guard` | `True` / `False` | true | - | keeps replies in the call's language; needs session controls |
<!-- /controls -->

## Text mode, manual turns, tools, interruptions

- **`modalities=["text"]`.** The agent's words go to the `AgentSession`'s TTS, as with OpenAI's text
  mode; give the session a `tts`.
- **`turn_detection=None`.** LiveKit's own turn detection (the session's VAD and turn detector) ends
  each turn: the plugin commits the caller's audio, and `generate_reply()` returns the reply.
- **Tools (preview: they need a satham server with tool support).** Each call the agent makes runs
  your tool; its result goes back to the server, which replies unless the tool returns
  `llm.ToolResult(..., reply_required=False)`.
- **Interruptions.** The caller speaking over the agent interrupts it and the playout stops at once.
  LiveKit mutes the caller for the first 3 s of agent speech by default (`AgentSession(
  aec_warmup_duration=3.0)`, off for SIP calls); set it to `None` where echo cancellation is good.
- **Not supported:** video, and reconnection (a dropped connection ends the call with an
  unrecoverable error).

## Text to speech

`satham.TTS` is kural-1, satham's text-to-speech model, as the TTS of an `AgentSession` that has an
LLM (and STT) of its own:

```python
from livekit.plugins import satham

session = AgentSession(
    stt=...,
    llm=...,
    tts=satham.TTS(voice="malar", language="ta", tone="conversational"),
)
```

- **A sentence at a time, as it is made.** LiveKit hands the TTS one sentence at a time; each is one
  streamed request (`stream: true`, raw PCM), so the agent starts speaking as soon as the first audio
  arrives. 24 kHz, mono.
- **Options:** `url` and `api_key` (or `SATHAM_URL` and `SATHAM_API_KEY`), `voice`, `language`, `tone`,
  `pace`, `instructions`, `breaths`, `natural_pauses` and `model`, with the values of the SDK's `client.audio.speech` (see the
  `satham` package's README). `tts.update_options(...)` changes them from the next sentence (`None`
  gives one back to the default); `instructions` and `tone`/`pace` exclude each other, so setting one
  clears the other. A pause marker in the text (`<break time="0.5s"/>`, 0.1 to 3 seconds) is spoken as that much silence.
- **Errors** are LiveKit's: `APIStatusError` with the HTTP status (401, 400 and 413 are not retried;
  429 and 5xx are, as LiveKit's connection options say), `APITimeoutError`, and `APIConnectionError`
  for a network failure or a stream the server cut short.
