Metadata-Version: 2.5
Name: talksign
Version: 0.2.1
Summary: Official Python SDK for the Talksign API: speech and text to sign language video.
Project-URL: Homepage, https://talksign.co
Project-URL: Documentation, https://github.com/talksign/talksign-python#readme
Project-URL: Repository, https://github.com/talksign/talksign-python
Project-URL: Issues, https://github.com/talksign/talksign-python/issues
Project-URL: Changelog, https://github.com/talksign/talksign-python/blob/main/CHANGELOG.md
Author: Talksign
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: accessibility,api,asl,avatar,bsl,sign language,talksign
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.25
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: video
Requires-Dist: av>=12; extra == 'video'
Requires-Dist: numpy>=1.24; extra == 'video'
Description-Content-Type: text/markdown

# Talksign Python SDK

The official Python library for the [Talksign](https://talksign.co) API: turn speech or text into
sign language video with **Echo 2.0**, in a few lines.

```sh
pip install talksign            # REST client + live stream
pip install "talksign[video]"   # + RGB frame decoder for video pipelines (PyAV, numpy)
```

Python 3.10+. Get an API key (`sk-live-…`) in the [Developer Console](https://developer.talksign.co)
and set it as `TALKSIGN_API_KEY`.

## REST quickstart

```python
from talksign import Talksign

client = Talksign()  # reads TALKSIGN_API_KEY

res = client.speech_to_sign.realtime("Hello, how are you?", avatar="arthur", language="asl")
for clip in res["data"]["playlist"]:
    print(clip["gloss"], clip["url"])
print("cost:", res["usage"]["costUsd"], "USD")

# One rendered MP4 instead of a clip playlist
video = client.speech_to_sign.studio("Welcome to our store", avatar="amara")
print(video["data"]["download_url"])

print(client.balance.retrieve()["available_usd"])
```

Async: use `AsyncTalksign` — same resources, `await` every call.

| Resource | Methods |
|---|---|
| `speech_to_sign` | `realtime`, `create`, `studio`, `gloss`, `video` |
| `avatars` | `list`, `get`, `create`, `delete`, `validate` |
| `jobs` | `create`, `get`, `list`, `cancel`, `wait` |
| `speech_to_speech` | `create` |
| `voice` | `create` (MP3 bytes), `create_json`, `voices` |
| `sign_to_speech` | `create` (not available in the API yet: raises `APIError` 501) |
| `uploads`, `meetings` | `create` / `create`, `get`, `stop` |
| `models` | `list`, `warmup` |
| `usage`, `balance` | `list`, `retrieve` |
| client | `openapi()` |

Responses are plain `dict`s typed with `TypedDict`s from `talksign.types`.

## Live signing from streamed text

`client.echo.stream()` turns text as it arrives (LLM tokens, TTS text) into an ordered stream of sign clips.
It cuts sentences, makes one realtime call per sentence with the next one prefetched, and can be interrupted.

```python
import asyncio
from talksign import AsyncTalksign


async def main():
    async with AsyncTalksign() as client:
        stream = client.echo.stream(avatar="arthur", language="asl")

        async def feed():
            for chunk in ["Hi there! ", "How can I ", "help you today?"]:
                stream.push_text(chunk)
            await stream.aclose()  # flush the rest, then "done"

        asyncio.create_task(feed())
        async for event in stream:
            if event.type == "sentence":
                print("signing:", event.text, event.glosses)
            elif event.type == "clip":
                print("  play", event.clip["gloss"], event.clip["url"])
            elif event.type == "idle":
                print("idle loop:", event.idle and event.idle["url"])


asyncio.run(main())
```

Events: `sentence` (has `glosses`, `usage`, `has_missing`), `clip` (in order; clips without a URL are skipped), `interrupted`, `idle` (`reason`: `ready` = the avatar's idle loop fetched at start with one free
`GET /v1/avatars/{id}`, so you can show the avatar before the first sentence; `drained`; `interrupt`), `error` (a sentence failed and was
skipped), `done`. Call `stream.interrupt()` when the user barges in: in-flight calls are aborted and the queue is dropped.

Each word's clip plays `in_url` → `url` from `active_start_s` to `active_end_s` → `out_url`; loop the `idle` clip in between.

Options of `echo.stream(...)`:

- `chunking="sentence"` (default) signs each sentence as soon as it is complete. `chunking="full"` buffers everything
  until `flush()` / close and signs it in one call (fewer calls, later start).
- `first_chunk_chars=40` (default): the first piece of each reply may be cut at a comma or clause once it has 40
  characters, so the avatar starts sooner. `0` turns it off.
- `fetch_idle=True` (default): fetch the avatar's idle loop at start (free). `False` skips it.

## Avatars and their idle loop

```python
avatar = client.avatars.get("arthur")       # free
idle = avatar["data"]["idle"]               # {"url": ..., "expires_at": ...} or None
```

Every avatar from `avatars.list()` / `avatars.get()` carries `idle`, a short-lived signed URL of its idle loop.

## Browser apps: short-lived tokens

Never put your secret key in a web page. Mint a short-lived token on your server and hand it to the page:

```python
token = client.tokens.create(expires_in=600, allowed_origins=["https://app.example.com"])
# -> {"token": "tst_…", "expires_at": "…", "scopes": ["sign:realtime", "avatars:read"], ...}
```

The token can only call `POST /v1/speech-to-sign/realtime` and `GET /v1/avatars[/{id}]`, bills your wallet like the
key, and ends when the key is revoked. Set `allowed_origins` in production. In the page, use the JavaScript SDK
(`new Talksign({ token })`).

## Video frames (for video pipelines and agent plugins)

```python
from talksign import AsyncTalksign
from talksign.video import EchoFrameSource

source = EchoFrameSource.from_client(AsyncTalksign(), avatar="arthur", width=1280, height=720, fps=30)
source.push_text("Nice to meet you.")
async for frame in source:  # numpy uint8 array (720, 1280, 3), RGB, at 30 FPS
    publish(frame)
```

It loops the idle clip while nothing is signing, crossfades between clips (150 ms), downloads clips with bounded
concurrency and an LRU cache, and decodes in a worker thread. `source.interrupt()` returns to idle at once.
Call `source.start()` at session start (iterating also starts it): the idle loop is looked up and downloaded at
once, and its first frame is shown as a still while the rest arrives (about 0.25 s instead of ~2.9 s in offline
tests). Pass `poster=` (image/clip bytes, an RGB array or a URL) to show the avatar from the very first frame. With `realtime=False`
(offline rendering) frames are produced as fast as possible and never padded with idle/background frames while a
sentence is still being fetched or downloaded.

## Errors and retries

All errors derive from `talksign.TalksignError` and carry `status_code`, `code`, `param` and `request_id`:
`APIError` (any HTTP error; base of) `AuthenticationError` (401), `InsufficientBalanceError` (402), `PermissionDeniedError` (403), `NotFoundError` (404),
`BadRequestError` (400/409/413/422), `RateLimitError` (429, `retry_after`), plus `APIConnectionError` / `APITimeoutError`. `status` is an alias of `status_code`.

429, 5xx and network errors are retried `max_retries` times (default 2) with exponential backoff, honouring `Retry-After`.
Every POST carries an `Idempotency-Key` (reused across retries), so a retried call is never charged twice. Pass your own
with `idempotency_key=`.

```python
client = Talksign(api_key="sk-live-…", base_url="https://api.talksign.co", timeout=30, max_retries=3)
```

## Licence

Apache-2.0. See [LICENSE](LICENSE).
