Skip to main content

Python SDK for AttentionLabs real-time attention detection.

Project description

attenlabs-sas

Python SDK for Attention Labs real-time attention detection.

Sign up

Get your API token at attentionlabs.ai/dashboard.

Install

pip install attenlabs-sas

Requires Python 3.10+. System audio / video access is handled via sounddevice + opencv-python, which are pulled in automatically.

Quickstart

import time
from sas import AttentionClient

client = AttentionClient(
    token="your-auth-token",
)

@client.on_connected
def _(): print("ws connected")

@client.on_started
def _(): print("server warmup complete")

@client.on_warmup_complete
def _(): print("first prediction received")

@client.on_prediction
def _(event):
    print(f"class={event.cls} conf={event.confidence:.2f} src={event.source} faces={event.num_faces}")

@client.on_vad
def _(event):
    print(f"vad={event.probability:.2f}")

@client.on_state
def _(event):
    print(f"conv state={event.state}")

@client.on_speech_ready
def _(event):
    # event.audio_pcm16 — np.int16 array @ 16 kHz mono
    # event.audio_base64 — same audio as base64 (ready for OpenAI Realtime etc.)
    # event.duration_sec — float
    # Forward to your LLM of choice.
    ...

@client.on_error
def _(event):
    print(f"ERROR: {event.title}: {event.message}")

client.start()
try:
    while True:
        time.sleep(0.1)
except KeyboardInterrupt:
    client.stop()

API

AttentionClient(...)

argument type default notes
token str | None None Sent as the WS subprotocol. Omit if the server has auth disabled.
video CameraConfig CameraConfig() device_index, width, height, jpeg_quality.
audio MicConfig MicConfig() device (int index or name; None → system default), channels.
initial_threshold float 0.7 Device-class confidence threshold, pushed to server after started.
enable_audio bool True Disable mic capture entirely.
enable_video bool True Disable webcam capture entirely.

Methods

method description
start() Opens WS, acquires mic+cam, starts capture threads. Non-blocking. Raises on handshake failure.
stop() Tears down capture, joins threads, closes WS.
mute() / unmute() Pauses/resumes upstream audio; also signals server so VAD stops firing.
mark_responding(bool) Tell the server an LLM response is in flight — server stops emitting predictions while true.
set_threshold(value) 0..1, device-class trigger threshold. Server acks via config event.

Events (decorator registration)

decorator payload
@on_connected
@on_started — (server-side warmup complete)
@on_warmup_complete — (first non-zero-confidence prediction received)
@on_prediction PredictionEvent(cls, confidence, source, num_faces)
@on_vad VadEvent(probability, is_speech)
@on_state StateEvent(state: "listening" | "sending" | "cancelled" | "idle")
@on_speech_ready SpeechReadyEvent(audio_pcm16, audio_base64, duration_sec)
@on_config ConfigEvent(model_class2_threshold) (server ack of set_threshold)
@on_stats StatsEvent(rtt_ms, sent_video, skipped_video, sent_audio, uptime_s)
@on_error AttentionErrorEvent(title, message, detail, code)
@on_disconnected DisconnectedEvent(code, reason, was_clean)

All callbacks fire on the WebSocket receive thread (or the heartbeat thread for stats/error). Keep them fast — offload heavy work to your own thread.

LLM integration

LLM routing is intentionally not part of the SDK. The speech_ready event hands you ready-to-send PCM16 audio (both as np.int16 and as base64); forward it wherever you like.

When your LLM starts speaking, call client.mute() + client.mark_responding(True), and unmute() + mark_responding(False) when it finishes — otherwise the server will keep emitting predictions during the response.

A full CLI sample showing SDK + OpenAI Realtime wiring lives in a separate public repo: sas-py-demo.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

attenlabs_sas-0.1.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

attenlabs_sas-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file attenlabs_sas-0.1.1.tar.gz.

File metadata

  • Download URL: attenlabs_sas-0.1.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for attenlabs_sas-0.1.1.tar.gz
Algorithm Hash digest
SHA256 20929bb25e604b56078b1c961e7742ea31e578960be276d712a6ecde68c89c44
MD5 0592e6686fb3e601bea03b90c314bd31
BLAKE2b-256 5cae97bdc7696ccf9e1b7286314e1b9768123f774a5f31a49fab860412beb580

See more details on using hashes here.

File details

Details for the file attenlabs_sas-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: attenlabs_sas-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for attenlabs_sas-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0055a7ce6bc48357f7e8f8765a44fb23bd1da6a394297ad104b250329ca8b274
MD5 599499c4d3a9b024514b09b39a7d9011
BLAKE2b-256 116a7045d57071b3adde44d9fa579db001d5c161800c9dcc89e493400e091408

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page