This release is a pre-release and may not be stable for production use.
pipecat-sprag
Sprag speech and language models for Pipecat.
This integration is maintained by Sprag.
| Service | Import | Model |
|---|---|---|
SpragSTTService |
pipecat_sprag.stt |
Rhythm (speech to text) |
SpragLLMService |
pipecat_sprag.llm |
Symphony (LLM) |
SpragTTSService |
pipecat_sprag.tts |
Chorus (text to speech) |
SpragTurnDetector, SpragTurnAnalyzer |
pipecat_sprag.turns |
Sprag Turns (end of turn) |
Installation
uv add pipecat-sprag
Each service reads your API key from the SPRAG_API_KEY environment variable, or takes it as api_key=. You can generate a key from API keys in the Sprag app.
Usage
Each service drops into a Pipecat pipeline in place of any other STT, LLM, or TTS service:
from pipecat_sprag.llm import SpragLLMService
from pipecat_sprag.stt import SpragSTTService
from pipecat_sprag.tts import SpragTTSService
stt = SpragSTTService()
llm = SpragLLMService()
tts = SpragTTSService(settings=SpragTTSService.Settings(voice="wade"))
pipeline = Pipeline(
[transport.input(), stt, user_aggregator, llm, tts, transport.output(), assistant_aggregator]
)
SpragSTTServicestreams audio to Rhythm over Sprag's streaming transcription socket (wss://api.sprag.ai/v1/audio/transcriptions). By default your pipeline's VAD decides when a turn ends; passturn_detection={"type": "server_vad"}to let Sprag detect turns instead, orcommit_on_turn_end=Trueto transcribe each turn whenSpragTurnDetectorends it.SpragLLMServiceruns Symphony through Sprag's chat completions API, with function calling and token usage metrics.SpragTTSServicestreams Chorus speech over Sprag's streaming speech socket (wss://api.sprag.ai/v1/audio/speech), one sentence at a time. It defaults to thechorusmodel and thewadevoice; the available voices are listed in voice presets.
Each service takes settings=<Service>.Settings(...) for its model and other options, and api_key= if you don't use the SPRAG_API_KEY environment variable.
Turn detection
Sprag's turn model reads the caller's audio, plus what your agent last said, and decides when the caller has finished their turn. It streams over Sprag's turns socket (wss://api.sprag.ai/v1/turns). You can use it in either of two ways.
SpragTurnDetector: the model decides the turn. Place the detector after the transport input, and let the user aggregator follow it with Pipecat's external turn strategies. The model's turn.started starts the user's turn and interrupts the bot. Its turn.ended commits the turn's audio to Rhythm, and the turn ends once that transcript arrives. No VAD is needed:
from pipecat.processors.aggregators.llm_response_universal import LLMUserAggregatorParams
from pipecat.turns.user_start import ExternalUserTurnStartStrategy
from pipecat.turns.user_stop import ExternalUserTurnStopStrategy
from pipecat.turns.user_turn_strategies import UserTurnStrategies
from pipecat_sprag.stt import SpragSTTService
from pipecat_sprag.turns import SpragAgentTextObserver, SpragTurnDetector
turns = SpragTurnDetector()
stt = SpragSTTService(commit_on_turn_end=True)
user_params = LLMUserAggregatorParams(
user_turn_strategies=UserTurnStrategies(
start=[ExternalUserTurnStartStrategy()],
stop=[ExternalUserTurnStopStrategy(timeout=0.1)],
)
)
pipeline = Pipeline(
[
transport.input(),
turns,
stt,
user_aggregator,
llm,
tts,
transport.output(),
assistant_aggregator,
]
)
worker = PipelineWorker(pipeline, observers=[SpragAgentTextObserver(turns)])
The stop strategy's timeout is how long it waits for further transcripts after one arrives; Pipecat's default is 0.5 s.
SpragTurnAnalyzer: a drop-in turn analyzer. It takes the place of LocalSmartTurnAnalyzerV3, alongside your VAD. Like other streaming analyzers, it reports the turn complete as soon as the model ends it. Create one analyzer for each pipeline:
from pipecat.turns.user_stop import TurnAnalyzerUserTurnStopStrategy
from pipecat_sprag.turns import SpragAgentTextObserver, SpragTurnAnalyzer
analyzer = SpragTurnAnalyzer()
stop = [TurnAnalyzerUserTurnStopStrategy(turn_analyzer=analyzer)]
worker = PipelineWorker(pipeline, observers=[SpragAgentTextObserver(analyzer)])
SpragAgentTextObserver gives the model the words of the agent's last reply that were played, as context. Without it, the model judges the caller's audio alone. Each turn the model ends is reported as a TurnMetricsData with the model's end-of-turn probability and the time from the VAD's last speech stop. The detector reports it when the pipeline enables metrics. Both take params=SpragTurnParams(...):
eot_threshold: the end-of-turn probability that ends the turn. Default0.6.eager_eot_threshold: a lower probability that reports an eager end, a sign the turn is probably over, beforeeot_thresholdis reached. DefaultNone, which reports none.min_silence_ms: the silence a turn needs before the model can end it, from 0 to 10000 and beloweot_timeout_ms. Default200.eot_timeout_ms: the silence that ends the turn whatever the model scores, from 100 to 60000. Default3000.
eot_threshold and eager_eot_threshold run from 0 to 1, and eager_eot_threshold can't exceed eot_threshold. SpragTurnParams raises a pydantic ValidationError for values outside these bounds, the same bounds the server applies. If the server refuses the params anyway, neither class reconnects: the detector pushes an ErrorFrame whose exception is a SessionConfigRefusedError and marks itself unusable, and the analyzer logs the error.
The analyzer needs a sample rate before it receives audio. A pipeline sets it when it starts; outside one, pass sample_rate= or call set_sample_rate(). Without one, the first append_audio raises RuntimeError, and later calls drop the audio and return INCOMPLETE.
Turn events
Both classes report each of the model's events to an event handler, with the event as a typed model:
| Handler | Event | When |
|---|---|---|
on_turn_started |
TurnStarted |
the model opens a turn |
on_turn_update |
TurnUpdate |
every reading during a pause, including one that ends the turn |
on_eager_end |
TurnEagerEnd |
the first reading in a pause at or above eager_eot_threshold, at most once per pause; on_turn_ended follows when the same reading ends the turn |
on_turn_resumed |
TurnResumed |
the caller speaks again after an eager end |
on_turn_ended |
TurnEnded |
the turn ends; reason is model, timeout, or client |
on_session_closed |
SessionClosed |
the session closes, with its usage |
Every turn event has turn_index, counted from 0, and audio_window_start and audio_window_end, in seconds from the connection's first audio byte. All three restart when the session reconnects. Readings add probability and silence. An eager end lets you start preparing a reply early and drop it if the caller resumes:
from pipecat_sprag.turns import SpragTurnDetector, SpragTurnParams, TurnEagerEnd, TurnResumed
turns = SpragTurnDetector(params=SpragTurnParams(eager_eot_threshold=0.4))
@turns.event_handler("on_eager_end")
async def on_eager_end(detector: SpragTurnDetector, event: TurnEagerEnd) -> None:
logger.info(f"Turn {event.turn_index} is probably over ({event.probability:.2f})")
@turns.event_handler("on_turn_resumed")
async def on_turn_resumed(detector: SpragTurnDetector, event: TurnResumed) -> None:
logger.info(f"Turn {event.turn_index} resumed at {event.audio_window_end:.2f} s")
Connection and usage
Both classes connect in the background and reconnect if the socket drops. Audio that arrives before the session is configured is buffered and sent first, so the start of the caller's first turn isn't lost. After a dropped connection, only the audio the lost connection didn't send is replayed, because the new session's clock starts again. The buffer keeps the latest 8 seconds, the most audio a reading scores, and drops anything older, including the older part of a single longer chunk.
When the session closes, it waits up to 2 seconds for the server's session.closed. Events that arrive in that time still reach their handlers, and the connection's usage is then available as usage on the detector or analyzer, as well as in on_session_closed. usage describes only the latest connection: it is None while that connection is open, and stays None when it closes without session.closed. usage.invocations counts model invocations, one for the first reading of each pause. The detector closes without waiting when its pipeline is cancelled, so a cancelled pipeline reports no usage.
Example
examples/voice_agent.py is a complete voice agent running on Rhythm, Symphony, and Chorus. It uses Pipecat's development runner:
uv sync --group examples
SPRAG_API_KEY=... uv run examples/voice_agent.py
Then open the printed URL in your browser and talk to it.
examples/demo.py runs the same pipeline behind a Sprag-branded browser client that shows the live transcript, which service is working, and each service's time to first byte:
uv sync --group examples
SPRAG_API_KEY=... uv run examples/demo.py
Then open http://localhost:7860.
Compatibility
Requires pipecat-ai>=1.8,<2. Tested with Pipecat v1.12.0.
Development
uv sync
uv run ruff check && uv run ruff format --check
uv run mypy src
uv run pytest
Live tests call api.sprag.ai and are skipped by default: SPRAG_API_KEY=... uv run pytest -m live.
License
BSD 2-Clause. See LICENSE.
Metadata
Release files for pipecat-sprag 0.2.0.dev4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pipecat_sprag-0.2.0.dev4.tar.gz | 21.4 kB | With provenance | Details for pipecat_sprag-0.2.0.dev4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pipecat_sprag-0.2.0.dev4-py3-none-any.whl | Python 3 | none | any | Details for pipecat_sprag-0.2.0.dev4-py3-none-any.whl |
Total release size: 49.3 kB
Release files / pipecat_sprag-0.2.0.dev4.tar.gz
| Download URL | pipecat_sprag-0.2.0.dev4.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68edeaf199395d6f5fa0f9b498b4e63b18b6fb87ec0dae8d7e3737e108f55e1b
|
|
BLAKE2b-256 checksum How to use checksums |
9b9f67e2442eaa1cf98d870ddce02f86bd9a6cf68e87331f2a035377d6b92371
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / pipecat_sprag-0.2.0.dev4-py3-none-any.whl
| Download URL | pipecat_sprag-0.2.0.dev4-py3-none-any.whl |
|---|---|
| Size | 27.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
796d21d63718d5ce98d0cdfeea4496f24cc28a816ea38dd38c118ba1423b1485
|
|
BLAKE2b-256 checksum How to use checksums |
74b02b853d5f46635357cdae9d89ba55af6b099c49941fe57c152740a137b213
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for pipecat-sprag 0.2.0.dev4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pipecat_sprag-0.2.0.dev4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.