Metadata-Version: 2.5
Name: laidline-livekit
Version: 1.1.2
Summary: LiveKit Agents `tts_node` wrapper: marks audio frames with streaming AudioSeal; one evidence entry per call.
Project-URL: Homepage, https://laidline.com
Project-URL: Documentation, https://laidline.com/docs/quickstart
Project-URL: Changelog, https://laidline.com/docs/changelog
Author: Laidline LLC
License-Expression: LicenseRef-Laidline-Source-Available
License-File: LICENSE
Keywords: ai-act,c2pa,livekit,provenance,voice,watermark
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia
Classifier: Topic :: Security :: Cryptography
Requires-Python: >=3.12
Requires-Dist: laidline[audio]<2,>=1.0
Requires-Dist: livekit-agents<2,>=1.8
Description-Content-Type: text/markdown

# laidline-livekit

A LiveKit Agents `tts_node` wrapper. It marks the synthesized `rtc.AudioFrame`s (keyed with audio payload layout `audioseal-p70-r1` from 8 kHz, otherwise from 16 kHz) with streaming AudioSeal and writes one Laidline evidence entry per call.

```bash
pip install laidline-livekit   # pulls laidline[audio] and livekit-agents>=1.8,<2
```

```python
from livekit.agents import Agent
from laidline import MarkContext, Marker
from laidline_livekit import mark_audio_frames

marker = Marker.from_config("laidline.yaml")  # in-process: keys, models and evidence stay on your host


class Assistant(Agent):
    async def tts_node(self, text, model_settings):
        return mark_audio_frames(
            marker,
            Agent.default.tts_node(self, text, model_settings),
            ctx=MarkContext(route="livekit:support-agent", tenant="acme"),
        )
```

## What it does

- `mark_audio_frames(marker, frames, *, ctx=None)` returns an async iterator of the same audio, marked. Rate and channels stay the same; frames are regrouped into 0.5 s blocks, and each frame keeps its `userdata`, where LiveKit carries timed transcripts.
- Each call writes one `marked` evidence entry with `modality: audio`, `watermark.streaming: true`, the payload and issuer id, the duration, and your `ctx` (default route `livekit:tts_node`). An iterator that changes sample rate part-way gets one entry per format.
- The entry is written when the iterator ends. That includes a consumer that stops early (an interrupted turn) and a cancelled task. The wrapped iterator is closed as well.
- It checks its arguments when you call it: a `MarkClient` raises `TypeError`, because the streaming path has no HTTP form. A Marker with `watermark.audio.enabled: false` raises `ValueError`.
- Unkeyed, the embedder is AudioSeal's streaming card (`watermark.audio.stream_kind: block`, the only value). A keyed deployment (`watermark.payload_keys`) marks through the keyed stream marker instead (see Survival).

## What it does not do

- Unkeyed, audio below 16 kHz (an 8 kHz phone bot) is not marked: it passes through unchanged and the entry says `watermark: null`, `watermark_skipped:rate_below_16k`. The unkeyed streaming mark does not survive below 16 kHz. A keyed deployment (`watermark.payload_keys`, what `laidline init` writes) marks from 8 kHz with audio payload layout `audioseal-p70-r1` (with layout `none` the 16 kHz floor applies): measured 2026-11-07 at 8 kHz, 100 of 100 through simulated G.711 mu-law and A-law, G.726 and 5 percent packet loss (n = 100 per cell; ffmpeg codecs, not a carrier path). Rates between 8 and 16 kHz are admitted but unmeasured.
- A stream carries no C2PA manifest (`c2pa: null`, warning `manifest_skipped:streaming`). The watermark and the evidence entry are the provenance for live audio.
- For a recording you store (for example egress to a file), sign the file itself with `marker.mark_audio(..., fmt="wav" | "flac" | "mp3" | "m4a")`. This embeds a manifest and adds the batch mark. Laidline's `/v1/audio/speech` proxy in streaming mode stores a signed twin of a response only when `watermark.audio.store_signed_twin` is enabled and only for a stream that completed.

## Survival

Measured 2026-09-27 on LibriSpeech test-clean, 500 speech clips. The threshold for this table is 0.39, which flagged 0.75 % of 530 unmarked clips; the shipped default is 0.5, which flagged 0.38 % and detects less after heavy degradation. Figures are the share of clips on which the streaming-mode mark (the one this wrapper embeds) is still detected:

| Transform | Streaming mode |
|---|---|
| Opus 24 kbps | 100 % |
| Opus 48 kbps | 100 % |
| MP3 64 kbps | 100 % |
| AAC 64 kbps | 100 % |
| G.711 mu-law | 0 % |
| 8 kHz resampling | 0 % |
| EnCodec 6 kbps | 100 % detected, 0 % exact issuer |
| Mimi | 0 % |

The streaming mark survives an offline Opus transcode at 24 and 48 kbps (100 percent on 500 LibriSpeech clips). One real WebRTC session on loopback was run, keyed under the trial shared key (2026-10-21); no session with a customer's own key and no real-network jitter was tested. **The unkeyed streaming mark does not survive a simulated phone leg** (G.711 codec simulation, the codec of LiveKit SIP calls to the PSTN), and it was not run over a real call. For an unkeyed phone deployment, provenance comes from the evidence entry and from C2PA on stored recordings, not from the unkeyed watermark. The keyed stream is what `laidline init` writes (`watermark.payload_keys`).

| Transform | Keyed or unkeyed | Method | n | Date | Result |
|---|---|---|---|---|---|
| Opus at 24 and 48 kbps, offline transcode | unkeyed stream | LibriSpeech test-clean | 500 clips | 2026-09-27 | 100 % detected |
| 5 percent packet loss, repeat-last fill, at 8 kHz | keyed stream | simulation | 100 | 2026-11-07 | 100 of 100 |
| G.711 and Opus at 24 kbit/s | keyed stream | ffmpeg codecs on 10 s of speech, not a carrier path | 100 each | 28 Oct 2026 | 100 of 100 each |
| real SignalWire calls at 8 kHz | keyed stream, clips marked offline by `Marker.audio_stream`, not through this plugin | read on the recording aligned to the clip; carrier routing unconfirmed, possibly on-net | 19 | 2026-11-08 | 19 of 19 (Wilson 95 % lower bound 83.2 %); the untrimmed recording 2 of 19 |
| real calls over Amazon Connect and SignalWire at 8 kHz, beside the row above, not pooled | keyed stream, clips marked the same way | played by Amazon Connect as an 8 kHz mu-law file, recorded by SignalWire at the callee, read on the recording aligned to the clip; carrier routing unconfirmed | 577 completed (1 call failed and is not counted, its inbound leg never matched to the contact) | 2026-11-08 | 576 of 577 (Wilson 95 % lower bound 99.0 %) |
| simulated G.711 and 8 kHz | batch mark (`mark_audio`, non-streaming) | simulation | see [the benchmarks page](https://laidline.com/docs/benchmarks) | see [the benchmarks page](https://laidline.com/docs/benchmarks) | 100 % |
| real Twilio number-to-number calls, recorded at the callee, G.711 8 kHz | batch mark | carrier routing unconfirmed and possibly on-net | 100 | 2026-09-27 | 96 % at the shipped 0.5, 99 % at 0.39 |
| real SignalWire calls | batch mark | read on the recording aligned to the clip; carrier routing unconfirmed, possibly on-net | 21 | 2026-10-21 and 22 | 21 of 21 exact payload; the untrimmed recording gave no exact read |

The unkeyed streaming mark's mean embed SNR is 17.4 dB (5th percentile 8.7 dB), which is audible on some voices. Listen to your own voices before you ship.

The full numbers and method are in [the benchmarks page](https://laidline.com/docs/benchmarks) ("Audio robustness"), and what was tested, and how, in [the LiveKit integration guide](https://laidline.com/docs/integrations/livekit). Streaming sessions, detection and the operating threshold are in [the audio guide](https://laidline.com/docs/integrations/audio).
